/* Base elements and shared components (compact, industrial). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--st-font);
  font-size: var(--st-text-md);
  line-height: 1.45;
  color: var(--st-text);
  background: var(--st-frame);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -0.005em; }
h1 { font-size: var(--st-text-2xl); }
h2 { font-size: var(--st-text-xl); }
h3 { font-size: var(--st-text-lg); }
p { margin: 0; }
a { color: var(--st-accent-text); }
code { font-size: .92em; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--st-focus); outline-offset: 2px; border-radius: 4px; }

.st-visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────── */
.st-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 14px;
  border: 1px solid var(--st-border-strong); border-radius: 6px;
  background: var(--st-surface); color: var(--st-text);
  font-weight: 600; font-size: var(--st-text-md); line-height: 1; white-space: nowrap;
  transition: background var(--st-fast) var(--st-ease), border-color var(--st-fast) var(--st-ease);
  -webkit-tap-highlight-color: transparent; text-decoration: none;
}
.st-btn:hover { border-color: var(--st-accent); background: var(--st-surface-sunken); }
.st-btn:active { transform: translateY(1px); }
.st-btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.st-btn--primary { background: var(--st-accent); border-color: var(--st-accent); color: var(--st-on-accent); }
.st-btn--primary:hover { background: var(--st-accent-strong); border-color: var(--st-accent-strong); }
.st-btn--ghost { background: transparent; border-color: transparent; color: var(--st-text-muted); }
.st-btn--ghost:hover { background: var(--st-surface-sunken); border-color: transparent; color: var(--st-text); }
.st-btn--danger { color: var(--st-danger); background: transparent; border-color: color-mix(in srgb, var(--st-danger) 40%, transparent); }
.st-btn--danger:hover { background: var(--st-danger-bg); border-color: var(--st-danger); }
.st-btn--block { width: 100%; }
.st-btn--lg { min-height: 42px; font-size: var(--st-text-md); padding: 0 18px; }
.st-btn--sm { min-height: 28px; padding: 0 10px; font-size: var(--st-text-sm); border-radius: 6px; }

.st-icon-btn {
  width: 34px; height: 34px; border-radius: 6px; flex-shrink: 0;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--st-frame-muted);
}
.st-icon-btn:hover { background: var(--st-frame-hover); color: var(--st-frame-text); }

/* ── Forms ───────────────────────────────────────────────── */
.st-field { display: flex; flex-direction: column; gap: 5px; }
.st-field + .st-field { margin-top: 12px; }
.st-label { font-size: var(--st-text-sm); font-weight: 700; color: var(--st-text-muted); }
.st-hint { font-size: var(--st-text-sm); color: var(--st-text-muted); }
.st-input, .st-select, .st-textarea {
  width: 100%; min-height: 36px; padding: 7px 11px;
  border: 1px solid var(--st-border-strong); border-radius: 6px;
  background: var(--st-surface); color: var(--st-text); font-size: var(--st-text-md);
  transition: border-color var(--st-fast) var(--st-ease), box-shadow var(--st-fast) var(--st-ease);
}
.st-textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.st-input::placeholder, .st-textarea::placeholder { color: var(--st-text-faint); }
/* Focused field: Fluix's yellow, not a blue ring */
.st-input:focus, .st-select:focus, .st-textarea:focus {
  outline: none; border-color: var(--st-selected-border); background: var(--st-selected);
}
.st-input[aria-invalid="true"] { border-color: var(--st-danger); }
.st-input--code { letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700; }
.st-input--pin { letter-spacing: 0.35em; font-weight: 700; font-size: var(--st-text-lg); text-align: center; }

/* ── Cards ───────────────────────────────────────────────── */
.st-card {
  background: var(--st-surface);
  border: 1px solid color-mix(in srgb, var(--st-border) 70%, transparent);
  border-radius: var(--st-radius);
  box-shadow: var(--st-shadow-sm);
  padding: 20px 24px;
}
.st-card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; min-height: 28px; }
.st-card__title {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.9375rem; font-weight: 600; color: var(--st-text); letter-spacing: -0.005em;
}
/* Heading over a group of cards ("Φέτος", "Τάση και κατηγορίες") */
.st-section-title { font-size: 1rem; font-weight: 600; color: var(--st-text); margin: 8px 0 -4px; }
.st-card__title svg { color: var(--st-text-faint); }

