/* ==========================================================================
   FUEL STOCK TRACKER — "Apple" CLEAN SURFACE
   Loaded LAST. Softens the industrial theme into a clean, calm, high-key
   surface (SF-style system font, softer radii, subtle blur, gentler shadows)
   and adds components used by the reliability features (topbar utilities,
   trash list). Both light and dark themes inherit from tokens.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   TYPOGRAPHY — SF-style system stack, tighter tracking
   -------------------------------------------------------------------------- */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-kurdish: 'Peshang Des 2', 'Space Grotesk', sans-serif;
}

body {
  letter-spacing: -0.01em;
}

/* --------------------------------------------------------------------------
   SURFACE — softer geometry
   -------------------------------------------------------------------------- */
:root {
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --badge-radius: 8px;
  --btn-radius: 12px;
  --input-radius: 12px;
  --card-radius: 16px;
  --toast-radius: 14px;
}

h1, h2, h3, .page-title { letter-spacing: -0.02em; }

/* --------------------------------------------------------------------------
   CARDS — roomy, calm
   -------------------------------------------------------------------------- */
.card {
  box-shadow: var(--elevation-1);
  border-radius: var(--card-radius);
}

/* --------------------------------------------------------------------------
   BUTTONS — pill-ish, weightless
   -------------------------------------------------------------------------- */
:root { --btn-height: 40px; --btn-height-sm: 32px; --btn-height-lg: 48px; }

.btn {
  border-radius: var(--btn-radius);
  box-shadow: var(--elevation-1);
  transition: transform var(--motion-fast), background var(--motion-fast), box-shadow var(--motion-fast);
}

.btn:active { transform: scale(.97); }

.btn--primary {
  box-shadow: 0 2px 10px var(--accent-border);
}

button.btn--ghost { background: var(--panel); border: 1px solid var(--border); }
button.btn--ghost:hover { background: var(--panel-hover); }

/* --------------------------------------------------------------------------
   TOPBAR — frosted, calm
   -------------------------------------------------------------------------- */
.topbar {
  backdrop-filter: var(--topbar-blur);
  -webkit-backdrop-filter: var(--topbar-blur);
}

.topbar__utilities {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.topbar__util {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  background: transparent;
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}

.topbar__util svg { width: 18px; height: 18px; }

.topbar__util:hover:not(:disabled) { background: var(--panel-hover); color: var(--text); }
.topbar__util:active:not(:disabled) { transform: scale(.92); }
.topbar__util:disabled { opacity: .35; cursor: default; }

[data-theme="light"] .topbar__util:hover { background: rgba(0, 0, 0, .05); }

/* --------------------------------------------------------------------------
   INPUTS — rounded filled fields
   -------------------------------------------------------------------------- */
input[type="text"], input[type="number"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="tel"], select, textarea {
  border-radius: var(--input-radius);
  background: var(--input-bg);
  border: 1px solid transparent;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast), background var(--motion-fast);
}

[data-theme="light"] input[type="text"], [data-theme="light"] input[type="number"],
[data-theme="light"] input[type="password"], [data-theme="light"] input[type="date"],
[data-theme="light"] input[type="datetime-local"], [data-theme="light"] input[type="tel"],
[data-theme="light"] select, [data-theme="light"] textarea {
  border: 1px solid var(--border);
}

input[type="text"]:hover, input[type="number"]:hover, select:hover textarea:hover,
[data-theme="light"] input[type="text"]:hover, [data-theme="light"] input[type="number"]:hover {
  border-color: var(--input-border-hover);
}

/* --------------------------------------------------------------------------
   TABLE — airier
   -------------------------------------------------------------------------- */
.table thead th {
  background: var(--table-header-bg);
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* --------------------------------------------------------------------------
   MODAL — frosted backdrop, softer dialog
   -------------------------------------------------------------------------- */
.modal-overlay {
  backdrop-filter: var(--modal-overlay-blur);
  -webkit-backdrop-filter: var(--modal-overlay-blur);
}

[data-theme="light"] .modal, [data-theme="light"] .modal-overlay {
  --modal-bg: #ffffff;
}

/* --------------------------------------------------------------------------
   LOGIN — calm card
   -------------------------------------------------------------------------- */
.login-card {
  border-radius: 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .16);
}

/* --------------------------------------------------------------------------
   TRASH PAGE — archived deletions
   -------------------------------------------------------------------------- */
.trash-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trash-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  transition: background var(--motion-fast);
}

.trash-row:hover { background: var(--panel-hover); }

