:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7ebf3;
  --muted: #9aa3b2;
  --accent: #6aa6ff;
  --accent-2: #4d8bff;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --warn: #fbbf24;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, video { max-width: 100%; }

/* Mobile burger button — hidden on desktop */
.nav-burger { display: none; background: none; border: none; color: var(--text); padding: 8px; cursor: pointer; border-radius: 8px; }
.nav-burger:hover { background: var(--panel-2); }
.nav-burger-icon { display: block; width: 22px; height: 2px; background: currentColor; position: relative; transition: background .15s; }
.nav-burger-icon::before, .nav-burger-icon::after {
  content: ''; position: absolute; left: 0; width: 22px; height: 2px; background: currentColor;
  transition: transform .2s;
}
.nav-burger-icon::before { top: -7px; }
.nav-burger-icon::after  { top: 7px; }
.topbar.nav-open .nav-burger-icon { background: transparent; }
.topbar.nav-open .nav-burger-icon::before { transform: translateY(7px) rotate(45deg); }
.topbar.nav-open .nav-burger-icon::after  { transform: translateY(-7px) rotate(-45deg); }

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: inline-flex; align-items: center; gap: 12px;
  font-weight: 700; font-size: 16px; color: var(--text);
  text-decoration: none;
}
.topbar .brand:hover { text-decoration: none; }
.brand-logo {
  height: 28px; width: auto; display: block;
  filter: drop-shadow(0 2px 6px rgba(241, 90, 41, .25));
}
.brand-divider {
  width: 1px; height: 22px; background: var(--border);
  display: inline-block;
}
.brand-name {
  font-weight: 800; letter-spacing: .12em; font-size: 13px;
  text-transform: uppercase; color: var(--text);
}
.brand-name-accent {
  background: linear-gradient(135deg, #f7931e 0%, #f15a29 50%, #e63946 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.topbar nav { display: flex; gap: 4px; flex: 1; align-items: center; }
.topbar nav > a {
  color: var(--muted); font-weight: 500;
  padding: 6px 10px; border-radius: 8px;
  transition: color .15s ease, background .15s ease;
}
.topbar nav > a:hover {
  color: var(--text); background: var(--panel-2);
  text-decoration: none;
}

.nav-drop { position: relative; display: inline-block; }
.nav-drop-trigger {
  color: var(--muted); font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
  transition: color .15s ease, background .15s ease;
}
.nav-drop-trigger::after {
  content: ''; width: 6px; height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  opacity: .55;
}
.nav-drop:hover .nav-drop-trigger,
.nav-drop:focus-within .nav-drop-trigger,
.nav-drop.open .nav-drop-trigger {
  color: var(--text); background: var(--panel-2);
}
.nav-drop:hover .nav-drop-trigger::after,
.nav-drop:focus-within .nav-drop-trigger::after,
.nav-drop.open .nav-drop-trigger::after {
  transform: rotate(-135deg) translate(0, 0);
  opacity: 1;
}

/* invisible hover bridge so cursor moving down to menu doesn't lose hover */
.nav-drop::after {
  content: ''; position: absolute;
  top: 100%; left: -8px; height: 16px;
  width: 240px;
}

.nav-drop-menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 220px;
  background: rgba(24, 27, 34, .85);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  padding: 6px; z-index: 50;
  box-shadow:
    0 16px 48px rgba(0,0,0,.45),
    0 2px 8px rgba(0,0,0,.25),
    inset 0 1px 0 rgba(255,255,255,.04);
  opacity: 0; visibility: hidden;
  transform: translateY(-6px) scale(.98);
  transform-origin: top left;
  transition:
    opacity .18s ease,
    transform .22s cubic-bezier(.4,0,.2,1),
    visibility .18s;
}
.nav-drop:hover .nav-drop-menu,
.nav-drop:focus-within .nav-drop-menu,
.nav-drop.open .nav-drop-menu {
  opacity: 1; visibility: visible;
  transform: translateY(0) scale(1);
}
.nav-drop-menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  color: var(--text); font-size: 13px; font-weight: 500;
  position: relative;
  transition: background .15s ease, color .15s ease, padding-left .15s ease;
}
.nav-drop-menu a::before {
  content: ''; width: 3px; height: 14px;
  background: var(--accent); border-radius: 3px;
  opacity: 0; transform: scaleY(.4);
  transition: opacity .15s, transform .15s;
}
.nav-drop-menu a:hover {
  background: rgba(106, 166, 255, .08);
  color: var(--accent);
  text-decoration: none;
}
.nav-drop-menu a:hover::before { opacity: 1; transform: scaleY(1); }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.btn-link { color: var(--accent); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

.auth-wrap { max-width: 380px; margin: 80px auto; padding: 32px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.auth-wrap h1 { margin: 0 0 4px; font-size: 22px; }
.auth-wrap p.sub { margin: 0 0 24px; color: var(--muted); }

label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }

button, .btn {
  display: inline-block; padding: 10px 16px; background: var(--accent-2); color: white;
  border: none; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
button:hover, .btn:hover { background: var(--accent); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger, .btn.danger { background: var(--danger); }
button.small, .btn.small { padding: 6px 10px; font-size: 12px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash-success { background: rgba(74, 222, 128, .15); color: var(--ok); border: 1px solid rgba(74, 222, 128, .3); }
.flash-error   { background: rgba(255, 107, 107, .15); color: var(--danger); border: 1px solid rgba(255, 107, 107, .3); }
.flash-info    { background: rgba(106, 166, 255, .15); color: var(--accent); border: 1px solid rgba(106, 166, 255, .3); }

h1, h2, h3 { line-height: 1.25; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }

.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-dash { grid-template-columns: 2fr 1fr; }
@media (max-width: 800px) { .grid-dash { grid-template-columns: 1fr; } }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.card h2 { margin: 0 0 14px; font-size: 16px; }

/* Module tiles on dashboard */
.tile-grid {
  display: grid; gap: 16px; margin-bottom: 28px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.tile {
  position: relative; display: flex; align-items: center; gap: 16px;
  padding: 20px; border-radius: 16px; color: var(--text);
  background: linear-gradient(135deg, var(--tile-from) 0%, var(--tile-to) 100%);
  border: 1px solid var(--tile-border);
  overflow: hidden; isolation: isolate;
  transition: transform .25s cubic-bezier(.4,0,.2,1), box-shadow .25s ease, border-color .25s ease;
}
.tile::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 100% 0%, rgba(255,255,255,.08) 0%, transparent 50%);
  pointer-events: none; z-index: -1;
}
.tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0,0,0,.35), 0 0 0 1px var(--tile-accent);
  text-decoration: none;
  border-color: var(--tile-accent);
}
.tile-icon {
  width: 52px; height: 52px; flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 26px;
  background: rgba(255,255,255,.06);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
}
.tile:hover .tile-icon { background: rgba(255,255,255,.1); }
.tile-meta { flex: 1; min-width: 0; }
.tile-meta h3 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.tile-meta p { margin: 2px 0 8px; color: var(--muted); font-size: 12px; }
.tile-stats { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.tile-stats b { color: var(--text); font-weight: 700; font-size: 13px; }
.tile-stats .ok   { color: var(--ok); }
.tile-stats .warn { color: var(--warn); }
.tile-arrow {
  font-size: 20px; color: var(--muted);
  transition: transform .25s, color .25s;
}
.tile:hover .tile-arrow { transform: translateX(4px); color: var(--text); }

.tile-blue   { --tile-from: #1f2840; --tile-to: #181b22; --tile-border: rgba(106,166,255,.15); --tile-accent: var(--accent); }
.tile-orange { --tile-from: #2a1e18; --tile-to: #1e1a18; --tile-border: rgba(241,90,41,.18);   --tile-accent: #f15a29; }
.tile-green  { --tile-from: #16261d; --tile-to: #181b22; --tile-border: rgba(74,222,128,.15);  --tile-accent: var(--ok); }
.tile-violet { --tile-from: #251a30; --tile-to: #1d1822; --tile-border: rgba(167,139,250,.18); --tile-accent: #a78bfa; }
.tile-cyan   { --tile-from: #142a30; --tile-to: #181b22; --tile-border: rgba(6,182,212,.18);  --tile-accent: #06b6d4; }

.link-card { display: flex; gap: 12px; align-items: center; padding: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.link-card .icon { width: 36px; height: 36px; display: grid; place-items: center; background: var(--panel-2); border-radius: 8px; font-size: 18px; flex-shrink: 0; }
.link-card .meta { flex: 1; min-width: 0; }
.link-card .meta .t { font-weight: 600; }
.link-card .meta .u { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-card .actions { opacity: 0; transition: opacity .15s; }
.link-card:hover .actions { opacity: 1; }

.todo { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; }
.todo:hover { background: var(--panel-2); }
.todo input[type=checkbox] { margin-top: 4px; }
.todo .body { flex: 1; }
.todo .body .t { font-weight: 500; }
.todo.done .body .t { text-decoration: line-through; color: var(--muted); }
.todo .meta { color: var(--muted); font-size: 12px; }
.pri-high { color: var(--danger); }
.pri-low  { color: var(--muted); }

.note-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.note-card.pinned { border-color: var(--warn); }
.note-card h3 { margin: 0 0 6px; font-size: 14px; }
.note-card .body { color: var(--muted); font-size: 13px; max-height: 80px; overflow: hidden; }
.note-card .ts { color: var(--muted); font-size: 11px; margin-top: 8px; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-clickable tbody tr { cursor: pointer; }
.table-clickable tbody tr:hover { background: var(--panel-2); }
.table-clickable a { color: var(--accent); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge-bought, .badge-ready_for_processing, .badge-processing { background: rgba(106,166,255,.15); color: var(--accent); border-color: rgba(106,166,255,.3); }
.badge-cancelled { background: rgba(255,107,107,.15); color: var(--danger); border-color: rgba(255,107,107,.3); }
.badge-filled_in { background: rgba(251,191,36,.15); color: var(--warn); border-color: rgba(251,191,36,.3); }
.badge-warn { background: rgba(251,191,36,.15); color: var(--warn); border-color: rgba(251,191,36,.3); }
.badge-ok   { background: rgba(74,222,128,.15); color: var(--ok); border-color: rgba(74,222,128,.3); }
.badge-cancelled { background: rgba(154,163,178,.15); color: var(--muted); border-color: var(--border); }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv dd code { font-size: 12px; background: var(--panel-2); padding: 1px 6px; border-radius: 4px; }

details.raw { margin-top: 24px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.raw pre { background: var(--panel-2); padding: 14px; border-radius: 8px; font-size: 11px; max-height: 400px; overflow: auto; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { flex: 1; }

.muted { color: var(--muted); }
.right { text-align: right; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ───────── AJAX typeahead ───────── */
.typeahead-field { position: relative; }
.typeahead-menu {
  position: absolute; top: 100%; left: 0; right: 0;
  margin-top: 4px; z-index: 30;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  max-height: 320px; overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
  display: none;
}
.typeahead-menu.open { display: block; }
.typeahead-menu .ta-item {
  padding: 10px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13px;
  transition: background .12s;
}
.typeahead-menu .ta-item:hover,
.typeahead-menu .ta-item.active {
  background: var(--panel-2);
}
.typeahead-menu .ta-item.ta-loading,
.typeahead-menu .ta-item.ta-empty {
  cursor: default; background: none;
}
.typeahead-menu .ta-name {
  font-weight: 600; color: var(--text);
}
.typeahead-menu .ta-name mark {
  background: rgba(106,166,255,.25); color: var(--accent); padding: 0; border-radius: 2px;
}
.typeahead-menu .ta-meta {
  font-size: 11px; color: var(--muted); margin-top: 2px;
}
.typeahead-menu .ta-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.typeahead-menu .ta-price {
  font-size: 12px; font-weight: 600; color: var(--ok);
  background: rgba(74,222,128,.1);
  padding: 2px 8px; border-radius: 12px;
  white-space: nowrap;
}

/* ───────── Tables: horizontal scroll wrapper for narrow screens ───────── */
.card .table { min-width: 100%; }
@media (max-width: 720px) {
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 540px; font-size: 13px; }
  .table th, .table td { padding: 8px 10px; }
}

/* ───────── Mobile breakpoint ─────────  */
@media (max-width: 900px) {
  .container { padding: 16px; }
  .topbar { padding: 10px 14px; gap: 12px; flex-wrap: wrap; }
  .brand-name { font-size: 11px; letter-spacing: .08em; }
  .brand-logo { height: 22px; }
  .brand-divider { height: 18px; }

  .nav-burger { display: block; margin-left: auto; order: 2; }
  .topbar .user { order: 3; margin-left: auto; gap: 10px; font-size: 13px; }
  .topbar .user span { display: none; }

  .topbar nav {
    order: 4;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 6px;
    display: none;
  }
  .topbar.nav-open nav { display: flex; }
  .topbar nav > a, .topbar nav .nav-drop { width: 100%; }
  .topbar nav > a { padding: 12px 14px; border-radius: 8px; }

  /* dropdowns inline on mobile — no floating menu */
  .nav-drop { display: block !important; }
  .nav-drop-trigger { width: 100%; justify-content: space-between; padding: 12px 14px; }
  .nav-drop::after { display: none; }
  .nav-drop-menu {
    position: static !important;
    background: transparent !important;
    border: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
    padding: 2px 0 4px 24px !important;
    min-width: 0 !important;
    width: 100%;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    display: none !important;
  }
  .nav-drop.open .nav-drop-menu,
  .nav-drop:focus-within .nav-drop-menu { display: block !important; }
  .nav-drop-menu a { padding: 10px 12px; font-size: 14px; }
  .nav-drop-menu a::before { display: none; }
}

@media (max-width: 720px) {
  /* Page heads — wrap controls below title */
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head h1 { font-size: 20px; }
  .page-head .row { flex-wrap: wrap; }

  /* Collapse any inline form grids to single column */
  .card form.grid,
  .card form[class*="grid"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .card form.grid > div[style*="grid-column"] { grid-column: auto !important; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .row.wrap { flex-direction: column; align-items: stretch; }
  .row.wrap > .spacer { display: none; }

  /* Buttons full-width-ish, easier to tap */
  .card form button[type="submit"]:not(.small) { width: 100%; padding: 12px; }
  button, .btn { min-height: 40px; }

  /* Auth/installer card */
  .auth-wrap { margin: 32px 16px; padding: 24px 20px; }

  /* Two-column dashboards collapse */
  .grid-dash { grid-template-columns: 1fr !important; }
  .grid[style*="grid-template-columns: 2fr"],
  .grid[style*="grid-template-columns: 280px"] {
    grid-template-columns: 1fr !important;
  }

  /* Dashboard module tiles — 1 col on small */
  .tile-grid { grid-template-columns: 1fr; gap: 12px; }
  .tile { padding: 16px; gap: 12px; }
  .tile-icon { width: 44px; height: 44px; font-size: 22px; }

  /* Notes 2-pane: stack */
  main.container > .grid[style*="grid-template-columns: 280px"] > .card:first-child {
    max-height: 280px;
  }

  /* Bigger touch targets on todo items */
  .todo { padding: 12px 10px; }

  /* Dashboard finance chart: smaller bars */
  .chart { height: 160px !important; }
}

@media (max-width: 480px) {
  .container { padding: 12px; }
  .brand-name { display: none; }
  .brand-divider { display: none; }

  /* Pay page (public /r/{token}) tweaks */
  .pay-wrap, .ship-wrap { margin: 24px auto !important; padding: 0 12px !important; }
}