/* ── KPI cards: one number per card ──────────────────────── */
/* Cards share rows through a subgrid, so values line up even when a label wraps to two lines */
.st-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.st-kpi {
  grid-row: span 3; display: grid; grid-template-rows: subgrid; row-gap: 8px; align-content: start;
  padding: 18px 20px 20px; min-width: 0;
  background: var(--st-surface); border: 1px solid color-mix(in srgb, var(--st-border) 70%, transparent); border-radius: var(--st-radius);
  box-shadow: var(--st-shadow-sm);
}
button.st-kpi { text-align: left; font: inherit; color: inherit; cursor: pointer; }
button.st-kpi:hover { border-color: var(--st-border-strong); }
.st-kpi__label { align-self: end; font-size: 0.9375rem; font-weight: 400; color: var(--st-text-muted); }
.st-kpi__value { font-size: 1.625rem; font-weight: 500; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.st-kpi__sub { font-size: var(--st-text-sm); color: var(--st-text-faint); }
@media (max-width: 600px) {
  .st-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .st-kpi { padding: 14px 14px 16px; row-gap: 6px; }
  .st-kpi__value { font-size: 1.625rem; }
}
.st-kpi__sub--bad { color: var(--st-danger); font-weight: 600; }
.st-kpi__sub--good { color: var(--st-ok); font-weight: 600; }

/* ── Chips ───────────────────────────────────────────────── */
.st-chip {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 22px; padding: 1px 8px; border-radius: 5px;
  font-size: var(--st-text-sm); font-weight: 600; letter-spacing: 0;
  background: var(--st-surface-sunken); color: var(--st-text-muted);
  border: 1px solid var(--st-border); white-space: nowrap;
}
.st-chip--ok { background: var(--st-ok-bg); color: var(--st-ok-text); border-color: transparent; }
.st-chip--warn { background: var(--st-warn-bg); color: var(--st-warn-text); border-color: transparent; }
.st-chip--danger { background: var(--st-danger-bg); color: var(--st-danger-text); border-color: transparent; }
.st-chip--info { background: var(--st-info-bg); color: var(--st-info-text); border-color: transparent; }

/* ── Tables ──────────────────────────────────────────────── */
.st-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--st-border); border-radius: 6px; }
.st-card .st-table-wrap { border: 0; border-radius: 0; }
.st-table { width: 100%; border-collapse: collapse; font-size: var(--st-text-md); }
.st-table th {
  text-align: left; font-weight: 500; color: var(--st-text-faint); background: transparent;
  font-size: var(--st-text-xs); text-transform: uppercase; letter-spacing: .06em;
  padding: 10px 12px; border-bottom: 1px solid var(--st-border-strong); white-space: nowrap;
}
.st-table td { height: 56px; padding: 8px 12px; border-bottom: 1px solid var(--st-border); vertical-align: middle; }
.st-table tbody tr:last-child td { border-bottom: 0; }
.st-table tbody tr:hover td { background: color-mix(in srgb, var(--st-surface-sunken) 70%, transparent); }
.st-table tr.is-link { cursor: pointer; }
/* Record cell: the code in bold, the title underneath in the secondary colour */
.st-idcell { display: grid; gap: 1px; line-height: 1.3; }
.st-idcell b { font-weight: 600; color: var(--st-text); }
.st-idcell span { color: var(--st-text-muted); }
.st-num, .st-table th.st-num { text-align: right; font-variant-numeric: tabular-nums; }
/* Whose items: a small two-way switch, kept apart from the status tabs. */
.st-scope { display: inline-flex; padding: 2px; gap: 2px; border-radius: 6px; background: var(--st-surface-sunken); border: 1px solid var(--st-border); }
.st-scope button { min-height: 32px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--st-text-muted); font-weight: 600; font-size: var(--st-text-sm); white-space: nowrap; }
.st-scope button:hover { color: var(--st-text); }
.st-scope button[aria-pressed="true"] { background: var(--st-surface); color: var(--st-text); box-shadow: var(--st-shadow-sm); }
@media (max-width: 600px) { .st-hide-sm { display: none; } }

/* Phones: every table becomes a list of compact cards. The first cell is the
   card's title; every other cell shows its column name (data-label, filled
   in from the header by ui.js). Empty cells disappear. */
