/* =========================================================================
   Thesis v5: instrument glass.

   v4 made Thesis read like its material: paper, ink, Source Serif 4 for
   what you read, IBM Plex Sans for what you operate, one navy accent. v5
   keeps all of that and adds depth only where it explains the layout:
     * the chrome that frames the work (header, rail, docks, menus, sheets,
       toasts) is frosted glass over a quiet tinted ground,
     * panels are a thicker glass, nearly white, so long text stays crisp,
     * what you read and write (the draft page, PDF pages, previews) is
       solid paper and never translucent.
   One shape language, applied by role rather than by accident:
     --r-xs   6px  kbd, code, badges, counts
     --r-sm   8px  controls: buttons, fields, chips, menu items, rows
     --r-md  12px  cards, tiles, menus, popovers, toasts, notices
     --r-lg  16px  panels: header, rail, composer, side panels, sheets
     pill          dots, avatars, switches and progress tracks only
   Inner corners follow outer ones (menu 12 with 4px padding holds items
   of 8), so nothing looks pinched or ballooned next to its container.
   This file only overrides; the structure underneath is unchanged.
   ========================================================================= */

:root {
  /* the ground: a cool mist with faint glows, so the glass has something to frost */
  --bg: #E8ECF2;
  --bg-gradient:
    radial-gradient(1100px 640px at 4% -12%, rgba(47, 99, 184, 0.17), transparent 60%),
    radial-gradient(900px 560px at 102% -4%, rgba(118, 146, 190, 0.18), transparent 62%),
    radial-gradient(1000px 720px at 62% 118%, rgba(208, 190, 160, 0.24), transparent 62%),
    linear-gradient(180deg, #EDF0F4 0%, #E6EAF0 100%);

  /* surfaces: controls stay solid, panels are glass, the page is paper */
  --surface: #FFFFFF;
  --surface-solid: #FFFFFF;
  --surface-2: rgba(255, 255, 255, 0.62);
  --surface-3: rgba(16, 32, 64, 0.055);
  --card: rgba(255, 255, 255, 0.9);
  --card-hover: #FFFFFF;
  --border: rgba(16, 32, 64, 0.12);
  --border-hair: rgba(16, 32, 64, 0.075);
  --paper: #FFFFFF;

  /* glass: three fills by job, one blur, a lit rim */
  --glass-blur: blur(26px) saturate(170%);
  --glass-rim: rgba(255, 255, 255, 0.72);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  --glass-edge: var(--glass-inset);
  --glass-ring: 0 0 0 1px rgba(16, 32, 64, 0.05);
  --glass-fill: rgba(255, 255, 255, 0.74);
  --glass-fill-chrome: rgba(255, 255, 255, 0.56);
  --glass-fill-composer: rgba(255, 255, 255, 0.86);
  --menu-fill: rgba(255, 255, 255, 0.86);
  --overlay-blur: blur(30px) saturate(180%);
  --scrim: rgba(12, 20, 36, 0.26);

  --text: #12161D;
  --text-2: #363D49;
  --text-muted: #5D6675;
  --text-faint: #8D95A3;
  --bot-text: #1A1F27;

  --accent-soft: rgba(30, 64, 124, 0.08);
  --accent-line: rgba(30, 64, 124, 0.24);
  --user-bubble: rgba(30, 64, 124, 0.085);
  --user-bubble-text: #12161D;

  --shadow: 0 1px 2px rgba(16, 32, 64, 0.05), 0 10px 30px rgba(16, 32, 64, 0.07);
  --shadow-sm: 0 1px 2px rgba(16, 32, 64, 0.04), 0 6px 18px rgba(16, 32, 64, 0.05);
  --shadow-lift: 0 2px 6px rgba(16, 32, 64, 0.08), 0 24px 56px rgba(16, 32, 64, 0.2);

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 16px;
  --r-pill: 999px;
  --gap: 12px;
  --focus-ring: rgba(47, 99, 184, 0.18);
}

[data-theme="dark"] {
  --bg: #0A0D12;
  --bg-gradient:
    radial-gradient(1000px 620px at 2% -14%, rgba(47, 99, 184, 0.28), transparent 60%),
    radial-gradient(900px 600px at 104% 4%, rgba(70, 100, 150, 0.18), transparent 62%),
    radial-gradient(1000px 720px at 50% 122%, rgba(30, 64, 124, 0.22), transparent 62%),
    linear-gradient(180deg, #0C1016 0%, #090B10 100%);
  --surface: #1C212A;
  --surface-solid: #161A21;
  --surface-2: rgba(255, 255, 255, 0.045);
  --surface-3: rgba(255, 255, 255, 0.065);
  --card: rgba(255, 255, 255, 0.04);
  --card-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.1);
  --border-hair: rgba(255, 255, 255, 0.065);
  --paper: #171B22;
  --glass-blur: blur(26px) saturate(150%);
  --glass-rim: rgba(255, 255, 255, 0.09);
  --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --glass-ring: 0 0 0 1px rgba(0, 0, 0, 0.25);
  --glass-fill: rgba(20, 24, 31, 0.72);
  --glass-fill-chrome: rgba(20, 24, 31, 0.56);
  --glass-fill-composer: rgba(27, 32, 41, 0.88);
  --menu-fill: rgba(29, 34, 44, 0.9);
  --overlay-blur: blur(30px) saturate(160%);
  --scrim: rgba(0, 0, 0, 0.5);
  --text: #ECEEF2;
  --text-2: #C7CBD3;
  --text-muted: #99A1AE;
  --text-faint: #6D7581;
  --bot-text: #E3E6EB;
  --user-bubble: rgba(128, 166, 232, 0.13);
  --user-bubble-text: #ECEEF2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25), 0 6px 18px rgba(0, 0, 0, 0.25);
  --shadow-lift: 0 2px 8px rgba(0, 0, 0, 0.45), 0 28px 64px rgba(0, 0, 0, 0.6);
}

/* Without a blur, translucent panels over the ground would muddy the text:
   fall back to solid. Same when someone asks the system for less transparency. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass-fill: #FFFFFF; --glass-fill-chrome: #F8FAFC; --glass-fill-composer: #FFFFFF; --menu-fill: #FFFFFF; }
  [data-theme="dark"] { --glass-fill: #161A21; --glass-fill-chrome: #141820; --glass-fill-composer: #1B2029; --menu-fill: #1D222C; }
}
@media (prefers-reduced-transparency: reduce) {
  :root { --glass-fill: #FFFFFF; --glass-fill-chrome: #F8FAFC; --glass-fill-composer: #FFFFFF; --menu-fill: #FFFFFF; --glass-blur: none; --overlay-blur: none; }
  [data-theme="dark"] { --glass-fill: #161A21; --glass-fill-chrome: #141820; --glass-fill-composer: #1B2029; --menu-fill: #1D222C; }
}

body { background-color: var(--bg); background-image: var(--bg-gradient); background-attachment: fixed; font-size: 14px; letter-spacing: 0; }
::selection { background: rgba(47, 99, 184, 0.18); }

/* ------------------------------------------------------------ materials */

.glass {
  background: var(--glass-fill);
  border: 1px solid var(--glass-rim);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-sm), var(--glass-inset), var(--glass-ring);
}
.app-header.glass, .rail.glass { background: var(--glass-fill-chrome); }
.composer.glass { background: var(--glass-fill-composer); }
.app { padding: 12px 14px 12px; gap: 12px; }
.app-body { gap: 12px; }
.messages { -webkit-mask-image: none; mask-image: none; }

