/* ============================================================
   TCG Tracker — "Holo Foil" design system
   Canvas #0D0B14 · Surface #16121F · Border #241B33
   Violet #8B5CF6 (hover #A78BFA) · Cyan #2DD4BF · Magenta #EC4899
   Text #ECEAF3 / muted #9A93AD
   ============================================================ */

:root {
  --bg: #0D0B14;
  --surface: #16121F;
  --surface-2: #1C1729;
  --border: #241B33;
  --primary: #8B5CF6;
  --primary-hover: #A78BFA;
  --cyan: #2DD4BF;
  --magenta: #EC4899;
  --text: #ECEAF3;
  --muted: #9A93AD;
  --danger: #F87171;
  --holo: linear-gradient(100deg, #8B5CF6 0%, #2DD4BF 50%, #EC4899 100%);
  --radius: 1rem; /* rounded-2xl feel */
  --font: "Space Grotesk", "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(139, 92, 246, 0.08), transparent 60%),
    radial-gradient(900px 400px at -10% 30%, rgba(45, 212, 191, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--primary-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--border);
  background: rgba(22, 18, 31, 0.6);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav-links { display: flex; flex-direction: column; gap: 0.35rem; }

.brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 0.5rem 1.25rem;
  background: var(--holo);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand small { display: block; color: var(--muted); -webkit-text-fill-color: var(--muted); font-weight: 400; font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; }

.nav-link {
  padding: 0.55rem 0.75rem;
  border-radius: 0.6rem;
  color: var(--muted);
  font-weight: 500;
  transition: all 0.15s ease;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-link.active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.18), rgba(45, 212, 191, 0.07));
  box-shadow: inset 2px 0 0 var(--primary);
}

.logout-form { margin-top: auto; }

main.content { flex: 1; padding: 2rem 2.25rem 4rem; max-width: 1200px; }

h1.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 1.5rem;
  background: var(--holo);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  width: fit-content;
}

h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.75rem; }

/* ---------- cards & tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
td { padding: 0.7rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.row-instock td { background: rgba(236, 72, 153, 0.045); }

.cell-label { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 0.78rem; margin-top: 0.1rem; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge-instock {
  color: #FBCFE8;
  background: rgba(236, 72, 153, 0.14);
  border-color: rgba(236, 72, 153, 0.45);
  box-shadow: 0 0 12px rgba(236, 72, 153, 0.35);
}
.badge-oos { color: var(--muted); background: var(--surface-2); border-color: var(--border); }
.badge-unknown { color: #C4B5FD; background: rgba(139, 92, 246, 0.1); border-color: rgba(139, 92, 246, 0.3); }
.badge-off { color: var(--muted); background: transparent; border-color: var(--border); opacity: 0.7; }

.badge-game { border-color: var(--border); background: var(--surface-2); color: var(--cyan); }
.badge-game.pokemon { color: var(--primary-hover); }

.badge-event { background: rgba(45, 212, 191, 0.1); border-color: rgba(45, 212, 191, 0.35); color: #99F6E4; }
.badge-event.BACK_IN_STOCK, .badge-event.NEW_LISTING {
  background: rgba(236, 72, 153, 0.12);
  border-color: rgba(236, 72, 153, 0.4);
  color: #FBCFE8;
}

.ok { color: var(--cyan); }
.fail { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 0.78rem; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--primary); box-shadow: 0 0 14px rgba(139, 92, 246, 0.25); text-decoration: none; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-ghost { background: transparent; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; border-radius: 0.5rem; }
.btn-danger:hover { border-color: var(--danger); box-shadow: 0 0 12px rgba(248, 113, 113, 0.25); }

label { display: block; color: var(--muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; margin: 0 0 0.3rem; }

input, select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { margin-top: 1.25rem; display: flex; gap: 0.75rem; }

/* ---------- misc ---------- */
.flash {
  padding: 0.7rem 1rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(45, 212, 191, 0.4);
  background: rgba(45, 212, 191, 0.08);
  color: #99F6E4;
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
}

