:root {
  color-scheme: light;
  --ink: #282138;
  --muted: #655c76;
  --accent: #583ca2;
  --accent-hover: #49318c;
  --accent-soft: #eee8fa;
  --sidebar: #242037;
  --page: #f7f6fa;
  --paper: #fff;
  --line: #e6e1ed;
  --green: #23634f;
  --green-soft: #e7f4ed;
  --red: #982f46;
  --red-soft: #fbeaf0;
  --radius: 19px;
  --shadow: 0 3px 12px #25194009;
  font-family: Inter, "Instrument Sans", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button, input:not([type=checkbox]), select {
  min-height: 42px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
}
button {
  cursor: pointer;
  font-size: .9rem;
  font-weight: 650;
  transition: background-color .15s, border-color .15s;
}
button:not(:disabled):hover { background: #f5f2fa; border-color: #c9bddb; }
button:disabled { opacity: .48; cursor: default; }
button.primary {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}
button.primary:not(:disabled):hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--red); }
input::placeholder { color: var(--muted); opacity: 1; }
input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
:focus-visible { outline: 3px solid #9779dc; outline-offset: 3px; }
a { color: inherit; }
p { margin: 0; }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -.035em; }
h1 { font-size: clamp(2.15rem, 4vw, 3.05rem); font-weight: 760; }
h2 { font-size: 1.45rem; font-weight: 740; }
h3 { font-size: 1.05rem; }
small { font-size: .83rem; color: var(--muted); }
svg {
  width: 19px;
  height: 19px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  transform: translateY(calc(-100% - 20px));
  z-index: 3;
  padding: 10px 16px;
  border-radius: 9px;
  background: var(--paper);
}
.skip-link:focus { transform: none; }