/* everything that floats over the work: one overlay material */
.menu, .popover, .popover.glass, .toast, .filters.glass, .float-tools, .rd-seltool, .rd-annpop, .dict-bubble {
  background: var(--menu-fill);
  border: 1px solid var(--glass-rim);
  backdrop-filter: var(--overlay-blur);
  -webkit-backdrop-filter: var(--overlay-blur);
  box-shadow: var(--shadow-lift), var(--glass-inset), var(--glass-ring);
}
dialog.sheet {
  background: var(--menu-fill);
  border: 1px solid var(--glass-rim);
  backdrop-filter: var(--overlay-blur);
  -webkit-backdrop-filter: var(--overlay-blur);
  box-shadow: var(--shadow-lift), var(--glass-inset), var(--glass-ring);
}
dialog.sheet::backdrop { background: var(--scrim); backdrop-filter: blur(6px) saturate(120%); -webkit-backdrop-filter: blur(6px) saturate(120%); }

/* paper: what you read and write is never see-through */
.wd-page { background: var(--paper); border-radius: 2px; box-shadow: 0 0 0 1px var(--border-hair), 0 1px 2px rgba(16, 32, 64, 0.05), 0 12px 32px rgba(16, 32, 64, 0.06); }
.wd-scroll, .wd-preview { background: transparent; }
.pv-page { box-shadow: 0 0 0 1px var(--border-hair), 0 8px 24px rgba(16, 32, 64, 0.1); }

