:root {
  color-scheme: light;
  --ink: #1c302c;
  --muted: #71807a;
  --line: #e6ebe7;
  --paper: #ffffff;
  --canvas: #f5f7f4;
  --green: #245b4e;
  --green-dark: #183c37;
  --green-soft: #e9f4ed;
  --orange: #c7783e;
  --shadow: 0 8px 26px rgba(24, 60, 55, .055);
  font-family: "Segoe UI", "Aptos", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 72px;
  padding: 12px max(24px, calc((100% - 1240px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--green-dark);
  color: white;
}

.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 12px;
  color: #f2c98e;
  font-family: Georgia, serif;
  font-size: 24px;
  font-weight: 700;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .01em; }
.brand small { margin-top: 1px; color: #c6d6d0; font-size: 11px; }
.topbar-note { display: flex; align-items: center; gap: 8px; color: #d3e2dc; font-size: 12px; }
.live-dot { width: 7px; height: 7px; border-radius: 100%; background: #89d3a6; }
.account-tools { display: flex; align-items: center; gap: 12px; color: #d3e2dc; font-size: 12px; }
.account-tools > span { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sign-out-button { padding: 6px 10px; border: 1px solid #ffffff55; border-radius: 8px; background: transparent; color: white; font-size: 11px; font-weight: 700; }
.sign-out-button:hover { background: #ffffff14; }

.page { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 32px 0 48px; }
.welcome { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 5px; color: #76847e; font-size: 10px; font-weight: 800; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(28px, 3vw, 36px); font-weight: 600; letter-spacing: -.025em; line-height: 1.15; }
.welcome-copy { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.week-picker { min-width: 290px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); }
.week-controls { display: flex; align-items: center; justify-content: space-between; gap: 11px; }
.week-controls strong { text-align: center; font-size: 13px; }
.icon-button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: white; color: var(--green-dark); font-size: 18px; }
.text-button { display: block; margin: 5px auto 0; padding: 2px 6px; border: 0; background: transparent; color: var(--green); font-size: 11px; font-weight: 700; }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.summary-card { position: relative; min-height: 132px; padding: 17px 18px 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); }
.summary-icon { position: absolute; top: 15px; right: 16px; display: grid; place-items: center; width: 31px; height: 31px; border-radius: 10px; background: #fff3e9; color: #b86c39; font-size: 17px; font-weight: 700; }
.icon-green { background: #e8f4ec; color: #317b51; }
.icon-blue { background: #eaf1f8; color: #4774a0; }
.icon-orange { background: #fff2e5; color: #ba7037; }
.icon-purple { background: #f2ecf8; color: #7956a0; }
.icon-dark { background: #e8eeea; color: var(--green-dark); }
.summary-label { display: block; margin-bottom: 9px; color: #63736d; font-size: 12px; font-weight: 600; }
.summary-card > strong { display: block; font-size: 25px; letter-spacing: -.035em; line-height: 1.15; }
.summary-card > small { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; }
.summary-card > small b { color: var(--ink); }
.summary-primary { border-top: 3px solid #d6a05d; }
.summary-net { border-top: 3px solid var(--green); }

.work-area { display: grid; grid-template-columns: minmax(0, 1fr) 286px; align-items: start; gap: 18px; }
.main-column, .side-column { display: grid; gap: 18px; min-width: 0; }
.panel { padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: var(--paper); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.panel-heading h2, .report-panel h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 600; letter-spacing: -.01em; }
.panel-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.date-label { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }
.date-label input { min-height: 37px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); font-size: 12px; }
.notice { margin: 14px 0 0; padding: 9px 11px; border-radius: 8px; background: #fff4e8; color: #8a5125; font-size: 12px; }
.day-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 18px 0 17px; padding: 13px; border-radius: 11px; background: #f6f8f6; }
.day-stats > div { display: grid; gap: 3px; }
.day-stats span { color: var(--muted); font-size: 10px; }
.day-stats strong { font-size: 16px; }
.day-stats .day-net strong { color: var(--green); }
.day-tabs { display: flex; gap: 5px; border-bottom: 1px solid var(--line); }
.day-tab { position: relative; padding: 10px 12px; border: 0; background: transparent; color: #75827d; font-size: 12px; font-weight: 650; }
.day-tab span { margin-left: 4px; padding: 1px 5px; border-radius: 8px; background: #f0f3f0; font-size: 10px; }
.day-tab.active { color: var(--green-dark); }
.day-tab.active:after { position: absolute; right: 9px; bottom: -1px; left: 9px; height: 2px; background: #4b8c67; content: ""; }
.tab-content { padding-top: 17px; }
.entry-form { display: grid; grid-template-columns: 1.15fr .82fr .82fr 1.05fr auto; align-items: end; gap: 9px; margin-bottom: 17px; }
.entry-form label:not(.radio-choice) { display: grid; gap: 5px; min-width: 0; color: #64736d; font-size: 10px; font-weight: 700; }
.entry-form input:not([type="radio"]), .entry-form select { width: 100%; min-width: 0; height: 38px; padding: 7px 9px; border: 1px solid #dfe6e1; border-radius: 8px; outline: none; background: white; color: var(--ink); font-size: 12px; }
.entry-form input:focus, .entry-form select:focus { border-color: #4d9870; box-shadow: 0 0 0 3px rgba(77,152,112,.13); }
.payment-field { display: flex; align-items: center; gap: 4px; min-width: 0; height: 38px; margin: 0; padding: 0; border: 0; }
.payment-field legend { position: absolute; overflow: hidden; width: 1px; height: 1px; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.radio-choice { position: relative; }
.radio-choice input { position: absolute; opacity: 0; }
.radio-choice span { display: grid; place-items: center; height: 36px; padding: 0 10px; border: 1px solid #dfe6e1; border-radius: 8px; color: #687871; font-size: 11px; font-weight: 650; cursor: pointer; }
.radio-choice input:checked + span { border-color: #88b99a; background: #eef7f0; color: #245b4e; }
.radio-choice input:focus-visible + span { outline: 3px solid rgba(77,152,112,.25); }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 39px; padding: 8px 12px; border: 1px solid transparent; border-radius: 9px; font-size: 11px; font-weight: 750; transition: background .15s, transform .15s; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--green); color: white; }
.button-primary:hover { background: #1d4b40; }
.button-secondary { border-color: #dce5df; background: white; color: var(--green-dark); }
.button-secondary:hover { background: #f5f8f5; }
.form-submit { white-space: nowrap; }
.helper-copy { margin: 0 0 14px; color: var(--muted); font-size: 12px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 8px 9px; border-bottom: 1px solid var(--line); color: #87918c; font-size: 9px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
td { padding: 10px 9px; border-bottom: 1px solid #eef1ee; color: #4e5e58; font-size: 11px; }
td:first-child { color: var(--ink); font-weight: 650; }
td.amount-cell { color: var(--ink); font-weight: 700; white-space: nowrap; }
.payment-badge { display: inline-block; padding: 3px 7px; border-radius: 20px; background: #edf5ef; color: #397250; font-size: 10px; font-weight: 700; }
.payment-badge.momo { background: #f1ecf8; color: #715396; }
.remove-button { padding: 3px 7px; border: 0; border-radius: 6px; background: transparent; color: #a56d5c; font-size: 11px; }
.remove-button:hover { background: #fff1ed; }
.empty-state { margin: 12px 0 0; color: #89948f; font-size: 12px; text-align: center; }
.chart-key { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.chart-key i { width: 9px; height: 9px; border-radius: 3px; background: #52966b; }
.weekly-chart { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: end; gap: 12px; min-height: 170px; margin-top: 18px; padding: 8px 7px 0; border-bottom: 1px solid var(--line); }
.chart-day { display: flex; min-width: 0; height: 160px; flex-direction: column; align-items: center; justify-content: flex-end; gap: 7px; text-align: center; }
.chart-value { color: #53645d; font-size: 10px; font-weight: 700; }
.chart-track { display: flex; width: min(34px, 75%); height: 104px; align-items: flex-end; justify-content: center; }
.chart-bar { width: 100%; min-height: 4px; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, #76b381, #3c825d); }
.chart-bar.negative { background: #d7866e; }
.chart-label { padding-bottom: 7px; color: #718079; font-size: 10px; }
.chart-label.selected { color: var(--green-dark); font-weight: 800; }
.chart-footnote { margin: 10px 0 0; color: #87918c; font-size: 10px; }
.section-total { color: var(--green); font-size: 15px; }
.loan-people { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.person-loan { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid #eef1ee; border-radius: 9px; }
.person-loan span { overflow: hidden; color: #5e6e67; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.person-loan strong { color: var(--ink); font-size: 12px; white-space: nowrap; }

.report-panel { padding: 20px; background: #f0f6f0; }
.report-icon { display: grid; place-items: center; width: 39px; height: 39px; margin-bottom: 13px; border-radius: 12px; background: #dcecdf; color: var(--green); font-size: 20px; }
.report-panel h2 { max-width: 210px; font-size: 20px; }
.report-panel > p:not(.eyebrow):not(.share-status) { margin: 9px 0 16px; color: #708078; font-size: 12px; }
.report-panel .button { width: 100%; margin-top: 8px; }
.share-status { min-height: 16px; margin: 7px 0 0; color: #4f775b; font-size: 10px; }
.guide-panel { padding: 20px; }
.guide-panel h3 { margin: 0 0 15px; font-family: Georgia, serif; font-size: 19px; font-weight: 600; }
.guide-panel ol { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.guide-panel li { display: flex; align-items: flex-start; gap: 10px; }
.guide-panel li > span { display: grid; flex: 0 0 23px; place-items: center; width: 23px; height: 23px; border-radius: 8px; background: #edf4ee; color: var(--green); font-size: 10px; font-weight: 800; }
.guide-panel li b, .guide-panel li small { display: block; }
.guide-panel li b { font-size: 11px; }
.guide-panel li small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.privacy-note { display: flex; gap: 8px; margin-top: 18px; padding: 11px; border-radius: 9px; background: #f6f8f6; color: #78857f; font-size: 10px; }
.footer { padding: 0 20px 24px; color: #89948f; font-size: 10px; text-align: center; }
.footer span { color: #c28a4f; }
.toast { position: fixed; right: 24px; bottom: 20px; z-index: 3; max-width: min(360px, calc(100% - 32px)); padding: 11px 15px; border-radius: 10px; background: var(--green-dark); box-shadow: 0 8px 25px #183c3733; color: white; font-size: 12px; }
.auth-screen { display: grid; min-height: 100vh; place-items: center; padding: 24px 16px; background: radial-gradient(ellipse at top, #eaf3eb 0, var(--canvas) 55%); }
.auth-card { width: min(100%, 410px); padding: 30px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 18px 55px rgba(24,60,55,.1); }
.auth-brand { margin-bottom: 30px; color: var(--green-dark); }
.auth-brand .brand-mark { border-color: #dce7de; }
.auth-brand small { color: #7d8b84; }
.auth-card h1 { margin-bottom: 8px; font-size: 30px; }
.auth-intro { margin-bottom: 20px; color: var(--muted); font-size: 13px; }
#auth-form { display: grid; gap: 13px; }
#auth-form label { display: grid; gap: 6px; color: #5f7068; font-size: 11px; font-weight: 700; }
#auth-form input { width: 100%; height: 43px; padding: 9px 11px; border: 1px solid #dfe6e1; border-radius: 9px; color: var(--ink); font-size: 13px; }
#auth-form input:focus { border-color: #4d9870; outline: 0; box-shadow: 0 0 0 3px rgba(77,152,112,.13); }
.auth-submit { width: 100%; min-height: 43px; margin-top: 5px; font-size: 13px; }
.auth-submit:disabled { cursor: wait; opacity: .7; }
.auth-link { margin: 9px 0 0; padding: 4px 0; }
.auth-message { min-height: 18px; margin: 10px 0 0; color: #397250; font-size: 11px; }
.error-message { color: #a44839; }
.auth-switch { margin: 12px 0 0; color: var(--muted); font-size: 11px; text-align: center; }
.auth-switch button { padding: 0; border: 0; background: none; color: var(--green); font-size: inherit; font-weight: 800; }
.auth-privacy { margin: 21px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: #85918b; font-size: 10px; text-align: center; }
.setup-warning { margin-bottom: 16px; }
.hidden { display: none !important; }
.sr-only { position: absolute; overflow: hidden; width: 1px; height: 1px; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 1000px) {
  .work-area { grid-template-columns: minmax(0, 1fr) 250px; gap: 13px; }
  .entry-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .payment-field { align-self: end; }
  .form-submit { min-height: 38px; }
  .summary-card { padding: 15px; }
}

@media (max-width: 760px) {
  .page { width: min(100% - 30px, 600px); padding-top: 24px; }
  .topbar { min-height: 64px; padding: 10px 15px; }
  .welcome { align-items: flex-start; flex-direction: column; }
  .week-picker { width: 100%; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .summary-card { min-height: 120px; padding: 14px; }
  .summary-card > strong { font-size: 22px; }
  .summary-icon { top: 12px; right: 12px; width: 27px; height: 27px; }
  .work-area { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .day-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 12px; }
  .panel { padding: 17px; }
}

@media (max-width: 480px) {
  .topbar-note { font-size: 10px; }
  .account-tools { gap: 7px; font-size: 10px; }
  .account-tools > span { max-width: 150px; }
  .sign-out-button { padding: 5px 7px; font-size: 10px; }
  .welcome-copy { max-width: 340px; font-size: 13px; }
  .summary-card { min-height: 113px; padding: 12px; }
  .summary-label { max-width: 145px; font-size: 11px; }
  .summary-card > strong { font-size: 19px; }
  .summary-card > small { font-size: 10px; }
  .panel { padding: 14px; border-radius: 12px; }
  .panel-heading { align-items: flex-start; }
  .panel-heading h2 { font-size: 19px; }
  .date-label input { max-width: 142px; }
  .day-tab { padding: 9px 7px; font-size: 10px; }
  .entry-form { grid-template-columns: 1fr 1fr; gap: 9px; }
  .entry-form label:first-child { grid-column: span 2; }
  .entry-form .payment-field { grid-column: span 1; }
  .entry-form .form-submit { grid-column: span 1; }
  .side-column { grid-template-columns: 1fr; }
  .weekly-chart { gap: 4px; }
  .chart-value { font-size: 9px; }
  .chart-label { font-size: 9px; }
  .loan-people { grid-template-columns: 1fr; }
  th, td { padding-right: 6px; padding-left: 6px; }
}

@media print {
  @page { margin: 14mm; }
  body { background: white; color: #172620; font-size: 10pt; }
  .topbar { min-height: auto; padding: 0 0 12px; border-bottom: 2px solid #245b4e; background: white; color: #183c37; }
  .topbar-note, .account-tools, .week-controls button, .text-button, .date-label, .day-tabs, .entry-form, .remove-button, .report-panel, .guide-panel, .footer, .toast, .chart-key, .auth-screen { display: none !important; }
  .page { width: 100%; max-width: none; padding: 12px 0 0; }
  .welcome { margin-bottom: 14px; }
  .welcome h1 { font-size: 23pt; }
  .welcome-copy { font-size: 10pt; }
  .week-picker { min-width: 0; padding: 0; border: 0; box-shadow: none; }
  .week-picker .eyebrow { text-align: right; }
  .week-controls { justify-content: flex-end; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 12px; }
  .summary-card { min-height: 0; padding: 9px; border-radius: 7px; box-shadow: none; }
  .summary-card > strong { font-size: 16pt; }
  .summary-icon { display: none; }
  .summary-card > small { font-size: 8pt; }
  .work-area { display: block; }
  .main-column { display: block; }
  .panel { margin-bottom: 12px; padding: 12px; border-radius: 7px; box-shadow: none; break-inside: avoid; }
  .panel-heading h2 { font-size: 16pt; }
  .day-stats { margin: 10px 0; padding: 8px; }
  .tab-content.hidden { display: block !important; }
  .tab-content { padding-top: 8px; }
  .tab-content:before { display: block; margin: 8px 0 4px; color: #245b4e; font-size: 11pt; font-weight: bold; }
  #tab-cuts:before { content: "Cuts"; }
  #tab-expenses:before { content: "Expenses"; }
  #tab-loans:before { content: "Customer loans"; }
  #tab-expenses table, #tab-loans table { margin-top: 6px; }
  .table-wrap { overflow: visible; }
  th, td { padding: 5px 7px; font-size: 8pt; }
  .empty-state { font-size: 8pt; }
  .weekly-chart { min-height: 145px; }
  .chart-day { height: 135px; }
  .chart-track { height: 85px; }
  .chart-footnote { font-size: 8pt; }
  .loan-people { grid-template-columns: repeat(3, 1fr); }
  .person-loan { padding: 6px 8px; }
  .auth-card { padding: 24px 20px; }
}
