/* Page frame: sidebar, top bar, bento tiles, buttons, inputs. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.num, .tile-value, td.num, th.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.zero { color: var(--faint); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Sign-in */
.signin { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.signin-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.signin-card h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.signin-card p { margin: 0 0 20px; color: var(--muted); }
.signin-card .field { margin-bottom: 14px; }
.signin-error { color: var(--danger); min-height: 20px; margin: 4px 0 8px; font-size: 13px; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100%; transition: grid-template-columns var(--t-mid) var(--ease); }
.shell.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px; overflow: hidden; }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; white-space: nowrap; }
.logo-mark { width: 28px; height: 28px; display: grid; place-items: center; flex: none; }
.folio-mark { width: 100%; height: 100%; display: block; }
.folio-cover { fill: var(--text); }
.folio-page { fill: none; stroke: var(--text); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.folio-line { fill: none; stroke: var(--accent); stroke-width: 3.4; stroke-linecap: round; }
.wordmark { display: flex; flex-direction: column; line-height: 0.95; }
.wordmark small { font-size: 10px; font-weight: 700; letter-spacing: 0.02em; color: var(--muted); }
.wordmark span { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.signin-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.signin-brand .folio-mark { width: 44px; height: 44px; }
.signin-brand .wordmark small { font-size: 13px; }
.signin-brand .wordmark span { font-size: 28px; }
.logo-text { font-weight: 600; letter-spacing: -0.01em; overflow: hidden; transition: opacity var(--t-fast) var(--ease); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; height: 36px; padding: 0 10px; border: 0; background: transparent; border-radius: var(--radius); color: var(--muted); cursor: pointer; white-space: nowrap; text-align: left; position: relative; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.is-active { background: var(--selected); color: var(--text); }
.nav-item svg { flex: none; width: 18px; height: 18px; }
.nav-label { overflow: hidden; transition: opacity var(--t-fast) var(--ease); }
.nav-count { margin-left: auto; font-family: var(--font-num); font-size: 11px; color: var(--warn-ink); background: var(--warn-soft); border-radius: 99px; padding: 1px 7px; }
.shell.is-collapsed .logo-text, .shell.is-collapsed .nav-label, .shell.is-collapsed .nav-count, .shell.is-collapsed .who-text { opacity: 0; pointer-events: none; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.who { display: flex; align-items: center; gap: 10px; padding: 6px 10px; white-space: nowrap; }
.who-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--elevated); display: grid; place-items: center; font-size: 11px; font-weight: 600; flex: none; }
.who-text { overflow: hidden; line-height: 1.25; }
.who-text small { display: block; color: var(--faint); font-size: 11px; }

/* Collapsed sidebar: floating label card instead of a slow native tooltip. */
.nav-tip { position: fixed; z-index: 60; background: var(--elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; font-size: 13px; box-shadow: var(--shadow-pop); pointer-events: none; opacity: 0; transform: scale(0.97); transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease); }
.nav-tip.is-on { opacity: 1; transform: scale(1); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 14px 28px; background: var(--bg); border-bottom: 1px solid var(--border); }
.topbar h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.page { padding: 22px 28px 48px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* Bento strip: "what needs me" */
.bento { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-tile); padding: 14px 16px; text-align: left; cursor: default; min-height: 86px; display: flex; flex-direction: column; justify-content: space-between; }
button.tile { cursor: pointer; transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease); }
button.tile:hover { background: var(--surface-2); }
.tile.is-picked { border-color: var(--border-strong); background: var(--surface-2); }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-value { font-size: 24px; font-weight: 500; letter-spacing: -0.02em; margin-top: 6px; }
.tile-sub { color: var(--faint); font-size: 11.5px; margin-top: 2px; }
.tile.is-hero { grid-column: span 2; }
.tile.is-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tile.is-accent .tile-label, .tile.is-accent .tile-sub { color: var(--accent-ink); opacity: 0.75; }
.tile.is-danger .tile-value { color: var(--danger); }
.tile.is-warn .tile-value { color: var(--warn); }
@media (max-width: 720px) { .tile.is-hero { grid-column: span 1; } }

/* Section headers above tables */
.section-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.section-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.section-head .grow { flex: 1; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; white-space: nowrap; transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease); }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover { background: var(--text); opacity: 0.9; }
.btn-accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-accent:hover { background: var(--accent); opacity: 0.9; }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 34px; padding: 0; justify-content: center; }
.btn-group { display: inline-flex; gap: 6px; }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }
.input, .textarea { height: 36px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--border-strong); background: var(--input-bg); outline: none; width: 100%; transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; }
.input:focus, .textarea:focus, .btn:focus-visible, .nav-item:focus-visible, .pick:focus-visible { box-shadow: 0 0 0 3px var(--focus); border-color: var(--border-strong); outline: none; }
.input.num { text-align: right; }
.search { position: relative; }
.search .input { padding-left: 34px; width: 220px; }
.search svg { position: absolute; left: 11px; top: 50%; width: 15px; height: 15px; transform: translateY(-50%); color: var(--faint); }
/* Saved browser passwords must not paint dark inputs white or blue. */
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--input-bg) inset;
  transition: background-color 9999s ease-out 0s;
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.phone-only, .tabbar { display: none; }

