:root {
  --cream: #fff8dc;
  --surface: #f4f6f2;
  --panel: #ffffff;
  --ink: #222222;
  --muted: #6a6a62;
  --orange: #ff950d;
  --yellow: #ffe85b;
  --teal: #358b7d;
  --danger: #c84646;
  --line: #e7e1c8;
  --shadow: 0 18px 45px rgba(62, 53, 21, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at 88% 46%, rgba(255, 232, 91, .42) 0 26rem, transparent 26.1rem), var(--surface);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; min-width: 0; }
img { max-width: 100%; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 280px;
  background: var(--cream);
  border-right: 1px solid rgba(255, 149, 13, .16);
  z-index: 30;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.sidebar-brand img { width: 66px; height: 66px; object-fit: contain; flex: 0 0 auto; }
.sidebar-brand strong { font-size: 17px; line-height: 1.2; letter-spacing: .02em; text-transform: uppercase; overflow-wrap: anywhere; }
.side-nav { display: grid; gap: 10px; }
.side-nav a, .side-nav button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf1;
  color: var(--teal);
  padding: 14px 16px;
  font-weight: 900;
  text-align: left;
  cursor: pointer;
}
.side-nav a:hover, .side-nav button:hover { background: #fff6c7; }
.side-nav form { margin: 0; }
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }
.menu-button {
  width: 46px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf1;
  display: grid;
  place-content: center;
  gap: 4px;
  cursor: pointer;
}
.menu-button span { display: block; width: 24px; height: 3px; background: var(--orange); }
.mobile-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mobile-brand img { width: 46px; height: 46px; object-fit: contain; }
.mobile-brand strong { font-size: 14px; line-height: 1.2; text-transform: uppercase; overflow-wrap: anywhere; }

.app-shell { max-width: 1220px; margin: 0 auto; padding: 42px clamp(16px, 3vw, 28px) 72px; margin-left: 280px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 24px; }
.page-heading h1 { margin: 4px 0 0; font-size: clamp(34px, 5vw, 56px); font-weight: 800; }
.eyebrow { margin: 0; color: var(--orange); font-family: Georgia, serif; font-size: 28px; }
.muted { color: var(--muted); line-height: 1.65; }
.back-link { color: var(--teal); font-weight: 800; }

