:root {
  --bg: #f7f7f2;
  --ink: #17201b;
  --muted: #66736d;
  --panel: #ffffff;
  --line: #dce2dc;
  --accent: #146c5f;
  --accent-strong: #0f5248;
  --warn: #9b4d18;
  --error: #a13131;
  --success: #1f7a43;
  --cell: #fbfcfb;
  --calendar-hot: #f0faf6;
  --topbar: rgba(255, 255, 255, 0.92);
  --shadow: rgba(23, 32, 27, 0.05);
  --shadow-strong: rgba(23, 32, 27, 0.08);
  --tag-bg: rgba(20, 108, 95, 0.14);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #101412;
  --ink: #edf5ef;
  --muted: #9fb0a7;
  --panel: #171d1a;
  --line: #2b3832;
  --accent: #55c2a8;
  --accent-strong: #78dbc4;
  --warn: #e5a15d;
  --error: #ff8c8c;
  --success: #77d49b;
  --cell: #121815;
  --calendar-hot: #162a24;
  --topbar: rgba(23, 29, 26, 0.92);
  --shadow: rgba(0, 0, 0, 0.28);
  --shadow-strong: rgba(0, 0, 0, 0.38);
  --tag-bg: rgba(85, 194, 168, 0.16);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101412;
    --ink: #edf5ef;
    --muted: #9fb0a7;
    --panel: #171d1a;
    --line: #2b3832;
    --accent: #55c2a8;
    --accent-strong: #78dbc4;
    --warn: #e5a15d;
    --error: #ff8c8c;
    --success: #77d49b;
    --cell: #121815;
    --calendar-hot: #162a24;
    --topbar: rgba(23, 29, 26, 0.92);
    --shadow: rgba(0, 0, 0, 0.28);
    --shadow-strong: rgba(0, 0, 0, 0.38);
    --tag-bg: rgba(85, 194, 168, 0.16);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.nav-form {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
}

.nav-form form {
  margin: 0;
}

.ghost-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.theme-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--cell);
  color: var(--ink);
}

.ghost-button:hover,
.theme-button:hover {
  border-color: var(--accent);
  background: var(--tag-bg);
  color: var(--ink);
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 62px);
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px var(--shadow-strong);
}

.auth-card h1,
.hero-line h1,
.section-title h2 {
  margin: 0;
}

.auth-card h1 {
  font-size: 28px;
}

.muted,
.section-title p,
.hero-line p {
  color: var(--muted);
}

.dashboard-shell {
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: 28px 24px 56px;
}

.hero-line {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.hero-line h1 {
  font-size: 34px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px var(--shadow);
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 126px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  font-size: 26px;
}

.month-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.month-summary article {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
}

.month-summary span,
.month-summary small {
  color: var(--muted);
}

.month-summary strong {
  font-size: 18px;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  padding: 18px;
}

.wide-panel {
  margin-bottom: 18px;
}

.section-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title h2 {
  font-size: 19px;
}

.section-title p {
  margin: 4px 0 0;
}

.month-nav {
  display: flex;
  gap: 8px;
}

.month-nav a {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekdays {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.calendar-grid {
  gap: 8px;
  min-width: 820px;
}

.calendar-scroll {
  overflow-x: auto;
  padding-bottom: 2px;
}

.calendar-cell {
  min-height: 142px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
  overflow: hidden;
}

.calendar-cell small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-cell.has-money {
  border-color: rgba(20, 108, 95, 0.42);
  background: var(--calendar-hot);
}

.muted-cell {
  background: transparent;
}

.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.day-head span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.day-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
}

.day-tags b {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--accent);
  font-size: 11px;
}

.day-tags .paid-tag,
.paid-item {
  color: var(--success);
}

.pending-item {
  color: var(--ink);
}

.stack-form {
  display: grid;
  gap: 12px;
}

.stack-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.payment-list {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 4px;
}

.upcoming-panel {
  align-self: start;
}

.payment-row {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
}

.payment-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

.pay-form {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 150px 92px;
  gap: 8px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.empty {
  margin: 0;
  color: var(--muted);
}

.alert {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(161, 49, 49, 0.25);
  border-radius: 8px;
  background: rgba(161, 49, 49, 0.08);
  color: var(--error);
  font-weight: 700;
}

.alert.success {
  border-color: rgba(31, 122, 67, 0.26);
  background: rgba(31, 122, 67, 0.08);
  color: var(--success);
}

.history-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  gap: 18px;
  margin-bottom: 18px;
}

.history-table {
  max-height: 420px;
  overflow: auto;
}

.timeline {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.timeline article {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
}

.timeline span {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .metrics-grid,
  .month-summary,
  .history-grid,
  .work-grid {
    grid-template-columns: 1fr 1fr;
  }

  .wide-panel {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 0 16px;
  }

  .nav-form {
    gap: 8px;
  }

  .theme-button,
  .ghost-button {
    padding: 0 10px;
  }

  .dashboard-shell {
    padding: 22px 14px 40px;
  }

  .metrics-grid,
  .month-summary,
  .history-grid,
  .work-grid {
    grid-template-columns: 1fr;
  }

  .calendar-grid,
  .weekdays {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    min-width: 820px;
  }

  .weekdays {
    display: grid;
  }

  .calendar-cell {
    min-height: 124px;
  }

  .pay-form {
    grid-template-columns: 1fr;
  }

  .nav-form span {
    display: none;
  }
}
