/* Platform shell and views. Desktop: sidebar + top bar. Phones and tablets (< 1024px): top bar + bottom tab bar. */

:root { --topbar-h: 72px; --tabbar-h: 64px; --side-w: 252px; }

.app-body {
  margin: 0; min-height: 100dvh; font-size: 15px;
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(31, 184, 106, 0.14), transparent 62%),
    radial-gradient(700px 520px at -8% 34%, rgba(31, 184, 106, 0.06), transparent 62%),
    var(--app-bg);
}
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }

/* ---- sidebar ------------------------------------------------------------------------------------ */
.side {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 20px; padding: 22px 14px 16px; overflow-y: auto;
  background: var(--app-side); border-right: 1px solid var(--app-line);
}
.side .brand { padding: 2px 8px 6px; }
.side .brand img { width: 38px; }
.side .wordmark { font-size: 1.3rem; }
.side-nav { display: grid; gap: 4px; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 11px; border: 1px solid transparent;
  color: var(--app-muted); text-decoration: none; font-size: 0.9rem; font-weight: 500; transition: background 0.15s, color 0.15s;
}
.side-nav a:hover { color: var(--app-text); background: rgba(255, 255, 255, 0.04); }
.side-nav a.is-active {
  color: #eafff3; font-weight: 600; background: linear-gradient(90deg, rgba(75, 227, 150, 0.2), rgba(75, 227, 150, 0.06)); border-color: rgba(75, 227, 150, 0.38);
}
.side-nav .ico { width: 19px; height: 19px; }
.side-nav [data-icon] { display: inline-flex; }
.side-foot { margin-top: auto; display: grid; gap: 10px; }
.user { display: flex; align-items: center; gap: 11px; padding: 10px; border-radius: 12px; text-decoration: none; color: inherit; border: 1px solid var(--app-line); background: var(--app-surface); }
.user:hover { border-color: var(--app-line-strong); }
.user b { display: block; font-size: 0.86rem; font-weight: 600; line-height: 1.25; }
.user small { color: var(--app-faint); font-size: 0.74rem; }
.back-link { padding: 4px 10px; font-size: 0.78rem; color: var(--app-faint); text-decoration: none; }
.back-link:hover { color: var(--app-accent); }
.avatar {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; text-decoration: none;
  font-weight: 700; font-size: 0.82rem; color: #d8ffe9; background: linear-gradient(135deg, #1b7048, #0d3b2a); border: 1px solid rgba(75, 227, 150, 0.45);
}

/* ---- top bar -------------------------------------------------------------------------------------- */
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; height: var(--topbar-h); padding: 0 28px;
  background: rgba(8, 18, 16, 0.82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--app-line);
}
.topbar .brand { display: none; }
.search {
  flex: 1; min-width: 0; max-width: 600px; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px;
  color: var(--app-faint); background: var(--app-surface-2); border: 1px solid var(--app-line); border-radius: 12px;
}
.search:focus-within { border-color: rgba(75, 227, 150, 0.65); box-shadow: 0 0 0 3px rgba(75, 227, 150, 0.14); }
.search input { flex: 1; width: 100%; min-width: 0; padding: 0; background: none; border: 0; outline: none; color: var(--app-text); font-size: 0.92rem; text-overflow: ellipsis; }
.search input::placeholder { color: var(--app-faint); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.notify { position: absolute; top: 9px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--app-accent); box-shadow: 0 0 0 2px var(--app-surface-2); }
.pop-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 60; width: min(350px, calc(100vw - 24px)); display: grid; gap: 8px; padding: 14px;
  background: #0e1c1a; border: 1px solid var(--app-line-strong); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.pop-title { font-size: 0.82rem; font-weight: 650; color: var(--app-muted); }
.popover ul { display: grid; gap: 2px; }
.popover a { display: grid; gap: 2px; padding: 10px; border-radius: 10px; color: inherit; text-decoration: none; }
.popover a:hover { background: var(--app-surface-2); }
.popover a b { font-size: 0.88rem; }
.popover a span { font-size: 0.78rem; color: var(--app-muted); }