.workspace {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 29px 15px 17px;
  background:
    radial-gradient(ellipse at top left, #42325d 0, transparent 42%),
    var(--sidebar);
  color: #f8f4ff;
  overflow: auto;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 0 10px;
  width: fit-content;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 43px;
  height: 43px;
  background: linear-gradient(150deg, #f4edff, #d9c8fb);
  border-radius: 12px;
  color: #51378c;
  font: italic 600 28px/1 "Cormorant Garamond", Georgia, serif;
  box-shadow: inset 0 0 0 1px #ffffff70;
}
.brand-wordmark { font-size: 1.21rem; line-height: 1.1; font-weight: 680; letter-spacing: -.025em; }
.brand-wordmark span {
  display: block;
  margin-top: 4px;
  color: #d2c4eb;
  font-size: .73rem;
  font-weight: 550;
  letter-spacing: .17em;
  text-transform: uppercase;
}
.workspace-nav {
  display: grid;
  gap: 5px;
  margin-top: 46px;
}
.workspace-nav a,
button.logout-button {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 9px;
  color: #e2d9f0;
  font-size: .91rem;
  font-weight: 560;
  text-decoration: none;
}
.workspace-nav a:hover, button.logout-button:not(:disabled):hover { background: #ffffff12; color: white; }
body:not(:has(#finance:target, #ledger:target, #backupPanel:target)) .nav-overview,
body:has(#finance:target) .nav-control,
body:has(#ledger:target) .nav-ledger,
body:has(#backupPanel:target) .nav-backup {
  background: #b292e52b;
  color: #fff;
  box-shadow: inset 0 0 0 1px #d5bfff26;
}
.workspace-nav svg, .logout-button svg { color: #d4c1f3; }
.sidebar-footer { margin-top: auto; padding-top: 28px; }
#status {
  margin: 0 10px 12px;
  color: #d4c8e3;
  font-size: .77rem;
}
#status:empty { display: none; }
#logout { border-top: 1px solid #ffffff20; padding-top: 8px; }
button.logout-button { width: 100%; background: transparent; border-color: transparent; }
button.logout-button:not(:disabled):hover { border-color: transparent; }

.content {
  width: 100%;
  max-width: 1540px;
  margin-inline: auto;
  padding: 36px clamp(22px, 3.5vw, 60px) 55px;
  min-width: 0;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 26px;
}
button.add-button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding-inline: 16px;
  box-shadow: 0 4px 10px #52369629;
}
.period-panel {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 20px;
  border: 1px solid #e1d7f3;
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse at top right, #e3d6fa 0, transparent 55%),
    linear-gradient(105deg, #f3eefa, #f8f5fc);
}
.period-intro, .period-fields { display: flex; align-items: center; gap: 10px; }
.period-intro h2 { color: #493276; font-size: 1rem; letter-spacing: -.015em; }
.period-intro svg {
  width: 37px;
  height: 37px;
  padding: 9px;
  border: 1px solid #e4daf3;
  border-radius: 11px;
  color: #624697;
  background: #ffffffa8;
}
.period-fields { flex-wrap: wrap; }
.period-fields input, .period-fields select { border-color: #ded3ef; font-size: .9rem; }
#endLabel { display: flex; align-items: center; gap: 8px; font-size: .85rem; }

.summary-group { margin-top: 17px; }
.summary-heading {
  color: var(--muted);
  font-size: .83rem;
  letter-spacing: .02em;
  margin: 0 2px 7px;
}
.cards, .control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 10px;
}
.card, .control-card, .panel, .summary-empty {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 6px;
  min-height: 94px;
  padding: 14px 15px;
  border-radius: 14px;
}
.card strong, .control-stat, .amount strong {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.card strong { font-size: clamp(1.02rem, 1.65vw, 1.45rem); letter-spacing: -.035em; }
.card small { font-weight: 580; }
.card:nth-child(1) { border-top-color: #cbb7e9; }
.card:nth-child(2) { border-top-color: #d4c1ed; }
.card:nth-child(3) {
  border-color: #dfd2f3;
  border-top-color: #b59ddf;
  background: linear-gradient(140deg, #fff, #f3eefb);
}
.card:nth-child(4) { border-top-color: #acd2c3; }
.card:nth-child(5) { border-top-color: #e4c39f; }
.summary-empty { padding: 18px; margin-top: 12px; color: var(--muted); }
.section { margin-top: 28px; scroll-margin-top: 18px; min-width: 0; }
.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}
.control-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }
.control-card {
  min-width: 0;
  padding: 17px 18px;
  display: grid;
  align-content: start;
  gap: 9px;
}
.control-card h3 { color: #503482; }
.control-card dl { margin: 0; }
.control-card dl > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}
.control-card dl > div + div { border-top: 1px solid var(--line); }
.control-card dt { color: var(--muted); }
.control-card dd { margin: 0; text-align: end; font-weight: 680; overflow-wrap: anywhere; }
.control-stat { font-size: 1.35rem; font-weight: 750; letter-spacing: -.03em; }
.control-stat:has(small) {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: .96rem;
  letter-spacing: 0;
}
.control-stat small { display: block; font-weight: 540; }
.control-stat.late { color: var(--red); }
progress.meter, progress {
  width: 100%;
  height: 7px;
  border: 0;
  border-radius: 100px;
  accent-color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--accent-soft); border-radius: inherit; }
progress::-webkit-progress-value { background: var(--accent); border-radius: inherit; }
progress::-moz-progress-bar { background: var(--accent); border-radius: inherit; }
.muted { color: var(--muted); }

.ledger { padding: 18px; }
.ledger-header { margin-bottom: 16px; }
.export-actions, .ledger-toolbar, .tabs, .ledger-filters, .bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}
.export-actions button { min-height: 36px; padding-block: 5px; color: var(--accent); }
.ledger-toolbar { justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.tabs { padding: 4px; background: #f2eff7; border-radius: 11px; gap: 3px; }
.tabs button { min-height: 34px; padding: 5px 10px; background: transparent; border-color: transparent; }
.tabs button[aria-pressed=true] {
  background: var(--paper);
  border-color: #e9e2f3;
  color: #53368f;
  box-shadow: var(--shadow);
}
.ledger-filters input, .ledger-filters select { font-size: .87rem; min-height: 40px; }
.search-field { position: relative; display: inline-flex; flex: 1 1 158px; min-width: 0; }
.search-field svg { position: absolute; top: 50%; left: 9px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 34px; width: 100%; min-width: 0; }
#notice:not(:empty) {
  display: block;
  padding: 10px 12px;
  margin: 4px 0 11px;
  background: var(--accent-soft);
  color: #472b81;
  border-radius: 9px;
}
.rows { display: grid; }
.rows > .muted { padding: 16px 4px 6px; }
.rows article {
  display: grid;
  grid-template-columns: minmax(130px, 1.2fr) minmax(100px, .75fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 10px 3px;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.row-info { display: grid; gap: 3px; }
.row-title, .rows article strong { font-weight: 700; }
.amount { text-align: right; }
.amount > * { display: block; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: end; gap: 6px; }
.row-actions button { min-height: 36px; padding: 5px 9px; font-size: .8rem; }
.status-pill {
  display: inline-flex;
  width: fit-content;
  border-radius: 50px;
  background: var(--accent-soft);
  color: #543c84;
  padding: 4px 8px;
  font-size: .77rem;
  font-weight: 660;
}
.status-pill.paid, button.paid { background: var(--green-soft); color: var(--green); }
.status-pill.late { background: var(--red-soft); color: var(--red); }
.status-pill.pending { background: #fbf0dc; color: #704915; }
button.status-pill:not(:disabled):hover { border-color: currentColor; }
button.status-pill:disabled { opacity: .85; }

.backup-panel { padding: 14px 18px; }
.backup-panel summary { width: fit-content; font-weight: 700; cursor: pointer; }
.backup-panel summary::marker { color: var(--accent); }
.backup-panel:target { border-color: #c9b6e9; }
.backup-actions { margin-top: 14px; }

dialog {
  width: min(560px, calc(100% - 24px));
  max-height: 92dvh;
  padding: 23px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 70px #20153638;
}
dialog::backdrop { background: #211b35aa; }
#form, .login-card form { display: grid; gap: 13px; }
.field, .login-card label { display: grid; gap: 4px; min-width: 0; font-size: .9rem; font-weight: 620; }
.field > *, .login-card input { min-width: 0; width: 100%; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check-fields, .editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.check-fields label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: .89rem;
  cursor: pointer;
}
.editor-actions { justify-content: end; padding-top: 10px; border-top: 1px solid var(--line); }
.editor-actions .danger { margin-right: auto; }

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(ellipse at 18% 20%, #e5d8fa, transparent 50%), var(--page);
}
.login-card {
  width: min(100%, 430px);
  padding: clamp(22px, 5vw, 39px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 25px;
  box-shadow: 0 18px 58px #39235a19;
}
.login-card h1 { margin: 16px 0 8px; font-size: clamp(1.8rem, 6vw, 2.6rem); }
.login-copy { color: var(--muted); margin-bottom: 17px; }
.login-card form button { margin-top: 5px; min-height: 44px; }
.login-error { color: var(--red); font-size: .88rem; }
.login-error:empty { display: none; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 190px minmax(0, 1fr); }
  .content { padding-inline: 22px; }
  .sidebar { padding-inline: 11px; }
  .rows article { grid-template-columns: minmax(130px, 1fr) minmax(100px, .6fr); }
  .row-actions { grid-column: 1 / -1; justify-content: start; }
}
@media (max-width: 760px) {
  .workspace { display: block; }
  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand footer" "nav nav";
    gap: 11px 8px;
    padding: 12px 15px;
  }
  .brand { grid-area: brand; margin: 0; }
  .brand-mark { width: 37px; height: 37px; border-radius: 10px; font-size: 25px; }
  .brand-wordmark { font-size: 1.12rem; }
  .brand-wordmark span { font-size: .66rem; }
  .sidebar-footer { grid-area: footer; margin: 0; padding: 0; }
  #status { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); }
  #logout { border: 0; padding: 0; }
  button.logout-button { min-height: 38px; padding: 6px 8px; }
  .workspace-nav {
    grid-area: nav;
    display: flex;
    gap: 5px;
    margin: 0 -4px;
    overflow-x: auto;
    padding: 3px 4px;
  }
  .workspace-nav a { min-height: 38px; gap: 7px; font-size: .83rem; padding: 6px 9px; white-space: nowrap; }
  .workspace-nav svg, .logout-button svg { width: 16px; height: 16px; }
  .content { padding: 22px 15px 40px; }
  .page-header { margin-bottom: 17px; }
  .section { margin-top: 22px; }
}
@media (max-width: 540px) {
  .page-header h1 { font-size: clamp(1.68rem, 6.8vw, 2rem); }
  button.add-button { min-height: 41px; gap: 3px; padding-inline: 9px; }
  .period-panel { align-items: stretch; flex-direction: column; gap: 8px; padding: 12px; }
  .period-fields input, .period-fields select { min-width: 0; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(min(100%, 115px), 1fr)); }
  .card { min-height: 80px; padding: 10px; }
  .ledger { padding: 13px; }
  .ledger-filters { width: 100%; }
  .ledger-filters .search-field { flex-basis: 100%; }
  .ledger-filters select { flex: 1 1 126px; min-width: 0; }
  .rows article { grid-template-columns: minmax(0, 1fr) minmax(85px, auto); gap: 8px; }
  dialog { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
