:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --text: #1f2428;
  --muted: #697077;
  --border: #e2e5e9;
  --accent: #2f5d50;
  --accent-dark: #24483f;
  --danger: #a13a3a;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

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

button, input { font: inherit; }
button { cursor: pointer; }

.page-shell {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 28px;
}

.topbar,
.section-heading,
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar { margin-bottom: 28px; }

h1, h2, p { margin: 0; }

h1 {
  font-size: clamp(1.75rem, 4vw, 2.4rem);
  letter-spacing: -0.035em;
}

h2 {
  font-size: 1.12rem;
  letter-spacing: -0.015em;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-badge {
  padding: 7px 10px;
  border: 1px solid #cbd9d4;
  border-radius: 999px;
  background: #edf4f1;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
}

.summary-card,
.admin-panel,
.expenses-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.summary-card {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px;
}

.summary-label,
.meta-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-total {
  margin-top: 5px;
  font-size: clamp(2.35rem, 7vw, 4.3rem);
  font-weight: 760;
  letter-spacing: -0.06em;
}

.summary-meta {
  display: flex;
  gap: 30px;
}

.summary-meta > div {
  display: grid;
  gap: 5px;
}

.summary-meta strong { font-size: 0.95rem; }

.admin-panel,
.expenses-section {
  margin-top: 18px;
  padding: 24px;
}

.expense-form {
  display: grid;
  grid-template-columns: 1.35fr 1.2fr 1.2fr 2fr auto;
  gap: 14px;
  margin-top: 18px;
  align-items: end;
}

.period-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  grid-column: 1 / -1;
}

.period-fieldset legend,
label > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 650;
}

.period-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfb;
  color: var(--text);
  cursor: pointer;
}

.radio-option input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.radio-option span {
  margin: 0;
  color: inherit;
  font-size: 0.9rem;
}

.field-group {
  min-width: 0;
}

.date-range-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-width: 0;
  grid-column: span 2;
}

label {
  display: grid;
  gap: 0;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 650;
  min-width: 0;
}

input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #d4d8dd;
  border-radius: 10px;
  outline: none;
  background: white;
  color: var(--text);
  font-size: 16px;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 93, 80, 0.12);
}

.button {
  min-height: 44px;
  padding: 10px 15px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 700;
}

.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.button-primary {
  background: var(--accent);
  color: white;
}

.button-primary:hover:not(:disabled) { background: var(--accent-dark); }

.button-secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.button-secondary:hover:not(:disabled) { background: #f1f3f4; }

.text-button,
.icon-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.text-button { padding: 8px 0; }

.icon-button {
  width: 40px;
  height: 40px;
  font-size: 1.5rem;
  line-height: 1;
}

.status-message {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.83rem;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td { font-size: 0.93rem; }
td.amount-cell { font-weight: 750; white-space: nowrap; }
td.remark-cell { word-break: break-word; }
.actions-cell { white-space: nowrap; }

.period-text {
  font-weight: 650;
}

.period-subtext {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.77rem;
}

.action-button {
  min-height: 36px;
  margin-left: 6px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.action-button.delete { color: var(--danger); }

.empty-state {
  margin-top: 14px;
  padding: 22px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
}

.error-state { color: var(--danger); }

.mobile-list {
  display: none;
  margin-top: 12px;
}

.mobile-expense {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.mobile-expense-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.mobile-expense-amount { font-weight: 800; }

.mobile-expense-period {
  font-weight: 650;
}

.mobile-expense-remark {
  margin-top: 7px;
  color: var(--text);
}

.mobile-expense-actions { margin-top: 10px; }

.login-dialog {
  width: min(430px, calc(100% - 28px));
  border: 0;
  border-radius: 16px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18);
}

.login-dialog::backdrop { background: rgba(20, 24, 27, 0.45); }

.login-card {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.full-width { width: 100%; }

footer {
  padding: 24px 2px 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.hidden { display: none !important; }

@media (max-width: 820px) {
  .expense-form {
    grid-template-columns: 1fr 1fr;
  }

  .period-fieldset,
  .remark-field {
    grid-column: 1 / -1;
  }

  .date-range-grid {
    grid-column: 1 / -1;
  }

  #saveExpenseButton {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 22px, 980px);
    padding-top: 24px;
  }

  .topbar { align-items: flex-start; }

  .summary-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-meta {
    width: 100%;
    justify-content: space-between;
    gap: 16px;
  }

  #desktopTableWrap { display: none !important; }

  #mobileExpenseList:not(.hidden) { display: block; }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

@media (max-width: 520px) {
  .expense-form,
  .date-range-grid {
    grid-template-columns: 1fr;
  }

  .period-fieldset,
  .remark-field,
  .date-range-grid,
  #saveExpenseButton {
    grid-column: 1;
  }

  .topbar { flex-direction: column; }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .summary-card,
  .admin-panel,
  .expenses-section {
    padding: 19px;
  }
}