.trash-row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.trash-row__title { font-weight: 600; font-size: var(--fs-md); }
.trash-row__meta { font-size: var(--fs-sm); }
.trash-row__actions { display: flex; gap: 8px; flex-shrink: 0; }

.trash-empty {
  padding: 26px 16px;
  text-align: center;
  font-size: var(--fs-md);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.page-head__actions { display: flex; gap: 8px; }

/* --------------------------------------------------------------------------
   DATA CARD HEADS (Data & Backup)
   -------------------------------------------------------------------------- */
.data-card__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.data-card__head-icon {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  color: var(--accent);
}

.data-card__head-icon svg { width: 18px; height: 18px; }

.data-card--danger .data-card__head-icon {
  background: var(--bad-bg);
  color: var(--bad);
}

.data-card__head-text { flex: 1; min-width: 0; }

.data-card__head-text h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.data-card__head-text .muted { margin: 3px 0 0; font-size: var(--fs-sm); line-height: 1.5; }

.data-card__head-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.data-card__body { margin-top: 14px; }

.snap-count {
  flex: none;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--panel-hover);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 2px 9px;
}

/* --------------------------------------------------------------------------
   SNAPSHOT LIST (Data & Backup)
   -------------------------------------------------------------------------- */
.snapshot-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 262px;
  overflow-y: auto;
  padding-right: 4px;
}

.snapshot-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--panel);
}

.snapshot-row__icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  color: var(--accent);
}

.snapshot-row__icon svg { width: 15px; height: 15px; }

.snapshot-row__main { flex: 1; min-width: 0; }
.snapshot-row__title { font-weight: 600; font-size: var(--fs-sm); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snapshot-row__meta { font-size: var(--fs-xs); color: var(--text-faint); margin-top: 2px; }

.snapshot-row__actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity 0.15s;
}

.snapshot-row:hover .snapshot-row__actions { opacity: 1; }

.snap-action {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.snap-action:hover { background: var(--panel-hover); color: var(--text); }
.snap-action--restore:hover { background: var(--accent-bg); color: var(--accent); }
.snap-action--delete:hover { background: var(--bad-bg); color: var(--bad); }

.snapshot-empty {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border: 1px dashed var(--border-soft);
  border-radius: 10px;
  color: var(--text-faint);
  font-size: var(--fs-sm);
  line-height: 1.5;
}

.snapshot-empty svg { flex: none; width: 18px; height: 18px; }

.snapshot-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-soft);
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

.snapshot-hint svg { flex: none; width: 13px; height: 13px; }

@media (max-width: 640px) {
  .data-card__head { flex-wrap: wrap; }
  .data-card__head-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
  .snapshot-row { flex-wrap: nowrap; }
}

/* --------------------------------------------------------------------------
   SAVED VIEWS PILL BAR
   -------------------------------------------------------------------------- */
.saved-views-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.saved-view-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast);
}

.saved-view-pill:hover { background: var(--panel-hover); color: var(--text); }
.saved-view-pill--active { border-color: var(--accent-border); background: var(--accent-bg); color: var(--accent); }
.saved-view-pill--add { border-style: dashed; color: var(--text-faint); }
.saved-view-pill--add:hover { color: var(--accent); border-color: var(--accent-border); background: var(--accent-bg); }
.saved-view-pill__x { opacity: .55; }
.saved-view-pill__x:hover { opacity: 1; }

/* --------------------------------------------------------------------------
   INLINE NOTE EDITING IN GRIDS
   -------------------------------------------------------------------------- */
.td-note--editable { cursor: text; }
.td-note--editable:hover { background: var(--accent-bg); }

.note-inline {
  box-sizing: border-box;
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  padding: 3px 8px;
}
.td--editing { padding: 3px 10px !important; }
[data-theme="dark"] .td-note--editable:hover { background: rgba(0, 122, 255, .12); }

/* --------------------------------------------------------------------------
   FOCUS RINGS & SELECTION — Apple-style accent glow
   -------------------------------------------------------------------------- */
input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus,
input[type="date"]:focus, input[type="datetime-local"]:focus, input[type="tel"]:focus,
select:focus, textarea:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 4px var(--accent-bg);
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

::selection { background: var(--accent-bg); color: var(--text); }

