:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #172033;
  --muted: #697386;
  --line: #e6e9f0;
  --brand: #5b5ff4;
  --brand2: #8a5cf6;
  --income: #16a46f;
  --expense: #e64d4d;
  --warning: #b7791f;
  --radius: 18px;
  --shadow: 0 16px 45px rgba(23, 32, 51, 0.08);
}
* { box-sizing: border-box; }
.debt-page .debt-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.debt-page .debt-summary strong { font-size: clamp(19px, 2.5vw, 28px); overflow-wrap: anywhere; }
.debt-page .debt-settings-grid { display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 14px; align-items: end; }
.debt-page .debt-months { display: grid; gap: 10px; }
.debt-page .debt-month-row { display: grid; grid-template-columns: 150px minmax(120px, .7fr) minmax(170px, 1.3fr); gap: 14px; align-items: center; padding: 14px; background: #f8f9fd; border: 1px solid var(--line); border-radius: 14px; }
.debt-page .debt-month-row h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 15px; }
.debt-page .debt-month-number { display: inline-grid; place-items: center; border-radius: 9px; min-width: 26px; height: 26px; color: var(--brand); background: #eaeaff; font-size: 12px; }
.debt-page .debt-month-row label { font-size: 12px; color: var(--muted); }
.debt-page .debt-month-row input { font-size: 15px; }
.debt-page .debt-save-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; position: sticky; bottom: 10px; padding: 12px; border-radius: 14px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.debt-page .debt-save-bar span { font-size: 13px; color: var(--muted); }
@media (max-width: 1100px) {
  .debt-page .debt-month-row { grid-template-columns: minmax(105px, .8fr) minmax(100px, 1fr); }
  .debt-page .debt-note { grid-column: span 2; }
  .debt-page .debt-settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) { .debt-page .debt-summary { grid-template-columns: 1fr; } }
.personal-entry-form .personal-amount-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.personal-entry-form .signed-amount { display: flex; align-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: white; }
.personal-entry-form .signed-amount.income { color: var(--income); }
.personal-entry-form .signed-amount.expense { color: var(--expense); }
.personal-entry-form .amount-sign { display: inline-grid; place-items: center; min-width: 40px; align-self: stretch; font-size: 26px; font-weight: 800; background: #f8f9fd; }
.personal-entry-form .signed-amount input { min-width: 0; border: 0; border-radius: 0; font-size: 22px; color: inherit; font-variant-numeric: tabular-nums; }
.personal-entry-form .signed-amount:focus-within { border-color: var(--brand); outline: 3px solid rgba(91,95,244,.15); }
.personal-entry-form .signed-amount input:focus { outline: none; }
.business-book { --brand: #087f79; --brand2: #18a384; }
.book-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #eef0f7; padding: 5px; border-radius: 12px; }
.book-switch a { padding: 9px 3px; text-align: center; font-weight: 700; color: var(--muted); border-radius: 9px; }
.book-switch a[aria-current] { background: var(--brand); color: white; }
.book-banner { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 14px 16px; margin-bottom: 16px; background: #eef0ff; border-radius: 14px; border-left: 4px solid var(--brand); }
.book-banner strong { color: var(--brand); white-space: nowrap; }
.book-banner span { color: var(--muted); font-size: 13px; }
.business-book .book-banner { background: #e7f7f1; }
.business-book { background: radial-gradient(circle at 15% 0%, #dff3ed 0, transparent 32rem), var(--bg); }
.main-book-switch { max-width: 380px; margin-bottom: 12px; }
.public-notice { font-size: 12px; margin: 0 0 20px; }
.business-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.direction-card { display: grid; gap: 5px; padding: 18px; border: 2px solid var(--line); border-radius: 16px; background: white; color: var(--ink); }
.direction-card strong { font-size: clamp(20px, 3vw, 28px); overflow-wrap: anywhere; }
.direction-card small { color: var(--muted); }
.direction-card.expense strong { color: var(--expense); }
.direction-card.income strong { color: var(--income); }
.direction-card.active { border-color: var(--brand); background: #f1fbf7; }
.business-layout { display: grid; grid-template-columns: minmax(240px, .85fr) minmax(0, 1.65fr); gap: 20px; align-items: start; }
.business-form { max-width: 650px; }
.business-description { overflow-wrap: anywhere; min-width: 80px; max-width: 280px; }
textarea { width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 10px; font: inherit; color: var(--ink); }
@media (max-width: 1100px) { .business-layout { grid-template-columns: 1fr; } .business-form { max-width: none; } }
body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at 15% 0%, #ececff 0, transparent 32rem), var(--bg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--brand); text-decoration: none; }
button, .button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}
button:hover, .button:hover { border-color: #cbd1df; transform: translateY(-1px); }
.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  border: 0;
  color: white;
  box-shadow: 0 10px 24px rgba(91, 95, 244, 0.25);
}
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 230px;
  padding: 24px 18px;
  background: rgba(255,255,255,.82);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand small { display: block; color: var(--muted); }
.logo {
  width: 42px; height: 42px; border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  color: white; display: inline-grid; place-items: center;
  font-weight: 900; font-size: 24px;
}
.logo.big { width: 64px; height: 64px; border-radius: 22px; font-size: 36px; }
nav { display: grid; gap: 8px; }
nav a {
  padding: 11px 12px;
  border-radius: 12px;
  color: var(--ink);
  font-weight: 700;
}
nav a:hover { background: #f0f2ff; color: var(--brand); }
.logout { margin-top: auto; }
.logout button { width: 100%; }
main { margin-left: 230px; padding: 34px; max-width: 1440px; }
.main-full { margin: 0; min-height: 100vh; display: grid; place-items: center; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
h1, h2 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 32px; }
h2 { font-size: 19px; }
p { color: var(--muted); margin: 0; }
.card {
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card-head, .actions, .inline {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat {
  padding: 20px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.stat span { color: var(--muted); display: block; margin-bottom: 8px; }
.stat strong { font-size: 28px; }
.stat.expense strong, .money.expense { color: var(--expense); }
.stat.income strong, .money.income { color: var(--income); }
.stat.net strong { color: var(--brand); }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; font-weight: 800; }
tr:last-child td { border-bottom: 0; }
.dense th, .dense td { padding: 9px 8px; font-size: 14px; }
.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill, .status, .chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #eef0f7;
}
.pill.expense { color: var(--expense); background: #ffecec; }
.pill.income { color: var(--income); background: #e9fbf3; }
.pill.transfer { color: #7c5b00; background: #fff6d7; }
.status.ok { color: var(--income); background: #e9fbf3; }
.muted, .hint { color: var(--muted); }
.hint {
  margin-top: 14px;
  padding: 14px;
  border-radius: 14px;
  background: #f8f9fd;
}
.form { display: grid; gap: 14px; }
.form.wide { max-width: 980px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span2 { grid-column: span 2; }
label { display: grid; gap: 7px; font-weight: 800; }
input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus {
  outline: 3px solid rgba(91,95,244,.15);
  border-color: var(--brand);
}
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.flashes { margin-bottom: 16px; display: grid; gap: 8px; }
.flash {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}
.flash.success { border-color: #bfead7; background: #f0fff8; color: #0c7c51; }
.flash.error { border-color: #ffc6c6; background: #fff3f3; color: #c23030; }
.flash.warning { border-color: #ffe1a8; background: #fff9ea; color: var(--warning); }
.flash.info { border-color: #cdd7ff; background: #f3f6ff; color: #3e4fd0; }
.login-card { width: min(920px, calc(100vw - 34px)); display: grid; grid-template-columns: 1.2fr .8fr; gap: 20px; align-items: stretch; }
.login-hero {
  border-radius: 28px;
  padding: 42px;
  background: linear-gradient(135deg, #171b46, #5b5ff4);
  color: white;
  box-shadow: var(--shadow);
}
.login-hero p { color: rgba(255,255,255,.78); max-width: 420px; }
.login-hero h1 { font-size: 44px; margin-top: 18px; }
.bars { display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 52px 1fr 1fr; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.bar-track { height: 10px; background: #eef0f7; border-radius: 99px; overflow: hidden; }
.bar-track i { display: block; height: 100%; min-width: 2px; border-radius: inherit; }
.bar-expense { background: var(--expense); }
.bar-income { background: var(--income); }
.empty { color: var(--muted); text-align: center; padding: 30px 8px; }
.row-actions { display: flex; gap: 8px; align-items: center; }
.row-actions form { margin: 0; }
.link {
  border: 0; background: transparent; min-height: auto; padding: 0;
  color: var(--brand); font-weight: 700; box-shadow: none;
}
.danger { color: var(--expense); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.connector { display: grid; gap: 12px; }
.pagination { display: flex; justify-content: center; gap: 18px; padding-top: 16px; }
@media (max-width: 980px) {
  .sidebar { position: static; width: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  main { margin-left: 0; padding: 20px; }
  nav { grid-template-columns: repeat(3, 1fr); }
  .stats, .grid.two, .grid.three, .login-card { grid-template-columns: 1fr; }
  .filters, .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: span 1; }
  .page-head { align-items: flex-start; flex-direction: column; }
  table { display: block; overflow-x: auto; }
}
/* Personal cycle dashboard; business styles and scripts remain unchanged. */
.personal-overview .period-picker { display:flex; flex-wrap:wrap; gap:12px; align-items:end; }
.personal-overview .period-picker label { max-width:240px; }
.personal-overview #refresh-status { flex:1 1 240px; font-size:13px; padding:8px 0; }
.personal-overview .period-heading { display:flex; flex-wrap:wrap; gap:12px; align-items:center; justify-content:space-between; }
.personal-overview .period-heading p { font-size:13px; }
.personal-overview .period-heading h2 { margin-bottom:6px; }
.personal-overview .ranking-list { padding:0; margin:0; list-style:none; display:grid; gap:20px; }
.personal-overview .ranking-list li { display:flex; align-items:center; gap:12px; }
.personal-overview .rank-number { display:grid; place-items:center; width:30px; height:30px; flex:0 0 30px; background:#f0efff; color:var(--brand); border-radius:9px; font-weight:800; }
.personal-overview .ranking-list li:first-child .rank-number { background:var(--brand); color:white; }
.personal-overview .rank-detail { flex:1; min-width:0; }
.personal-overview .rank-title, .personal-overview .rank-meta { display:flex; flex-wrap:wrap; justify-content:space-between; gap:6px; overflow-wrap:anywhere; }
.personal-overview .rank-meta { font-size:12px; color:var(--muted); margin:4px 0 8px; }
.personal-overview .history-periods { display:flex; flex-wrap:wrap; gap:8px; max-height:280px; overflow:auto; }
.personal-overview .history-periods .button { font-size:13px; }
.personal-overview .history-periods [aria-current] { border-color:var(--brand); color:var(--brand); background:#f0efff; }
.personal-entry-form .entry-time { display:grid; gap:6px; }
.personal-entry-form .entry-time time { font-size:18px; font-variant-numeric:tabular-nums; padding:8px 11px; background:#f2f4ff; border-radius:12px; }
.personal-entry-form .entry-time small { font-weight:normal; }
@media (max-width:600px) {
  .personal-overview .period-heading .actions { flex-wrap:wrap; }
  .personal-overview .period-picker label { flex:1 1 100%; max-width:none; }
  .personal-overview .stats strong { font-size:25px; overflow-wrap:anywhere; }
}

/* Signed net for independent individual/partnership business ledgers. */
.business-net { display:grid; gap:12px; margin-bottom:20px; }
.business-net > span, .business-net small { color:var(--muted); }
.business-net strong { font-size:38px; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }
.main-book-switch { grid-template-columns:repeat(3,minmax(0,1fr)); max-width:540px; }
.business-net strong.income { color:var(--income); }
.business-net strong.expense { color:var(--expense); }
.business-book .page-head .inline { flex-shrink:0; }
.business-book .page-head .inline button { white-space:nowrap; flex-shrink:0; }
@media (max-width:600px) { .business-net strong { font-size:30px; } }

/* Stable feedback outside the swapped view; never blocks the book switch. */
#ledger-feedback {
  position:fixed; z-index:50; bottom:max(18px,env(safe-area-inset-bottom));
  left:50%; transform:translateX(-50%); width:max-content; max-width:calc(100vw - 24px);
  display:flex; align-items:center; gap:12px; padding:12px 16px;
  color:#fff; background:#24283e; border-radius:14px; box-shadow:0 8px 28px #10142933;
  font-size:14px; line-height:1.5;
}
#ledger-feedback[hidden] { display:none; }
#ledger-feedback button { flex-shrink:0; min-height:36px; padding:6px 12px; background:#fff; color:#24283e; border:0; }
@media (max-width:600px) { #ledger-feedback { width:calc(100vw - 24px); } }

/* Entry-first layout: sign inputs lead every entry form, reports have their own page. */
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
.entry-first, .business-form.entry-first { width:100%; max-width:none; }
.entry-first .personal-amount-grid { gap:16px; }
.entry-first .signed-amount input { font-size:30px; min-height:64px; }
.entry-first .amount-sign { min-width:48px; font-size:32px; }
.entry-details { display:grid; grid-template-columns:1fr 2fr; gap:12px; }
.entry-details .entry-note { grid-column:1 / -1; }
.entry-first .entry-time { display:flex; align-items:center; flex-wrap:wrap; gap:8px; color:var(--muted); font-size:13px; }
.entry-first .entry-time time { font-size:14px; padding:0; background:none; }
.entry-first > .primary { min-height:44px; }
.personal-net small { display:inline-block; margin-left:12px; }
.overview-footer { display:flex; flex-wrap:wrap; justify-content:space-between; align-items:center; gap:12px; }
.overview-footer #refresh-status { font-size:12px; }
.business-net .card-head { flex-wrap:wrap; }
.business-net .inline input { width:auto; max-width:180px; }
.business-net .inline button { flex-shrink:0; }
@media (max-width:600px) {
  main { padding:12px 12px 100px; }
  .main-book-switch { max-width:none; margin-bottom:12px; }
  .main-book-switch a { font-size:14px; min-height:44px; display:grid; place-items:center; }
  .entry-first { padding:16px; }
  .entry-first .personal-amount-grid { gap:10px; }
  .entry-first .signed-amount input { font-size:24px; min-height:58px; padding:8px; }
  .entry-first .amount-sign { min-width:30px; font-size:28px; }
  .entry-details { grid-template-columns:1fr; }
  .personal-net small { display:block; margin:4px 0 0; }
  .sidebar { position:fixed; inset:auto 0 0; width:100%; z-index:30; padding:6px 8px max(6px,env(safe-area-inset-bottom)); gap:4px; background:#fff; border-top:1px solid var(--line); border-bottom:0; }
  .sidebar .brand { display:none; }
  .sidebar nav { display:grid; grid-template-columns:none; grid-auto-flow:column; grid-auto-columns:minmax(50px,1fr); gap:2px; overflow-x:auto; }
  .sidebar nav a { padding:10px 3px; min-height:44px; text-align:center; font-size:13px; white-space:nowrap; }
  .sidebar .logout { margin:0; }
  .business-book .sidebar { display:none; }
  .business-book main { padding-bottom:24px; }
  #ledger-feedback { bottom:max(80px,calc(env(safe-area-inset-bottom) + 70px)); }
  .business-book #ledger-feedback { bottom:max(18px,env(safe-area-inset-bottom)); }
}