.news-item { display: flex; gap: 1rem; padding: 1rem 0; border-bottom: 1px solid var(--border); }
.news-item:last-child { border-bottom: none; }
.news-thumb {
  width: 88px;
  height: 66px;
  object-fit: cover;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface-2);
}
.news-title { font-weight: 600; }
.news-meta { color: var(--muted); font-size: 0.78rem; margin-top: 0.2rem; display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.kv { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px dashed var(--border); font-size: 0.85rem; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 340px; text-align: center; }
.login-card .brand { margin: 0 auto 1.5rem; font-size: 1.4rem; }

.empty { color: var(--muted); text-align: center; padding: 2.5rem 1rem; font-size: 0.9rem; }

.holo-divider { height: 1px; border: none; background: var(--holo); opacity: 0.35; margin: 1.5rem 0; }

/* ---------- collapsible "add" panel + search + button feedback ---------- */
.add-panel { margin-bottom: 1.5rem; }
.add-toggle {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border-radius: 0.65rem;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}
.add-toggle::-webkit-details-marker { display: none; }
.add-toggle:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.add-panel[open] > .add-toggle { background: var(--surface-2); color: var(--text); border-color: var(--border); margin-bottom: 1rem; }
.add-panel[open] > .add-toggle::before { content: "✕ "; }
.add-panel .card { margin-bottom: 0; }

.watch-search { margin-bottom: 1rem; }
.watch-count { margin-top: 0.75rem; text-align: right; }

/* HTMX: show a button is working (dim + block double-taps while loading) */
.btn.htmx-request { opacity: 0.5; pointer-events: none; }
tbody.htmx-request { opacity: 0.6; transition: opacity 0.1s ease; }

/* ============================================================
   Mobile / tablet — compact top bar, scrollable nav, card tables
   ============================================================ */
@media (max-width: 800px) {
  .shell { flex-direction: column; }

  /* Sidebar becomes a sticky compact top bar: brand | logout on row 1,
     a horizontally scrollable nav strip on row 2. */
  .sidebar {
    width: 100%;
    height: auto;
    padding: 0.7rem 1rem;
    gap: 0.6rem;
    position: sticky;
    top: 0;
    z-index: 30;
    border-right: none;
    border-bottom: 1px solid var(--border);
    background: rgba(13, 11, 20, 0.94);
    backdrop-filter: blur(10px);
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand logout"
      "nav   nav";
    align-items: center;
  }
  .brand { grid-area: brand; margin: 0; font-size: 1.05rem; }
  .brand small { display: inline; margin-left: 0.5rem; }
  .logout-form { grid-area: logout; margin: 0; }

  .nav-links {
    grid-area: nav;
    flex-direction: row;
    gap: 0.4rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.15rem;
    margin: 0 -1rem;          /* bleed to the screen edges */
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-link { white-space: nowrap; flex-shrink: 0; padding: 0.45rem 0.8rem; }
  .nav-link.active { box-shadow: inset 0 -2px 0 var(--primary); }

  main.content { padding: 1.1rem 1rem 3rem; }
  h1.page-title { font-size: 1.35rem; margin-bottom: 1rem; }
  .card { padding: 1rem; border-radius: 0.85rem; }
  .form-grid .span-2 { grid-column: span 1; }
}

/* Phone: turn wide data tables into stacked cards so nothing needs
   horizontal scrolling, and make tap targets finger-friendly. */
@media (max-width: 640px) {
  /* iOS zooms when an input font is < 16px on focus — pin to 16px. */
  input, select { font-size: 16px; padding: 0.65rem 0.7rem; }

  .table-wrap { overflow-x: visible; }
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }

  .table-wrap tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 0.4rem 0.9rem;
    margin-bottom: 0.85rem;
  }
  .table-wrap tr:last-child { margin-bottom: 0; }
  tr.row-instock { border-color: rgba(236, 72, 153, 0.45); }
  tr.row-instock td { background: transparent; }

  /* label : value rows for the short cells (those carry data-label) */
  .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
  }
  .table-wrap td:last-child { border-bottom: none; }
  .table-wrap td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: left;
    flex-shrink: 0;
  }

  /* cells with no data-label (product/name, actions) span the full width */
  .table-wrap td:not([data-label]) {
    display: block;
    text-align: left;
  }
  .cell-sub { max-width: none; white-space: normal; }

  /* action button clusters: full-width, wrapping, finger-sized */
  .row-actions { justify-content: flex-start !important; flex-wrap: wrap; }
  .row-actions .btn { flex: 1 1 auto; justify-content: center; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 38px; padding: 0.4rem 0.7rem; font-size: 0.8rem; }

  .news-item { gap: 0.7rem; }
  .news-thumb { width: 64px; height: 48px; }
  .stat-grid { grid-template-columns: 1fr; }
}
