:root {
  --ink: #15171b; --muted: #68707c; --line: #e4e7eb; --soft: #f6f7f9; --paper: #fff;
  --accent: #1d4e89; --accent-soft: #e8eff8; --red: #b3261e; --green: #1f7a3a;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.45; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 44px; font-weight: 800; line-height: 1.05; text-transform: uppercase; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; margin: 26px 0 8px; }
a { color: inherit; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 36px; padding: 0 32px; height: 64px; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 30; }
.wordmark { font-weight: 800; font-size: 22px; letter-spacing: -0.03em; text-decoration: none; }
.wordmark span { color: var(--accent); }
.wordmark.big { font-size: 30px; margin-bottom: 30px; }
.tabs { display: flex; gap: 6px; height: 100%; }
.tabs a { display: flex; align-items: center; padding: 0 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }
.tools { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.link { color: var(--muted); font-weight: 600; text-decoration: none; }
.link:hover { color: var(--ink); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); cursor: pointer; font-size: 22px; line-height: 1; }
.icon-btn:hover { background: var(--soft); }

/* page */
.page { padding: 36px 32px 80px; }
.controls { display: flex; align-items: center; gap: 14px; margin: 26px 0 30px; }
.field { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 600; }
input[type=date], .card input, .login-card input { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid #cfd4db; border-radius: 8px; padding: 9px 12px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; font: inherit; font-weight: 600; padding: 9px 16px; border: 1px solid #cfd4db; border-radius: 8px; background: var(--paper); color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--soft); }
.btn.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.dark:hover { background: #2a2e35; }
section { margin-bottom: 44px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.error { border: 1px solid var(--red); background: #fdf1f0; color: var(--red); border-radius: 8px; padding: 18px 20px; font-weight: 700; }

/* tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 74vh; }
.table-wrap.short { max-height: 220px; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 11px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); background: var(--paper); }
.grid th.first, .grid td.first { text-align: left; position: sticky; left: 0; z-index: 2; border-right: 1px solid var(--line); }
.grid thead th { position: sticky; z-index: 3; font-weight: 700; color: var(--ink); white-space: normal; min-width: 84px; vertical-align: bottom; }
.grid thead tr.groups th { top: 0; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); text-align: left; padding: 9px 14px; border-left: 1px solid var(--line); }
.grid thead tr.groups th.first { border-left: 0; }
.grid thead tr:nth-child(2) th { top: 34px; border-bottom: 1px solid #cfd4db; }
.grid thead th.first { z-index: 4; }
.grid tbody tr:hover td { background: var(--soft); }
.grid td.asin { font-weight: 700; letter-spacing: 0.01em; }
.grid td.neg, .neg { color: var(--red); }
.grid td.up { color: var(--green); font-weight: 600; }
.grid td.down { color: var(--red); font-weight: 600; }
.grid td.nodata { color: var(--red); font-size: 12.5px; }
.grid td.muted, .muted { color: var(--muted); }

/* calculator */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; margin-top: 28px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 20px; background: var(--paper); }
.card h2 { margin-bottom: 14px; }
.inputs { display: grid; gap: 10px; margin-bottom: 14px; }
.inputs label { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 12px; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.inputs input { text-align: right; width: 100%; }
.result { margin: 16px 0 0; }
.result div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); }
.result dt { color: var(--muted); }
.result dd { margin: 0; font-weight: 800; font-size: 18px; text-align: right; }
.result .err { color: var(--red); font-weight: 600; border-top: 1px solid var(--line); padding-top: 9px; }

/* how to use */
.prose { max-width: 640px; margin-top: 24px; }
.prose h2 { margin: 26px 0 6px; }
.prose p { margin: 0; color: var(--muted); }

/* settings dialog */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(900px, 94vw); max-height: 88vh; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(15, 18, 24, 0.55); }
.settings { padding: 26px 30px 30px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 26px; font-weight: 800; }
.row { display: flex; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); }
.row form { display: flex; align-items: center; gap: 14px; margin: 0; }
.linkbtn { font: inherit; font-weight: 700; background: none; border: 0; cursor: pointer; padding: 0; }
table.plain { width: 100%; border-collapse: collapse; font-size: 14px; }
.plain td, .plain th { padding: 8px 10px 8px 0; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.plain th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--paper); }
.plain td:first-child { color: var(--muted); font-weight: 600; width: 130px; }
.formulas { margin: 0; padding-left: 18px; color: var(--ink); }
.formulas li { margin: 6px 0; }

/* login */
body.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg, #2b3f4f 0%, #121d26 62%, #0a141b 100%); }
.hills { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.login-card { position: relative; z-index: 1; width: min(440px, 92vw); background: var(--paper); border-radius: 12px; padding: 40px 40px 44px; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45); }
.login-card label { display: block; font-weight: 600; color: #3a414b; margin: 18px 0 8px; }
.login-card input { width: 100%; padding: 14px; font-size: 16px; }
.pw { position: relative; }
.pw .show { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: 0; font: inherit; font-weight: 700; cursor: pointer; }
.login-card .primary { width: 100%; margin-top: 26px; display: flex; justify-content: space-between; align-items: center; font: inherit; font-weight: 700; font-size: 17px; padding: 16px 18px; background: var(--ink); color: #fff; border: 0; border-radius: 8px; cursor: pointer; }
.login-error { color: var(--red); font-weight: 600; margin: 14px 0 0; }

@media (max-width: 720px) {
  .topbar { gap: 14px; padding: 0 14px; }
  .page { padding: 24px 14px 60px; }
  h1 { font-size: 32px; }
  .tabs a { padding: 0 8px; font-size: 13px; }
  .link { display: none; }
}
