/*
 * Application shell: sign-in page, sidebar navigation, top bar and the
 * off-canvas navigation used on narrow screens.
 */

.skip-link { position: fixed; top: 8px; left: 8px; z-index: 200; padding: 8px 14px; border-radius: var(--radius); color: var(--on-brand); background: var(--brand); font-size: var(--text-sm); font-weight: 600; transform: translateY(-200%); }
.skip-link:focus { transform: none; }

/* ---------- Sign-in ---------- */
body:not(.authenticated) .app-shell { display: none; }
body.authenticated .login-page, body.authenticated .skip-link:not(:focus) { display: none; }
body.authenticated .skip-link:focus { display: block; }

.login-page { --login-ink: #0f1936; --login-rule: rgba(255, 255, 255, .14); min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(380px, .95fr); background: var(--canvas); }
.login-page:not(.ready) .login-panel { visibility: hidden; }
.login-story { position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; padding: 40px clamp(28px, 5vw, 72px); color: #fff; background: var(--login-ink); overflow: hidden; }
/* Ruled ledger lines: the one decorative device, and it is the product's own material. */
.login-story::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(to bottom, transparent 0 47px, var(--login-rule) 47px 48px); mask-image: linear-gradient(105deg, transparent 45%, #000 100%); -webkit-mask-image: linear-gradient(105deg, transparent 45%, #000 100%); opacity: .5; pointer-events: none; }
.login-story > * { position: relative; z-index: 1; }
.login-brand { display: flex; align-items: center; gap: 12px; font-family: var(--font-figure); font-size: 19px; letter-spacing: .2px; }
.login-brand img { width: 38px; height: 38px; padding: 6px; border-radius: var(--radius); background: #fff; }
.login-brand strong { overflow-wrap: anywhere; font-weight: 600; }
.login-pitch { max-width: 560px; }
.login-pitch h2 { color: #fff; font-size: clamp(28px, 3.2vw, 44px); line-height: 1.35; font-weight: 650; }
.login-pitch > p { max-width: 46ch; margin-top: 18px; color: #b9c3dc; font-size: 15px; line-height: 1.9; }
.login-capabilities { display: grid; gap: 14px; margin: 36px 0 0; padding: 0; list-style: none; }
.login-capabilities li { display: flex; align-items: flex-start; gap: 12px; color: #b9c3dc; font-size: var(--text-sm); line-height: 1.6; }
.login-capabilities svg { width: 18px; height: 18px; margin-top: 2px; color: #9fb0ff; }
.login-capabilities strong { display: block; color: #fff; font-size: var(--text-md); font-weight: 600; }
.login-foot { color: #8f9bb8; font-size: var(--text-xs); }

.login-side { position: relative; display: grid; place-items: center; padding: 88px 24px 48px; }
.login-appearance { position: absolute; top: 28px; right: 28px; }
.login-panel { width: min(400px, 100%); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-md); }
.login-heading { padding: 28px 28px 4px; }
.login-heading h1 { font-size: 24px; }
.login-heading p { margin-top: 6px; color: var(--muted); font-size: var(--text-sm); }
.login-panel .auth-switch { margin: 18px 28px 0; }
.login-panel .auth-form { gap: 18px; padding: 22px 28px 28px; }
.login-panel .auth-form input { min-height: 42px; font-size: var(--text-md); }
.login-panel .auth-form .primary-button { min-height: 44px; font-size: var(--text-md); }
.turnstile-slot { min-height: 65px; overflow: hidden; }

/* ---------- Frame ---------- */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.main-content { grid-column: 2; min-width: 0; outline: 0; }

.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-width); display: flex; flex-direction: column; padding: 0 12px 14px; color: var(--nav-ink); border-right: 1px solid var(--line); background: var(--nav); }
.brand { height: var(--topbar-height); display: flex; align-items: center; gap: 10px; padding: 0 8px; flex: 0 0 auto; }
.brand > div { min-width: 0; flex: 1; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; flex: 0 0 auto; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.brand-mark img { width: 22px; height: 22px; object-fit: contain; }
.brand strong, .brand small, .sidebar-foot strong, .sidebar-foot small { display: block; }
.brand strong { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; color: var(--ink); font-family: var(--font-figure); font-size: 17px; line-height: 1.2; font-weight: 600; letter-spacing: .2px; }
.brand small { margin-top: 2px; overflow: hidden; color: var(--nav-muted); font-size: var(--text-xs); text-overflow: ellipsis; white-space: nowrap; }

.main-nav { display: flex; flex-direction: column; gap: 2px; min-height: 0; flex: 1; padding: 8px 0; overflow-y: auto; scrollbar-width: thin; }
.nav-group-title { margin: 14px 0 4px; padding: 0 10px; color: var(--nav-muted); font-size: var(--text-xs); font-weight: 550; }
.nav-item { width: 100%; min-height: 38px; display: flex; align-items: center; gap: 10px; flex: 0 0 auto; padding: 0 10px; border: 0; border-radius: var(--radius); color: var(--nav-ink); background: transparent; font-size: var(--text-md); font-weight: 500; text-align: left; transition: background 120ms ease, color 120ms ease; }
.nav-item svg { width: 18px; height: 18px; color: var(--nav-muted); transition: color 120ms ease; }
.nav-item:hover { color: var(--ink); background: var(--nav-hover); }
.nav-item.active { color: var(--nav-active-ink); background: var(--nav-active); font-weight: 650; }
.nav-item.active svg { color: var(--nav-active-ink); }

.sidebar-foot { display: flex; align-items: flex-start; gap: 10px; flex: 0 0 auto; margin-top: 8px; padding: 12px 10px 2px; border-top: 1px solid var(--line); }
.sidebar-foot .status-dot { margin-top: 6px; }
.sidebar-foot strong { color: var(--ink-2); font-size: var(--text-xs); font-weight: 600; }
.sidebar-foot small { margin-top: 2px; color: var(--nav-muted); font-size: var(--text-xs); line-height: 1.5; }
.sidebar-foot.sync-error .status-dot { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.sidebar-foot.sync-error strong { color: var(--amber-strong); }

.topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-height); display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 var(--page-gutter); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px); }
.topbar-title { min-width: 0; flex: 1 1 auto; display: flex; align-items: center; gap: 12px; }
.topbar-title > div { min-width: 0; }
.topbar-actions { flex: 0 0 auto; }
.topbar h1 { overflow: hidden; font-size: 18px; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.eyebrow { color: var(--muted); font-size: var(--text-xs); line-height: 1.2; }
.eyebrow:empty { display: none; }
.page-title-line { min-width: 0; display: flex; align-items: center; gap: 10px; }
.page-title-line .analysis-month-badge { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.update-note { color: var(--muted); font-size: var(--text-xs); white-space: nowrap; }
.update-button { position: relative; }
.update-indicator { display: none; position: absolute; top: -3px; right: -3px; width: 8px; height: 8px; border: 2px solid var(--surface); border-radius: 50%; background: var(--amber); box-sizing: content-box; }
.update-button.has-update { color: var(--amber-strong); border-color: var(--amber-line); background: var(--amber-soft); }
.update-button.has-update .update-indicator { display: block; }
.account-button { max-width: 168px; }
.account-button span { overflow: hidden; text-overflow: ellipsis; }
.appearance-select { width: auto; min-width: 92px; padding-right: 26px; }

.nav-toggle, .nav-close, .nav-scrim { display: none; }

.view { display: none; max-width: 1680px; padding: 24px var(--page-gutter) 56px; }
.view.active { display: block; }
.view-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.view-intro h2 { font-size: var(--text-xl); }

/* ---------- Narrow screens: navigation becomes a drawer ---------- */
@media (max-width: 960px) {
  .app-shell { display: block; }
  .main-content { grid-column: auto; }
  .sidebar { width: min(280px, 86vw); box-shadow: var(--shadow-lg); transform: translateX(-102%); visibility: hidden; transition: transform 200ms ease, visibility 0s linear 200ms; }
  .app-shell.nav-open .sidebar { transform: none; visibility: visible; transition: transform 200ms ease; }
  .nav-scrim { position: fixed; inset: 0; z-index: 35; background: var(--overlay); }
  .app-shell.nav-open .nav-scrim { display: block; }
  .nav-toggle, .nav-close { display: inline-grid; }
  .nav-item { min-height: 44px; }

  .login-page { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-story { padding: 18px 20px; }
  .login-story::after, .login-pitch, .login-foot { display: none; }
  .login-side { place-items: start center; padding: 72px 16px 40px; }
  .login-appearance { top: 20px; right: 16px; }
}

@media (max-width: 640px) {
  .topbar { gap: 8px; padding-inline: 12px; }
  .topbar h1 { font-size: var(--text-lg); }
  .topbar-actions { gap: 6px; }
  .update-note, #exportAll, #checkUpdates:not(.has-update), .page-title-line .analysis-month-badge { display: none; }
  .appearance-select { min-width: 0; width: 76px; padding-inline: 8px 20px; }
  .account-button { width: var(--control-height); padding: 0; }
  .account-button #accountButtonLabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .view { padding: 16px 12px 40px; }
  .view-intro { align-items: stretch; flex-direction: column; gap: 12px; }
  .action-group { flex-wrap: wrap; }
  .login-heading { padding: 22px 20px 2px; }
  .login-panel .auth-form { padding: 18px 20px 22px; }
  .login-panel .auth-switch { margin-inline: 20px; }
}