/* Bottom tab bar and the More sheet (phones). */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--sidebar); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; height: 52px; justify-content: center; border: 0; background: transparent;
  color: var(--faint); border-radius: 10px; cursor: pointer; transition: color 130ms ease, background 130ms ease, transform 95ms var(--pop-spring); -webkit-tap-highlight-color: transparent; }
.tab:active { transform: scale(0.94); }
.tab.is-active { color: var(--text); }
.tab.is-active .tab-icon { background: var(--selected); }
.tab-icon { position: relative; display: grid; place-items: center; width: 44px; height: 28px; border-radius: 99px; transition: background 160ms var(--spring); }
.tab-icon svg { width: 20px; height: 20px; }
.tab-label { font-size: 11px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.tab-dot { position: absolute; top: -3px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: var(--warn); color: #1a1200; font-family: var(--font-num); font-size: 10px; font-weight: 600; line-height: 16px; text-align: center; }
.more-list { display: flex; flex-direction: column; gap: 2px; }
.more-item { display: flex; align-items: center; gap: 14px; height: 48px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; cursor: pointer; color: var(--text); font-size: 15px; }
.more-item svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.more-item:hover, .more-item:active { background: var(--hover); }
.more-item.is-active { background: var(--selected); }
.more-item .nav-count { margin-left: auto; }
.more-sep { height: 1px; background: var(--border); margin: 6px 0; }

/* Phones: no sidebar; a short top bar whose tools scroll sideways in one row; room for the tab bar. */
@media (max-width: 760px) {
  .shell, .shell.is-collapsed { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .tabbar { display: grid; }
  .phone-only { display: grid; }
  .topbar .logo-mark { width: 24px; height: 24px; }
  .topbar { position: static; flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 16px 10px; }
  .topbar h2 { font-size: 20px; }
  .topbar-tools { margin: 0 -16px; padding: 0 16px 2px; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .topbar-tools::-webkit-scrollbar { display: none; }
  /* A soft fade on the right edge says "more to the side". */
  .topbar-tools.is-more { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent); }
  .topbar-tools > * { flex: none; }
  .page { padding: 14px 16px calc(96px + env(safe-area-inset-bottom)); gap: 14px; }
  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .tile { min-height: 0; padding: 10px 12px; }
  .tile-value { font-size: 19px; margin-top: 4px; }
  .tile-sub { font-size: 11px; }
  .search .input { width: 210px; }
  /* Thumb-sized controls, and 16px text so phones do not zoom into inputs. */
  .btn { height: 38px; }
  .btn-sm { height: 32px; }
  .btn-icon { width: 38px; }
  .input, .textarea, .pick { font-size: 16px; }
  .input, .pick { height: 40px; }
  .section-head { gap: 8px; }
}