/* ---- view container ------------------------------------------------------------------------------ */
.view { width: 100%; max-width: 1240px; margin: 0 auto; padding: 8px 28px 64px; outline: none; }
.view.is-ai { display: flex; flex-direction: column; height: calc(100dvh - var(--topbar-h)); padding-bottom: 22px; }
.chat-wrap { flex: 1; min-height: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 16px; padding: 16px 0 14px; }
.page-head h1 { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.55rem, 2.4vw, 1.95rem); letter-spacing: -0.03em; line-height: 1.15; }
.page-sub { margin-top: 5px; max-width: 70ch; font-size: 0.92rem; color: var(--app-muted); line-height: 1.5; }
.page-actions { display: flex; gap: 10px; flex: none; }
.count { margin: 4px 0 12px; font-size: 0.84rem; color: var(--app-muted); }
.foot-note { margin-top: 22px; }
.sec-title { margin-bottom: 12px; font-size: 1rem; font-weight: 650; }

/* ---- filters and form controls -------------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin: 8px 0 14px; }
.filters-slim { margin: 12px 0 0; }
.field { display: grid; gap: 4px; font-size: 0.74rem; color: var(--app-faint); }
.field select {
  min-height: 42px; padding: 0 12px; border-radius: 10px; background: var(--app-surface-2); color: var(--app-text);
  border: 1px solid var(--app-line); font-size: 0.88rem; max-width: 100%;
}
.field select:focus, .select-sm:focus { outline: none; border-color: rgba(75, 227, 150, 0.65); box-shadow: 0 0 0 3px rgba(75, 227, 150, 0.14); }
.field-search {
  display: flex; align-items: center; gap: 9px; flex: 1 1 260px; min-width: 0; min-height: 42px; padding: 0 12px; color: var(--app-faint);
  background: var(--app-surface-2); border: 1px solid var(--app-line); border-radius: 10px;
}
.field-search:focus-within { border-color: rgba(75, 227, 150, 0.65); box-shadow: 0 0 0 3px rgba(75, 227, 150, 0.14); }
.field-search input { flex: 1; min-width: 0; padding: 0; border: 0; outline: none; background: none; color: var(--app-text); font-size: 0.9rem; text-overflow: ellipsis; }
.field-search input::placeholder { color: var(--app-faint); }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; width: fit-content; max-width: 100%; padding: 4px; border-radius: 12px; background: var(--app-surface); border: 1px solid var(--app-line); }
.seg { padding: 9px 14px; border: 0; border-radius: 9px; background: none; color: var(--app-muted); font-weight: 600; font-size: 0.86rem; text-align: left; transition: background 0.15s, color 0.15s; }
.seg:hover { color: var(--app-text); }
.seg[aria-pressed="true"] { color: #eafff3; background: rgba(75, 227, 150, 0.16); box-shadow: inset 0 0 0 1px rgba(75, 227, 150, 0.42); }
.brief { display: grid; gap: 4px; margin: 14px 0 4px; padding: 14px 16px; border-radius: 14px; background: var(--app-surface); border: 1px solid var(--app-line); font-size: 0.88rem; color: var(--app-muted); line-height: 1.5; }
.brief b { color: var(--app-text); font-weight: 600; }
.brief-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; color: var(--app-text); font-weight: 600; }
.brief-title span { color: var(--app-muted); font-weight: 400; }

/* ---- empty states, saved, settings ------------------------------------------------------------------ */
.empty {
  display: grid; justify-items: center; gap: 10px; padding: 44px 20px; text-align: center;
  border: 1px dashed var(--app-line-strong); border-radius: 18px; background: var(--app-surface);
}
.empty-ico { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; color: var(--app-accent); background: rgba(75, 227, 150, 0.1); }
.empty h2 { font-size: 1.1rem; font-weight: 650; }
.empty p { max-width: 48ch; color: var(--app-muted); line-height: 1.5; }
.saved-sec { margin-top: 22px; }
.saved-item { display: grid; gap: 2px; justify-items: start; }
.saved-item .card { width: 100%; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.set-card { display: grid; align-content: start; gap: 10px; padding: 18px; border-radius: 16px; background: var(--app-surface); border: 1px solid var(--app-line); }
.set-card h2 { font-size: 1rem; font-weight: 650; }
.set-card p { color: var(--app-muted); font-size: 0.88rem; line-height: 1.5; }
.set-card .lead { color: var(--app-text); }
.set-label { margin-top: 6px; font-size: 0.74rem; color: var(--app-faint) !important; }

/* ---- compare bar ------------------------------------------------------------------------------------- */
.compare-bar {
  position: fixed; z-index: 40; left: calc(var(--side-w) + 24px); right: 24px; bottom: 20px; max-width: 820px; margin-inline: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 12px 10px 18px; border-radius: 16px;
  background: rgba(12, 24, 22, 0.94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(75, 227, 150, 0.42); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); font-size: 0.88rem;
}
.compare-bar[hidden] { display: none; }
.compare-bar p { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-actions { display: flex; gap: 8px; flex: none; }

/* ---- tab bar (phones and tablets) ---------------------------------------------------------------------- */
.tabbar { display: none; }
.more-sheet {
  position: fixed; z-index: 55; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); width: min(300px, calc(100% - 24px));
  display: grid; gap: 2px; padding: 8px; background: #0e1c1a; border: 1px solid var(--app-line-strong); border-radius: 18px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.more-sheet[hidden] { display: none; }
.more-sheet a { display: flex; align-items: center; gap: 12px; padding: 13px 12px; border-radius: 12px; color: var(--app-text); text-decoration: none; font-size: 0.95rem; font-weight: 500; }
.more-sheet a:hover, .more-sheet a.is-active { background: rgba(75, 227, 150, 0.1); }
.more-sheet a.is-active { color: var(--app-accent); }
.more-sheet .ico { width: 19px; height: 19px; color: var(--app-muted); }
.more-sheet a.is-active .ico { color: var(--app-accent); }

@media (max-width: 1023px) {
  :root { --topbar-h: 64px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .brand { display: inline-flex; }
  .topbar .brand img { width: 34px; }
  .topbar .wordmark { display: none; }
  .search { min-height: 42px; }
  .top-actions { gap: 8px; }
  .popover { position: fixed; left: 12px; right: 12px; top: calc(var(--topbar-h) + 6px); width: auto; }
  .view { padding: 4px 16px calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom)); }
  .view.is-ai { height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - env(safe-area-inset-bottom)); padding: 4px 12px 12px; }
  .view.is-ai .page-head { padding: 8px 4px; }
  .view.is-ai .page-sub { display: none; }
  .page-head h1 { font-size: 1.5rem; }
  .compare-bar { left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }

  .tabbar {
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: rgba(9, 17, 19, 0.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--app-line);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 2px 4px; border: 0; background: none;
    color: var(--app-faint); font-size: 0.68rem; font-weight: 600; text-decoration: none; letter-spacing: 0.005em;
  }
  .tabbar .ico { width: 22px; height: 22px; }
  .tabbar [data-icon] { display: inline-flex; }
  .tabbar a.is-active, .tabbar button.is-active, .tabbar button[aria-expanded="true"] { color: var(--app-accent); }
  .tabbar .tab-ai [data-icon] {
    width: 48px; height: 48px; margin-top: -22px; display: grid; place-items: center; border-radius: 50%; color: #03100a;
    background: linear-gradient(135deg, #3ee08f, #7df4ba); box-shadow: 0 10px 26px -8px rgba(62, 224, 143, 0.75), 0 0 0 5px var(--app-side);
  }
  .tabbar .tab-ai { color: var(--app-text); }
  .tabbar .tab-ai.is-active { color: var(--app-accent); }
}
@media (max-width: 640px) {
  .filters .field { flex: 1 1 140px; }
  .filters .field select { width: 100%; }
  .page-head { padding-top: 10px; }
  .view { padding-left: 14px; padding-right: 14px; }
}