@media (max-width: 600px) {
  .st-table-wrap { border: 0; border-radius: 0; overflow: visible; }
  .st-table thead { display: none; }
  .st-table, .st-table tbody, .st-table tr { display: block; width: 100%; }
  .st-table tr {
    padding: 9px 12px; margin-bottom: 6px; border: 1px solid var(--st-border); border-radius: 6px; background: var(--st-surface);
  }
  .st-table tbody tr:last-child { margin-bottom: 0; }
  .st-table tbody tr:hover td { background: transparent; }
  .st-table tr.st-me-row { background: var(--st-selected); }
  .st-table td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: auto; padding: 1px 0; border: 0; text-align: right; font-size: var(--st-text-sm); min-height: 22px;
  }
  .st-table td:empty, .st-table td.st-hide-sm { display: none; }
  .st-table td::before {
    content: attr(data-label); flex-shrink: 0; text-align: left;
    font-size: 0.65625rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--st-text-faint);
  }
  .st-table td[data-label=""]::before { content: none; }
  .st-table td[data-label=""] { justify-content: flex-start; flex-wrap: wrap; padding-top: 6px; }
  .st-table td:first-child { display: block; text-align: left; padding: 0 0 4px; font-size: var(--st-text-md); }
  .st-table td:first-child::before { content: none; }
  /* Inside a card the rows are a plain list: no card within a card. */
  .st-card .st-table tr { border: 0; border-bottom: 1px solid var(--st-border); border-radius: 0; margin: 0; padding: 10px 0; background: transparent; }
  .st-card .st-table tbody tr:last-child { border-bottom: 0; padding-bottom: 0; }
  .st-card .st-table tbody tr:first-child { padding-top: 0; }
  .st-card .st-table tr.st-me-row { background: var(--st-selected); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 6px; }
  .st-card { padding: 14px; }
}

/* ── Tabs (underline) ────────────────────────────────────── */
.st-tabs { display: inline-flex; gap: 2px; border-bottom: 1px solid var(--st-border); max-width: 100%; overflow-x: auto; }
.st-tabs__btn {
  position: relative; min-height: 34px; padding: 0 12px; border: 0; background: transparent;
  font-weight: 600; font-size: var(--st-text-md); color: var(--st-text-muted); white-space: nowrap;
}
.st-tabs__btn:hover { color: var(--st-text); }
/* Phones: the tabs share the full width and always fit, nothing hides off-screen. */
@media (max-width: 600px) {
  .st-tabs { display: flex; width: 100%; overflow: visible; gap: 0; }
  .st-tabs__btn { flex: 1 1 auto; min-width: 0; min-height: 40px; padding: 0 4px; font-size: var(--st-text-sm); }
}
.st-tabs__btn[aria-selected="true"] { color: var(--st-text); }
.st-tabs__btn[aria-selected="true"]::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: 0; height: 2px; border-radius: 2px; background: var(--st-accent);
}
.st-count { font-variant-numeric: tabular-nums; color: var(--st-text-faint); margin-left: 4px; font-weight: 600; }

/* ── Feedback ────────────────────────────────────────────── */
.st-alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 6px;
  font-size: var(--st-text-md); background: var(--st-info-bg); color: var(--st-text);
}
.st-alert > svg { color: var(--st-info); flex-shrink: 0; margin-top: 1px; }
.st-alert__text { min-width: 0; flex: 1 1 auto; }
.st-alert--danger { background: var(--st-danger-bg); }
.st-alert--danger > svg { color: var(--st-danger); }
.st-alert--ok { background: var(--st-ok-bg); }
.st-alert--ok > svg { color: var(--st-ok); }
.st-alert--warn { background: var(--st-warn-bg); }
.st-alert--warn > svg { color: var(--st-warn); }

.st-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
  padding: 32px 16px; color: var(--st-text-muted); font-size: var(--st-text-md);
}
.st-empty__icon { color: var(--st-text-faint); }
.st-empty__title { font-weight: 700; color: var(--st-text); }

.st-spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor; animation: st-spin .8s linear infinite;
}
@keyframes st-spin { to { transform: rotate(360deg); } }