.primary-button, .ghost-button, .danger-button, .link-button {
  border: 0;
  border-radius: 999px;
  padding: 13px 22px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
  white-space: nowrap;
}
.primary-button { background: var(--yellow); color: #5c5200; box-shadow: 0 10px 20px rgba(255, 204, 0, .22); }
.ghost-button { background: #fffdf1; color: var(--teal); border: 1px solid var(--line); }
.danger-button { background: #fff0ef; color: var(--danger); padding: 9px 14px; }
.link-button { background: #eef8f5; color: var(--teal); padding: 9px 14px; }
.primary-button:hover, .ghost-button:hover, .danger-button:hover, .link-button:hover { transform: translateY(-1px); }

.toolbar, .table-panel, .stat-card, .login-card {
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.toolbar { padding: 16px; border-radius: 8px; margin-bottom: 22px; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  background: #fffdf6;
  color: var(--ink);
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--orange); box-shadow: 0 0 0 4px rgba(255, 149, 13, .12); }
.filters input { min-width: min(340px, 100%); flex: 1; }
.filters select { width: 190px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { border-radius: 8px; padding: 22px; }
.stat-card span { color: var(--muted); display: block; margin-bottom: 8px; }
.stat-card strong { font-size: 38px; }
.payment-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.payment-summary .stat-card strong { font-size: clamp(24px, 3vw, 34px); }
.payment-table { margin-bottom: 24px; }
.progress-hero {
  background: rgba(255, 255, 255, .86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(22px, 4vw, 38px);
  margin-bottom: 24px;
}
.progress-hero div:first-child { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.progress-hero span { color: var(--muted); font-weight: 900; }
.progress-hero strong { font-size: clamp(48px, 8vw, 86px); line-height: .9; color: var(--teal); }
.diary-page {
  background: repeating-linear-gradient(#fffdf5 0 31px, #d9ecff 32px), #fffdf5;
  border: 1px solid #eadfbf;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(24px, 4vw, 44px);
  min-height: 420px;
  position: relative;
}
.diary-page::before { content: ""; position: absolute; top: 0; bottom: 0; left: 58px; width: 2px; background: rgba(200, 70, 70, .22); }
.diary-header { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 28px; position: relative; }
.diary-header span { color: var(--muted); font-weight: 800; }
.diary-lines { line-height: 32px; font-family: Georgia, serif; font-size: 20px; position: relative; padding-left: 52px; }

.table-panel { border-radius: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 17px 18px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #fffbea; color: #6c6100; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
td small { display: block; margin-top: 5px; color: var(--muted); }
.row-title { font-weight: 900; color: var(--teal); }
.status-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 11px; background: #fff4b6; color: #675b00; font-size: 12px; font-weight: 900; }
.today-pill { display: inline-flex; align-items: center; margin-left: 8px; border-radius: 999px; padding: 5px 10px; background: #ffe6e3; color: #b42318; font-size: 12px; font-weight: 900; }
.progress-meter { width: 160px; max-width: 100%; height: 10px; border-radius: 999px; background: #efe9d0; overflow: hidden; }
.progress-meter span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--orange), var(--teal)); }
.progress-meter.large { width: 100%; height: 18px; margin: 14px 0; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions { flex-wrap: wrap; }
.actions form { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 34px; }
.alert { border-radius: 8px; padding: 14px 16px; margin-bottom: 18px; font-weight: 700; }
.alert-error { background: #fff0ef; color: #9a2f2f; border: 1px solid #ffd1ce; }
.alert-success { background: #edf9f5; color: #196c60; border: 1px solid #c4eee3; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 10% 90%, rgba(255, 232, 91, .55), transparent 32rem), var(--surface); }
.auth-shell { width: min(1020px, 100%); }
.login-card { display: grid; grid-template-columns: .9fr 1.1fr; border-radius: 8px; overflow: hidden; min-height: 560px; }
.login-art { background: var(--cream); display: grid; place-items: center; position: relative; overflow: hidden; }
.login-art img { width: min(320px, 70%); position: relative; z-index: 1; }
.sun-ring { position: absolute; width: 180px; height: 180px; border: 8px solid var(--orange); border-radius: 50%; top: 42px; right: 36px; }
.login-panel { padding: clamp(28px, 5vw, 58px); align-self: center; }
.login-panel h1 { font-size: clamp(32px, 5vw, 54px); margin: 8px 0 12px; line-height: 1.05; }
.form-stack { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 7px; font-weight: 800; color: #333; }

.modal { position: fixed; inset: 0; z-index: 50; display: none; }
.modal.is-open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(22, 22, 18, .45); }
.modal-panel {
  position: relative;
  width: min(620px, calc(100% - 28px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  margin: 20px auto;
  background: var(--panel);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, .24);
}
.modal-panel.wide { width: min(900px, calc(100% - 28px)); }
.modal-panel h2 { margin-top: 0; }
.modal-close { position: absolute; top: 14px; right: 14px; border: 0; background: var(--teal); color: white; border-radius: 50%; width: 34px; height: 34px; cursor: pointer; font-weight: 900; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.checkbox-panel { border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 10px; }
.checkbox-panel legend { font-weight: 900; padding: 0 8px; }
.check-row { display: flex; align-items: center; gap: 10px; font-weight: 800; }
.check-row input { width: auto; accent-color: var(--teal); }
.payment-panel { border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 12px; }
.payment-panel legend { font-weight: 900; padding: 0 8px; }
.payment-row {
  display: grid;
  grid-template-columns: minmax(120px, .8fr) minmax(180px, 1fr) minmax(220px, 1.4fr) auto;
  gap: 10px;
  align-items: end;
  width: 100%;
}
.payment-row label { min-width: 0; }
.payment-row .danger-button { align-self: end; }

@media (max-width: 920px) {
  .payment-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .payment-statement { grid-column: span 2; }
  .payment-row .danger-button { width: fit-content; }
}

@media (max-width: 760px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    width: min(290px, 84vw);
  }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    border: 0;
    background: rgba(28, 22, 12, .45);
    display: none;
  }
  .sidebar-open .sidebar-backdrop { display: block; }
  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 72px;
    padding: 10px 14px;
    background: var(--cream);
    border-bottom: 1px solid rgba(255, 149, 13, .16);
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .app-shell { padding-top: 24px; margin-left: 0; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .stat-grid, .payment-summary, .login-card, .form-grid, .payment-row { grid-template-columns: 1fr; }
  .payment-statement { grid-column: auto; }
  .span-2 { grid-column: span 1; }
  .filters select, .filters button { width: 100%; }
  .modal-panel, .modal-panel.wide {
    width: 100%;
    min-height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    padding: 22px 16px;
  }
  .modal-close { top: 10px; right: 10px; }
  .diary-page::before { left: 28px; }
  .diary-lines { padding-left: 24px; font-size: 18px; }
  .progress-hero div:first-child { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 460px) {
  .page-heading h1 { font-size: 34px; }
  .eyebrow { font-size: 24px; }
  th, td { padding: 14px 12px; }
  table { min-width: 680px; }
}

@supports not (height: 100dvh) {
  @media (max-width: 760px) {
    .modal-panel, .modal-panel.wide {
      min-height: 100vh;
      max-height: 100vh;
    }
  }
}