.tabular { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   DARK THEME refinements
   -------------------------------------------------------------------------- */
[data-theme="dark"] .topbar__util:hover { background: rgba(255, 255, 255, .08); }
[data-theme="dark"] .btn--ghost { background: var(--panel); }

[data-theme="dark"] .topbar { border-bottom: 1px solid rgba(255, 255, 255, .08); }

[data-theme="dark"] .card { border: 1px solid rgba(255, 255, 255, .05); }

[data-theme="dark"] .modal { border: 1px solid rgba(255, 255, 255, .07); }

[data-theme="dark"] .login-card {
  background: #1c1c1e;
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
}

[data-theme="dark"] * {
  scrollbar-width: thin;
  scrollbar-color: #48484a transparent;
}
[data-theme="dark"] ::-webkit-scrollbar { width: 10px; height: 10px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: transparent; }
[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #38383c;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: #48484a;
  background-clip: content-box;
  border: 2px solid transparent;
}

/* --------------------------------------------------------------------------
   UX POLISH — hierarchy, native controls, empty states
   -------------------------------------------------------------------------- */

/* Native control theming follows the active theme (overrides dark-only hardcodes) */
:root[data-theme="light"] {
  color-scheme: light;
}
:root[data-theme="light"] input,
:root[data-theme="light"] select,
:root[data-theme="light"] textarea,
:root[data-theme="light"] .field__input,
:root[data-theme="light"] .field__select,
:root[data-theme="light"] .field__textarea {
  color-scheme: light;
}
:root[data-theme="light"] ::-webkit-calendar-picker-indicator {
  filter: none;
  opacity: 0.55;
}

/* Sidebar — softer chips */
.nav-item { border-radius: 10px; }
.nav-child { border-radius: 7px; }

/* Buttons — primary lift */
.btn--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px var(--accent-bg);
}
.btn--primary:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

/* Empty states — Apple illustration chip */
.empty-state__icon,
.table-empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-faint);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .06);
  font-size: 26px;
}
.empty-state__icon svg,
.table-empty__icon svg {
  width: 28px;
  height: 28px;
}
.empty-state__icon,
.table-empty__icon {
  margin-bottom: 14px;
}

/* Breadcrumb current — clearer hierarchy */
.topbar__breadcrumb-item--current {
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* Table row selection accent shadow */
.table tbody tr.tr--selected td:first-child {
  box-shadow: inset 2px 0 0 var(--accent);
}

/* Dropdown options match the active theme */
.filter-chip select option,
select.field__select option,
select.field__select optgroup {
  background: var(--bg-elevated);
  color: var(--text);
}

/* --------------------------------------------------------------------------
   PHONE LAYOUT — full small-screen support (modals, forms, touch)
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .content {
    padding: 12px 12px max(14px, env(safe-area-inset-bottom, 0));
  }

  .page-head {
    flex-wrap: wrap;
    row-gap: 10px;
  }
  .page-head__actions {
    flex-wrap: wrap;
  }

  .card {
    padding: 14px;
  }
  .table-card {
    padding: 0;
  }

  .field__input,
  .field__select,
  .field__textarea {
    min-height: 44px;
    font-size: 16px;
  }

  .btn {
    min-height: 38px;
  }
  .btn--sm {
    min-height: 34px;
  }
  .modal__close {
    width: 40px;
    height: 40px;
  }

  .topbar__sync-text {
    display: none;
  }
  .topbar__sync {
    padding: 6px 10px;
  }

  .empty-state {
    padding: 28px 16px;
  }

  .table-scroll {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
}

@media (max-width: 640px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal,
  .modal--lg {
    max-width: 100%;
    width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 94dvh;
    transform: translateY(24px);
  }
  .modal-overlay--open .modal {
    transform: translateY(0);
  }
  .modal__body {
    max-height: calc(94dvh - 150px);
  }

  .topbar__actions {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    max-width: 62vw;
    justify-content: flex-end;
    scrollbar-width: none;
  }
  .topbar__actions::-webkit-scrollbar {
    display: none;
  }
  .topbar__actions .btn,
  .topbar__actions .topbar__sync {
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .content__title {
    font-size: 20px;
  }
  .stat-chips {
    grid-template-columns: 1fr 1fr;
  }
  .empty-state__icon,
  .table-empty__icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
  }
  .history-summary,
  .table-toolbar__count {
    font-size: 11px;
  }
  .modal__header {
    padding: 12px 14px;
  }
  .modal__body {
    padding: 12px 14px;
  }
  .modal__footer {
    padding: 8px 14px max(10px, env(safe-area-inset-bottom, 0));
  }
}

/* --------------------------------------------------------------------------
   REDUCED MOTION
   -------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------
   Footnotes
   -------------------------------------------------------------------------- */