.st-toast-host {
  position: fixed; z-index: 1000; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px; width: min(92vw, 360px);
}
.st-toast {
  padding: 10px 14px; border-radius: 6px; font-weight: 600; font-size: var(--st-text-md);
  background: var(--fx-neutral-8); color: #FFFFFF; box-shadow: var(--st-shadow-lg);
  animation: st-rise var(--st-med) var(--st-ease);
}
.st-toast--danger { background: var(--st-danger); color: #fff; }
@keyframes st-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (max-width: 680px) {
  .st-toast-host { left: 50%; right: auto; transform: translateX(-50%); bottom: calc(var(--st-bottomnav-height) + 14px + env(safe-area-inset-bottom)); }
}

/* ── Modal ───────────────────────────────────────────────── */
.st-modal-backdrop {
  position: fixed; inset: 0; z-index: 900; background: rgba(10, 20, 20, .5);
  display: grid; place-items: center; padding: 16px; animation: st-fade var(--st-med) var(--st-ease);
}
.st-modal {
  width: min(540px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--st-surface); color: var(--st-text); border: 1px solid var(--st-border); border-radius: var(--st-radius-lg);
  box-shadow: var(--st-shadow-lg); padding: 20px;
  animation: st-rise var(--st-med) var(--st-ease);
}
.st-modal--wide { width: min(920px, 100%); }
.st-modal__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.st-modal__head h2 { font-size: var(--st-text-lg); }
.st-modal__head .st-icon-btn { color: var(--st-text-muted); }
.st-modal__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
@keyframes st-fade { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 600px) {
  .st-modal-backdrop { place-items: end center; padding: 0; }
  .st-modal { border-radius: var(--st-radius-lg) var(--st-radius-lg) 0 0; width: 100%; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* A tab or filter changed and new rows are on the way: the old ones fade, so they
   are never mistaken for the answer. */
.st-stack[aria-busy="true"] > :is(.st-list, .st-card, .st-kpis, .st-grid-main, .st-grid-2, .st-alert) {
  opacity: .4; pointer-events: none; transition: opacity var(--st-fast) var(--st-ease);
}

/* ── Loading ─────────────────────────────────────────────── */
/* Start-up splash: the mark in the middle of the screen with a thin running bar.
   The page renders it before any script, and the app keeps the same markup until it is ready. */
.st-boot {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--st-frame); color: var(--st-frame-accent);
}
.st-boot__name { font-family: var(--st-font); font-weight: 800; font-size: 1.375rem; letter-spacing: -0.02em; color: var(--st-frame-text); }
.st-boot__name b { color: var(--st-frame-accent); font-weight: inherit; }
.st-boot__bar { position: relative; width: 120px; height: 3px; border-radius: 3px; overflow: hidden; background: rgba(255, 255, 255, .14); }
.st-boot__bar i { position: absolute; top: 0; bottom: 0; width: 40%; border-radius: 3px; background: var(--st-frame-accent); animation: st-boot-run 1.1s var(--st-ease) infinite; }
@keyframes st-boot-run { from { left: -40%; } to { left: 100%; } }

/* A spinner inside a card or list keeps a steady height and sits in the middle */
.st-loading { min-height: 200px; justify-content: center; }

/* A page still loading: shapes where its title, number cards and first cards will be */
/* The shapes look like the white cards that replace them, with a soft light passing over */
.st-skeleton i {
  display: block; border-radius: var(--st-radius);
  border: 1px solid color-mix(in srgb, var(--st-border) 70%, transparent); box-shadow: var(--st-shadow-sm);
  background: linear-gradient(90deg, var(--st-surface) 0%, color-mix(in srgb, var(--st-surface) 55%, var(--st-border)) 50%, var(--st-surface) 100%);
  background-size: 200% 100%; animation: st-shimmer 1.4s linear infinite;
}
.st-skeleton__head { display: grid; gap: 8px; padding: 6px 0 18px; border-bottom: 1px solid var(--st-border); }
.st-skeleton__head i { height: 20px; border-radius: 4px; border: 0; box-shadow: none;
  background: linear-gradient(90deg, var(--st-border) 0%, color-mix(in srgb, var(--st-border) 50%, var(--st-bg)) 50%, var(--st-border) 100%);
  background-size: 200% 100%; }
.st-skeleton__kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.st-skeleton__kpis i { height: 122px; }
.st-skeleton__label { margin: 8px 0 -4px; }
.st-skeleton__label i { width: 72px; height: 16px; border: 0; box-shadow: none; border-radius: 4px; background: var(--st-border); animation: none; }
.st-skeleton__cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; }
.st-skeleton__cards i { height: 260px; }
@keyframes st-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .st-boot__bar i, .st-skeleton i { animation: none; } .st-boot__bar i { left: 30%; } }

/* On/off row (ST.Toggle) */
.st-toggle { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px; text-align: left;
  border: 1px solid var(--st-border); border-radius: var(--st-radius); background: var(--st-surface); color: var(--st-text); cursor: pointer; font: inherit; }
.st-toggle:hover { border-color: var(--st-border-strong); }
.st-toggle:focus-visible { outline: 2px solid var(--st-focus); outline-offset: 2px; }
.st-toggle[aria-checked="true"] { border-color: var(--st-selected-border); background: var(--st-selected); }
.st-toggle:disabled { opacity: .55; cursor: default; }
.st-toggle__icon { display: inline-flex; color: var(--st-text-muted); flex: none; }
.st-toggle__text { flex: 1 1 auto; min-width: 0; font-weight: 700; }
.st-toggle__sub { display: block; margin-top: 2px; font-weight: 400; font-size: var(--st-text-sm); color: var(--st-text-muted); }
.st-toggle__track { position: relative; flex: none; width: 42px; height: 24px; border-radius: 999px; background: var(--st-border-strong); transition: background var(--st-fast) var(--st-ease); }
.st-toggle__track i { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--st-surface); box-shadow: var(--st-shadow-sm); transition: transform var(--st-fast) var(--st-ease); }
.st-toggle[aria-checked="true"] .st-toggle__track { background: var(--st-accent); }
.st-toggle[aria-checked="true"] .st-toggle__track i { transform: translateX(18px); }
