/* ═══════════════════════════════════════════════════════════
   shosho — design tokens
   Dark theme; the accent gradient nods to Instagram without
   copying its branding.
════════════════════════════════════════════════════════════ */
:root {
  --bg:        #0d0b14;
  --surface:   #171426;
  --surface2:  #1f1b31;
  --border:    #2e2844;
  --text:      #efeaf6;
  --text2:     #9b93b5;
  --accent:    #c13584;
  --accent2:   #f56040;
  --gradient:  linear-gradient(135deg, #405de6, #c13584 55%, #fcaf45);
  --green:     #3ecf8e;
  --red:       #f2557a;
  --yellow:    #f5c451;
  --radius:    14px;
  --shadow:    0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.45;
}

/* Usernames are always latin. Wrap them in an inline LTR island so bidi can't
   reorder "@name", while the surrounding cell keeps the page's alignment.
   (Setting direction on the cell itself would drag its content to the far
   edge, since `start` flips with direction.) */
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

.hidden { display: none !important; }
.muted  { color: var(--text2); font-size: 13px; }

/* ── buttons & inputs ─────────────────────────────────────── */
.btn, .ghost {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  padding: 9px 16px;
  transition: filter .15s, border-color .15s;
}
.btn:hover, .ghost:hover { filter: brightness(1.25); }
.btn.primary {
  background: var(--gradient);
  border: none;
  color: #fff;
  font-weight: 600;
}
.ghost { background: transparent; color: var(--text2); }
.ghost:hover { color: var(--text); border-color: var(--accent); }
.ghost.small { padding: 5px 11px; font-size: 13px; }

input[type=password], input[type=search] {
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 13px;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── login ────────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 40px 34px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.logo {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  direction: ltr;
}
.logo.small { font-size: 24px; }
.login-sub { color: var(--text2); margin: 6px 0 24px; font-size: 14px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
.error-msg { color: var(--red); font-size: 14px; min-height: 20px; margin-top: 10px; }
.lang-toggle { margin-top: 8px; font-size: 13px; }

/* ── top bar ──────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 22px;
  background: var(--surface);
  border-block-end: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.tab {
  font: inherit;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text2);
  padding: 8px 15px;
  border-radius: 10px;
}
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active { color: #fff; background: var(--gradient); font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; }

.content { padding: 26px 22px 60px; max-width: 1180px; margin: 0 auto; }

/* ── panels ───────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-block-end: 20px;
}
.panel h3 {
  font-size: 16px;
  margin-block-end: 4px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.panel-sub { color: var(--text2); font-size: 13px; margin-block-end: 14px; }
.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

/* ── stat tiles ───────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-block-end: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: '';
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  width: 100%;
  height: 3px;
  background: var(--gradient);
  opacity: .8;
}
/* Digits need no direction override — bidi already renders "1,017" correctly
   in both directions, and forcing LTR would push them to the wrong edge. */
.stat .value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--text2); font-size: 13px; margin-block-start: 4px; }
.stat .delta { font-size: 12px; margin-block-start: 6px; }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: var(--accent); }
.delta.up   { color: var(--green); }
.delta.down { color: var(--red); }

.pill {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}
.pill:empty { display: none; }
.pill.up   { background: rgba(62, 207, 142, .16); color: var(--green); }
.pill.down { background: rgba(242, 85, 122, .16); color: var(--red); }
/* "0 removed" isn't bad news — don't colour it like a loss. */
.pill.zero { background: var(--surface2); color: var(--text2); }

/* ── sparkline ────────────────────────────────────────────── */
.spark { display: block; width: 100%; height: 26px; margin-block-start: 8px; }

/* ── pie / donut charts ───────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
  margin-block-end: 20px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.chart-card h3 { font-size: 15px; margin-block-end: 2px; }
.chart-card .panel-sub { margin-block-end: 16px; }
.chart-body { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; flex-shrink: 0; }
.donut .slice { transition: stroke-width .15s; }
.donut .slice:hover { stroke-width: 30; }
.donut-total { font-size: 26px; font-weight: 700; fill: var(--text); }
.donut-caption { font-size: 11px; fill: var(--text2); }

.legend { flex: 1; min-width: 150px; display: grid; gap: 9px; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
}
.legend-label { flex: 1; }
.legend-val { color: var(--text2); font-size: 13px; white-space: nowrap; }

/* ── star rating ──────────────────────────────────────────── */
.stars { display: inline-flex; gap: 1px; direction: ltr; }
.star {
  font: inherit;
  line-height: 1;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0 1px;
  color: var(--border);
  font-size: 16px;
  transition: color .1s, transform .1s;
}
.star:hover { transform: scale(1.2); }
.star.on { color: var(--yellow); }
/* Preview the rating you'd get by releasing here: light up this star and
   every one before it. */
.stars:hover .star { color: var(--border); }
.stars:hover .star.on { color: var(--border); }
.stars .star:hover, .stars .star:hover ~ .star { color: var(--yellow); }

.cat-select, .filter {
  font: inherit;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  max-width: 170px;
}
.filter { padding: 9px 10px; font-size: 14px; }
.cat-select:focus, .filter:focus { outline: 2px solid var(--accent); }
.cat-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-inline-end: 6px;
  vertical-align: middle;
}