/* -------------------------------------------------------------- shapes */

/* panels */
.app-header, .rail, .messages-shell, .side, .composer, .lib-list, .nt-list, .lib-detail, .nt-main, .wr-main, .wr-assist, .mx-main, .lock-card, dialog.sheet { border-radius: var(--r-lg); }
.side-scroll { border-radius: 0 0 calc(var(--r-lg) - 1px) calc(var(--r-lg) - 1px); }
/* overlays, cards and notices */
.menu, .popover, .toast, .filters, .float-tools, .rd-seltool, .rd-annpop, .dict-bubble, .card, .tpl, .as-card, .src-card, .source, .orig-item, .orig-top, .orig-web, .gd-step, .pp-sec, .fmt-tpl, .fmt-exp,
.notice, .lib-empty, .refs-empty, .hero-upload, .hero-guide, .as-paper, .status-big, .sheet .kv, .verify-panel, .pane { border-radius: var(--r-md); }
/* controls */
.primary-btn, .ghost-btn, .icon-btn, .chip, .chip-btn, .tool-chip, .tray-chip, .kw-chip, .type-chip, .link-chip, .link-add, .field, .tb-select, .year-input, .lib-search input,
.project-btn, .search-pill, .menu-item, .rail-btn, .lib-row, .composer-btn, .send-btn, .ft-btn, .st-btn, .fmt-seg, .seg, .hero-project, .toast .t-act, .tpl-ico, .as-mark, .ap-ico, .le-ico, .fe-ico, .card-ico { border-radius: var(--r-sm); }
.seg-btn, .seg-pill, .fmt-seg button { border-radius: var(--r-xs); }
/* small print */
.badge, .ref-badge, .seg-count, .chip-count, .rs-head .count, .st-sec h3 .count, kbd, .sp-kbd, code { border-radius: var(--r-xs); }
/* round on purpose */
.status-dot, .proj-dot, .thea-avatar, .switch .track, .logo, .logo img { border-radius: var(--r-pill); }

/* ---------------------------------------------------------------- brand */

.logo { width: 38px; height: 38px; background: none; box-shadow: none; overflow: visible; }
.logo img { width: 38px; height: 38px; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(16, 32, 64, 0.25)); }

/* ----------------------------------------------------------- typography */

.hero-title, .sheet-title, .pd-title, .wd-title, .refs-title, .lib-welcome .hero-title, .hist-h {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.012em;
}
.sheet-title { font-size: 21px; }
.prose { font-family: var(--serif); font-size: 16.5px; line-height: 1.65; }
.prose h4 { font-family: var(--sans); font-size: 14px; letter-spacing: 0; }
.wd-body.rich h1, .wd-body.rich h2, .wd-body.rich h3 { font-family: var(--serif); letter-spacing: -0.005em; }
.rich h1 { font-weight: 650; } .rich h2 { font-weight: 650; } .rich h3 { font-weight: 650; }

/* ------------------------------------------------------------- controls */

