:root {
  --ink: #1c2421;
  --muted: #6f655b;
  --paper: #efe6d6;
  --card: #fffaf3;
  --line: #eadfcd;
  --orange: #e4572e;
  --orange-deep: #c2410c;
  --green: #0f6e56;
  --rose: #9f1239;
  --sidebar: #1c2421;
  --shadow: 0 18px 50px rgba(48, 32, 14, 0.08);
  color-scheme: light;
  font-family: "Outfit", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--orange-deep); }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

body:not(.login-body):not(.slip-body) {
  display: grid;
  grid-template-columns: 232px 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: #f6f1e7;
  min-height: 100vh;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand svg { width: 42px; height: 42px; color: #ffb088; flex: none; }
.brand strong { display: block; font-family: "Fraunces", Georgia, serif; font-size: 18px; line-height: 1.15; font-weight: 560; }
.brand em { color: #c8bfb2; font-style: normal; font-size: 12px; letter-spacing: 0.12em; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar a {
  text-decoration: none;
  color: inherit;
  padding: 8px 10px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}
.sidebar a small { color: #b7aea3; font-size: 12px; }
.sidebar a[aria-current="page"] { background: #31403b; }
.side-foot { margin-top: auto; display: grid; gap: 8px; color: #d9d0c4; font-size: 14px; }
.side-foot button, .ghost {
  background: transparent;
  border: 1px solid #6d645c;
  color: inherit;
  border-radius: 999px;
  padding: 8px 12px;
}
.side-foot a { color: #ffb088; }

main { padding: 28px 28px 64px; }
h1, h2 { font-family: "Fraunces", Georgia, serif; font-weight: 560; margin: 0; }
h1 { font-size: 40px; letter-spacing: -0.03em; }
h2 { font-size: 22px; margin-bottom: 12px; }
.muted, .hint { color: var(--muted); }
.page-head, .filters, .row-actions { display: flex; gap: 12px; align-items: end; justify-content: space-between; flex-wrap: wrap; }
.page-head { margin-bottom: 18px; }
.filters, .row-actions { margin: 12px 0; }
.month-label, .filters label, .stack label, dialog label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  background: white;
  border: 1px solid #e4d8c6;
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 0;
}
textarea { resize: vertical; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.narrow { max-width: 560px; }
.stack { display: grid; gap: 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { display: block; margin-top: 6px; font-family: "Fraunces", Georgia, serif; font-size: 28px; font-weight: 560; }
.split { display: grid; grid-template-columns: 1.3fr 0.7fr; gap: 14px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #efe4d4; white-space: nowrap; vertical-align: middle; }
th { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
td.wrap { white-space: normal; min-width: 180px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 18px; }
button, .login-card button, dialog button[type="submit"] {
  background: var(--orange);
  color: white;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
}
button.danger { background: transparent; color: var(--rose); border: 1px solid #f3c3d0; }
button.linkish { background: transparent; color: var(--orange-deep); border: 0; padding: 0; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); }
.tag { border-radius: 999px; padding: 2px 8px; font-size: 12px; background: #ece7df; }
.tag.Active, .tag.P { background: #e5f6ee; color: var(--green); }
.tag.Inactive, .tag.A { background: #fde8ee; color: var(--rose); }
.tag.L { background: #fff1df; color: var(--orange-deep); }
.tag.H { background: #ece7df; color: #57534e; }
.money-pos { color: var(--green); }
.money-neg { color: var(--rose); }
.form-error { color: var(--rose); margin: 0; }
dialog { border: 0; padding: 0; border-radius: 18px; background: var(--card); width: min(520px, calc(100vw - 24px)); box-shadow: 0 24px 80px rgba(40, 28, 12, 0.28); }
dialog::backdrop { background: rgba(28, 36, 33, 0.46); }
dialog form { display: grid; gap: 12px; padding: 22px; }
dialog menu, .row-actions { justify-content: flex-end; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; }
.toast { background: var(--ink); color: white; padding: 12px 14px; border-radius: 12px; max-width: 320px; }
.toast.bad { background: var(--rose); }
.grid th:first-child, .grid td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
.mark { width: 34px; height: 30px; border-radius: 8px; padding: 0; background: transparent; color: #a8a29e; border: 1px solid #e7dccb; }
.mark.P { background: #e5f6ee; color: var(--green); border-color: transparent; }
.mark.A { background: #fde8ee; color: var(--rose); border-color: transparent; }
.mark.L { background: #fff1df; color: var(--orange-deep); border-color: transparent; }
.mark.H { background: #ece7df; color: #57534e; border-color: transparent; }
.sun { color: var(--rose); }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #fff7ea, var(--paper) 45%, #e7d3b5); }
.login-card { width: min(440px, 100%); background: var(--card); border-radius: 24px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card h1 { font-size: 42px; }
.eyebrow { letter-spacing: 0.16em; text-transform: uppercase; color: var(--orange-deep); margin: 0; font-size: 12px; }
.slip-body { background: #d9d0c3; padding: 24px; }
.slip-toolbar { width: min(720px, 100%); margin: 0 auto 12px; display: flex; justify-content: space-between; }
.slip { width: min(720px, 100%); margin: 0 auto; background: white; padding: 32px; border-radius: 8px; }
.slip header { display: flex; justify-content: space-between; align-items: end; border-bottom: 2px solid var(--ink); padding-bottom: 10px; }
.slip header p, .slip header h1 { margin: 0; }
.slip dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin: 18px 0; }
.slip dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.slip dd { margin: 0; font-size: 18px; }
.net { display: flex; justify-content: space-between; align-items: center; background: #1c2421; color: white; padding: 14px 16px; border-radius: 12px; }
.net strong { font-family: "Fraunces", Georgia, serif; font-size: 32px; }
.signs { display: flex; justify-content: space-between; margin-top: 48px; }
.signs span { border-top: 1px solid var(--ink); padding-top: 6px; min-width: 140px; }

.topbar, .nav-backdrop { display: none; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
button.nav-toggle {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  border: 1px solid #e4d8c6;
  display: grid;
  place-items: center;
}
.nav-bars, .nav-bars::before, .nav-bars::after {
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
  position: relative;
}
.nav-bars::before, .nav-bars::after { content: ""; position: absolute; left: 0; }
.nav-bars::before { top: -5px; }
.nav-bars::after { top: 5px; }
.login-card label { display: grid; gap: 6px; }
.login-card input, .login-card button, .stack input, .stack select, .stack textarea, dialog input, dialog select, dialog textarea { width: 100%; }

@media (max-width: 900px) {
  body:not(.login-body):not(.slip-body) {
    display: block;
    padding-top: 58px;
    overflow-x: clip;
  }
  .brand strong, .login-card h1, .topbar strong { overflow-wrap: anywhere; }
  .topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    z-index: 25;
    top: 0;
    left: 0;
    right: 0;
    height: 58px;
    padding: 8px 12px;
    background: rgba(239, 230, 214, 0.96);
    border-bottom: 1px solid var(--line);
  }
  .topbar strong { font-family: "Fraunces", Georgia, serif; font-size: 18px; font-weight: 560; }
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(28, 36, 33, 0.46); }
  .nav-backdrop[hidden] { display: none; }
  .sidebar {
    position: fixed;
    z-index: 40;
    top: 0;
    left: 0;
    width: min(300px, 88vw);
    height: 100vh;
    min-height: 100vh;
    overflow: auto;
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar nav { grid-template-columns: 1fr; }
  .sidebar a { min-height: 44px; justify-content: center; }
  .split, .pair, .slip dl { grid-template-columns: 1fr; }
  main { padding: 18px 14px 48px; }
  h1, .login-card h1 { font-size: 32px; }
  .page-head, .filters, .row-actions, .slip-toolbar, .slip header, .net { align-items: stretch; }
  .filters > *, .row-actions > *, .page-head .month-label { flex: 1 1 160px; }
  input, select, textarea, .login-card button, .slip-toolbar button { min-height: 44px; }
  .mark { width: 40px; height: 40px; }
  .stat b { font-size: 24px; }
  #toasts { left: 12px; right: 12px; }
  .toast { max-width: none; }
  .slip { padding: 18px 14px; }
  .slip header, .signs { flex-direction: column; align-items: flex-start; gap: 16px; }
  .net strong { font-size: 26px; }
  .login-body { padding: 16px; }
  .login-card { padding: 22px 16px; }
}
@media print {
  .slip-toolbar { display: none; }
  .slip-body { background: white; padding: 0; }
  .slip { width: 100%; }
}