.row-del {
  font: inherit;
  cursor: pointer;
  background: none;
  border: 1px solid transparent;
  color: var(--text2);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 14px;
}
.row-del:hover { color: var(--red); border-color: var(--red); }

/* ── inline forms (add user, add category) ────────────────── */
.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-block: 14px;
}
.inline-form input[type=text] {
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  flex: 1;
  min-width: 150px;
}
.inline-form input[type=color] {
  width: 44px;
  height: 40px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.btn.small { padding: 6px 13px; font-size: 13px; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 0;
  border-block-end: 1px solid var(--border);
  flex-wrap: wrap;
}
.cat-row:last-of-type { border-block-end: none; }
.cat-row .cat-name { flex: 1; min-width: 110px; max-width: 320px; }
.inline-form input[type=text] { max-width: 340px; }
.cat-row .cat-count { color: var(--text2); font-size: 13px; }

/* ── mini lists (recent gains / losses) ───────────────────── */
.mini-list { max-height: 300px; overflow-y: auto; }
.mini-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-block-end: 1px solid var(--border);
}
.mini-row:last-child { border-block-end: none; }
.mini-row a { color: var(--text); text-decoration: none; }
.mini-row a:hover { color: var(--accent2); text-decoration: underline; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gradient);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  direction: ltr;
}

/* ── chips ────────────────────────────────────────────────── */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-block-end: 18px; }
.chip {
  font: inherit;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  /* flex gap, not a margin — it spaces the count from the label in both
     directions without depending on which side `inline-start` lands on. */
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active { background: var(--gradient); color: #fff; border-color: transparent; font-weight: 600; }
.chip .n { opacity: .75; font-size: 12px; }

/* Separates the exported lists from the computed ones in the same chip row. */
.chip-group-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-inline-start: 6px;
}
.chip-group-label::before {
  content: '';
  width: 1px;
  height: 20px;
  background: var(--border);
}
.chip:disabled { opacity: .4; cursor: not-allowed; }

/* ── tables ───────────────────────────────────────────────── */
.table-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-block-end: 14px;
  flex-wrap: wrap;
}
.table-toolbar input { flex: 1; min-width: 180px; }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th {
  text-align: start;
  color: var(--text2);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 8px 10px;
  border-block-end: 1px solid var(--border);
  white-space: nowrap;
}
table.tbl th.sortable { cursor: pointer; user-select: none; }
table.tbl th.sortable:hover { color: var(--text); }
table.tbl th.sorted { color: var(--accent2); }
/* Reserve the arrow's width so headers don't shift as the sort column moves. */
table.tbl th .arrow {
  display: inline-block;
  width: 1em;
  font-size: 9px;
  margin-inline-start: 3px;
}

table.tbl td { padding: 9px 10px; border-block-end: 1px solid var(--border); }
table.tbl tr:hover td { background: var(--surface2); }
table.tbl a { color: var(--text); text-decoration: none; }
table.tbl a:hover { color: var(--accent2); text-decoration: underline; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text2);
  white-space: nowrap;
}
.badge.yes { border-color: rgba(62, 207, 142, .5); color: var(--green); }
.badge.no  { border-color: rgba(242, 85, 122, .4); color: var(--red); }

.load-more { display: block; margin: 16px auto 0; }
.list-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}
.summary-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.summary-item:hover { border-color: var(--accent); }
.summary-item .n { font-size: 20px; font-weight: 700; }
.summary-item .l { color: var(--text2); font-size: 13px; }
.summary-item .d { color: var(--text2); font-size: 11px; margin-block-start: 3px; }

/* ── upload ───────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--text2);
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--surface2); color: var(--text); }
.dz-icon { font-size: 34px; margin-block-end: 8px; }
.dropzone .btn { margin-block-start: 14px; }

.result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-block-end: 1px solid var(--border);
  flex-wrap: wrap;
}
.result-row:last-child { border-block-end: none; }
.result-name { font-weight: 600; min-width: 150px; }
.progress {
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-block-start: 14px;
}
.progress > div { height: 100%; background: var(--gradient); width: 0; transition: width .2s; }

/* ── empty state ──────────────────────────────────────────── */
.empty { text-align: center; padding: 70px 20px; color: var(--text2); }
.empty-icon { font-size: 52px; margin-block-end: 12px; }
.empty h2 { color: var(--text); margin-block-end: 8px; }
.empty p { margin-block-end: 20px; }

/* ── toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 50;
}

@media (max-width: 620px) {
  .content { padding: 18px 12px 50px; }
  .panel { padding: 16px 14px; }
  .stat .value { font-size: 25px; }

  /* Two rows: logo + actions, then the tabs scrolling horizontally under them.
     Reordering with `order` avoids an extra wrapper element in the markup. */
  .topbar { padding: 10px 12px; gap: 10px; }
  .logo.small { order: 1; }
  .topbar-actions { order: 2; margin-inline-start: auto; }
  .tabs { order: 3; flex: 0 0 100%; flex-wrap: nowrap; overflow-x: auto; }
  .tab { flex-shrink: 0; white-space: nowrap; }
}