.primary-btn { font-weight: 600; letter-spacing: 0.005em; box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 1px 2px rgba(16, 32, 64, 0.18); }
.primary-btn:active { transform: none; }
.ghost-btn { background: var(--surface); border-color: var(--border); font-weight: 550; box-shadow: 0 1px 1px rgba(16, 32, 64, 0.04); }
.ghost-btn:hover { background: var(--surface); border-color: rgba(16, 32, 64, 0.22); }
[data-theme="dark"] .ghost-btn { background: rgba(255, 255, 255, 0.05); box-shadow: none; }
[data-theme="dark"] .ghost-btn:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.18); }
.seg { background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--border-hair); padding: 2px; }
.seg-pill { background: var(--surface); box-shadow: 0 0 0 1px var(--border-hair), 0 1px 2px rgba(16, 32, 64, 0.08); }
.seg-btn { color: var(--text-muted); font-weight: 550; }
.seg-btn.is-on { color: var(--text); }
.seg:not(.has-pill) .seg-btn.is-on { background: var(--surface); box-shadow: 0 0 0 1px var(--border-hair), 0 1px 2px rgba(16, 32, 64, 0.08); }
.seg-btn.is-on .seg-count { background: var(--surface-3); color: var(--text-2); }
[data-theme="dark"] .seg-pill, [data-theme="dark"] .seg:not(.has-pill) .seg-btn.is-on { background: rgba(255, 255, 255, 0.1); box-shadow: none; }
.badge { letter-spacing: 0.04em; }
.field { background: var(--surface); border-color: var(--border); }
.field:focus { border-color: var(--accent-bright); box-shadow: 0 0 0 3px var(--focus-ring); }
[data-theme="dark"] .field { background: rgba(255, 255, 255, 0.04); }
.search-pill { background: rgba(255, 255, 255, 0.55); border: 1px solid var(--border-hair); }
.search-pill:hover { background: rgba(255, 255, 255, 0.85); border-color: var(--border); }
[data-theme="dark"] .search-pill { background: rgba(255, 255, 255, 0.05); }
[data-theme="dark"] .search-pill:hover { background: rgba(255, 255, 255, 0.08); }
.project-btn { background: rgba(255, 255, 255, 0.55); border: 1px solid var(--border-hair); }
.project-btn:hover { background: rgba(255, 255, 255, 0.85); }
[data-theme="dark"] .project-btn { background: rgba(255, 255, 255, 0.05); }
.send-btn { box-shadow: 0 1px 2px rgba(16, 32, 64, 0.2); }

/* --------------------------------------------------------------- the rail */

.rail { padding: 6px; }
.rail-btn { font-weight: 550; }
.rail-btn[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border-hair), 0 1px 2px rgba(16, 32, 64, 0.06); }
[data-theme="dark"] .rail-btn[aria-selected="true"] { background: rgba(255, 255, 255, 0.08); box-shadow: none; }
.rail-btn[aria-selected="true"] svg { color: var(--accent); }
.rail-btn[aria-selected="true"]::before { content: ""; position: absolute; left: -6px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent-bright); }

/* -------------------------------------------------------- conversation */

.bubble-user { border-radius: var(--r-md); font-weight: 450; }
.msg-thea { gap: 10px; }

/* the welcome: editorial, not a landing page */
.hero { width: min(680px, 100%); text-align: left; align-items: stretch; animation: none; padding: 8px 0 22px; }
.hero-mark { display: none; }
.hero-project { align-self: flex-start; margin: 0 0 16px; font-size: 12px; font-weight: 550; color: var(--text-muted); }
.hero-title { font-size: clamp(30px, 3.6vw, 40px); line-height: 1.12; letter-spacing: -0.02em; }
.hero-title em { font-style: italic; color: var(--accent); font-weight: 600; }
.hero-sub { margin: 12px 0 22px; max-width: 58ch; font-size: 15px; line-height: 1.6; color: var(--text-2); text-align: left; }
.hero-ask { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 0 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.ha-label { padding-top: 9px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.hero-examples { list-style: none; margin: 0; padding: 0; }
.hero-examples li + li { border-top: 1px solid var(--border-hair); }
.ex-btn { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; padding: 9px 4px 9px 0; border: 0; background: none; color: var(--text); font-family: var(--serif); font-size: 16px; line-height: 1.4; text-align: left; }
.ex-btn svg { flex: none; color: var(--text-faint); transition: transform 0.15s ease, color 0.15s ease; }
.ex-btn:hover { color: var(--accent); }
.ex-btn:hover svg { color: var(--accent); transform: translateX(3px); }
.hero-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.hero-upload, .hero-guide { display: inline-flex; align-items: center; gap: 9px; margin: 0; padding: 9px 12px; border: 1px solid var(--border); background: var(--card); color: var(--text-2); font-size: 12.5px; line-height: 1.4; text-align: left; width: auto; max-width: 100%; box-shadow: none; }
.hero-upload:hover, .hero-guide:hover { border-color: var(--accent-line); color: var(--text); background: var(--card-hover); }
.hero-upload strong, .hero-guide strong { color: var(--text); font-weight: 600; }
.hero-upload svg, .hero-guide svg { color: var(--accent); flex: none; }
.hero-pillars { display: none; }
.hero-facts { margin: 22px 0 0; font-size: 12px; line-height: 1.7; color: var(--text-faint); }
.hero-facts span + span::before { content: "\00a0 · \00a0"; }

/* cards sit on glass: solid enough to read, ruled not floating */
.as-card, .src-card, .source, .orig-item, .gd-step, .pp-sec, .fmt-tpl, .fmt-exp, .tpl { box-shadow: none; background: var(--card); }
.tpl:hover, .fmt-tpl:hover, .fmt-exp:hover { background: var(--card-hover); }
.composer { box-shadow: var(--shadow-sm), var(--glass-inset), var(--glass-ring); }
.composer:focus-within { border-color: var(--accent-line); box-shadow: var(--shadow-sm), var(--glass-inset), 0 0 0 3px rgba(47, 99, 184, 0.09); }

/* verdict badges keep their meaning */
.badge.good { background: var(--ok-soft); color: var(--ok-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); }
.badge.bad { background: var(--bad-soft); color: var(--bad-text); }

/* ------------------------------------------------------- floating parts */

/* menus scroll inside themselves instead of running off the screen */
.menu { padding: 4px; overscroll-behavior: contain; }
.menu-item { padding: 8px 10px; }
.menu-head { padding: 8px 10px 4px; }
/* toolbars that float over the page wrap instead of running past its edge */
.float-tools, .rd-seltool { flex-wrap: wrap; max-width: calc(100% - 16px); white-space: normal; }
.rd-annpop { width: min(320px, calc(100% - 16px)); }
/* toasts: bottom right on wide screens, above the bottom bar on phones;
   never over the composer's send button */
.toast { left: auto; right: 20px; bottom: 20px; transform: translateY(16px); max-width: min(460px, calc(100vw - 40px)); }
.toast.is-open { transform: none; }
.popover { max-height: calc(100dvh - 24px); overflow-y: auto; }

@media (max-width: 760px) {
  .app { padding: 8px; gap: 8px; }
  .hero-title { font-size: 30px; }
  .rail-btn[aria-selected="true"]::before { display: none; }
}
@media (max-width: 640px) {
  /* room for the bottom navigation, as in style.css */
  .app { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  .rail, body.rail-open .rail { background: var(--menu-fill); backdrop-filter: var(--overlay-blur); -webkit-backdrop-filter: var(--overlay-blur); box-shadow: var(--shadow-lift), var(--glass-inset), var(--glass-ring); }
  .toast { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; justify-content: center; }
}

/* the draft header holds a lot: keep every control on screen */
.wd-head { gap: 6px; }
.wd-style .tb-select { max-width: 128px; }
@media (max-width: 1500px) { .wr.assist-on .wd-head .save-state { display: none; } }
@media (max-width: 1320px) { .wr.assist-on .wd-view .seg-btn svg, .wr.assist-on .wd-head [data-act="export"] svg { display: none; } }
@media (max-width: 640px) {
  .wd-head .save-state, .wd-style { display: none; }
  .wd-view .seg-btn { font-size: 0; gap: 0; padding: 0 9px; }
  .wd-view .seg-btn svg { display: block; }
  .wd-head [data-act="export"] span, .wd-head .wd-thea span { display: none; }
  .wd-head [data-act="export"], .wd-head .wd-thea { padding: 0 9px; }
  .type-chip { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
}

/* sheets that hold a preview or an editable plan get the room they need;
   every sheet fits the screen and scrolls inside */
dialog.sheet { max-height: min(820px, calc(100dvh - 32px)); }
dialog.sheet.fig-sheet { width: min(980px, calc(100vw - 32px)); }
dialog.sheet.paper-sheet, dialog.sheet.orig-sheet, dialog.sheet.pick-sheet { width: min(760px, calc(100vw - 32px)); }
dialog.sheet.guide-sheet { width: min(860px, calc(100vw - 32px)); }
@media (max-width: 560px) {
  /* phones: sheets rise from the bottom edge and use the full width */
  dialog.sheet, dialog.sheet.wide, dialog.sheet.xwide, dialog.sheet.fig-sheet, dialog.sheet.paper-sheet, dialog.sheet.orig-sheet, dialog.sheet.pick-sheet, dialog.sheet.guide-sheet {
    width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: calc(100dvh - 24px); border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0;
  }
  .sheet-inner { padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); }
}
