:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --primary: #2f6fed;
  --primary-dark: #1f55c7;
  --success: #0d9c75;
  --warning: #f0b429;
  --text: #1f2937;
  --muted: #64748b;
  --border: #dfe7f3;
  --shadow: 0 12px 30px rgba(17, 24, 39, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(180deg, #edf5ff 0%, var(--bg) 42%, #f8fafc 100%);
  color: var(--text);
  overflow-x: hidden;
}

body {
  display: flex;
  justify-content: center;
  padding: 0 0 88px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  position: relative;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2.3vw, 2rem);
}

.app-main {
  padding: 0 18px calc(100px + env(safe-area-inset-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.03);
}

.summary-card,
.panel-card,
.metric-card,
.form-card {
  padding: 16px;
}

.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.summary-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.date-picker-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.date-picker-wrap input,
.field-row input,
.field-row select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: var(--surface-soft);
  color: var(--text);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.customer-row,
.history-item,
.monthly-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}

.customer-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.customer-main strong,
.history-item strong,
.monthly-row strong {
  font-size: 1rem;
}

.customer-main span,
.history-item span,
.monthly-row span,
.metric-card .label {
  color: var(--muted);
}

.customer-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(47, 111, 237, 0.12);
  color: var(--primary-dark);
}

.badge.inactive {
  background: rgba(100, 116, 139, 0.12);
  color: var(--muted);
}

.customer-amount {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 110px;
}

.primary-button,
.ghost-button {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  transition: all 0.2s ease;
  min-height: 44px;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
}

.ghost-button.secondary {
  background: transparent;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 98px;
  justify-content: center;
}

.metric-card strong {
  font-size: clamp(1.2rem, 3vw, 1.6rem);
}

.metric-card.accent {
  background: linear-gradient(140deg, rgba(47, 111, 237, 0.08), rgba(13, 156, 117, 0.08));
}

.form-card.hidden {
  display: none;
}

.field-row {
  margin-top: 12px;
}

.month-navigator {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.year-list,
.month-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.year-button,
.month-button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 8px 10px;
  font-weight: 700;
}

.year-button.active,
.month-button.active {
  background: rgba(47, 111, 237, 0.12);
  border-color: rgba(47, 111, 237, 0.2);
  color: var(--primary-dark);
}

.month-button {
  min-width: 60px;
  flex: 1 1 24%;
}

.field-row label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.checkbox-field {
  justify-content: center;
  align-items: center;
}

.checkbox-field input {
  width: 20px;
  height: 20px;
}

.form-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 60px;
  padding: 12px 14px;
  cursor: pointer;
}

.check-main {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.check-main input {
  width: 24px;
  height: 24px;
  accent-color: var(--primary);
  flex: 0 0 24px;
}

.check-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.check-meta strong {
  color: var(--text);
}

.form-actions.compact {
  margin-top: 16px;
  justify-content: stretch;
}

.form-actions.compact .primary-button {
  width: 100%;
  min-height: 52px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.customer-actions,
.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.action-button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  padding: 7px 10px;
  font-size: 0.82rem;
}

.action-button.danger {
  color: #b42318;
  border-color: rgba(180, 35, 24, 0.2);
  background: rgba(180, 35, 24, 0.04);
}

.history-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  align-items: flex-start;
}

.history-item .meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item .amount {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 16px;
}

.startup-error {
  width: min(100% - 32px, 560px);
  margin: 24px auto;
  padding: 22px;
  border: 1px solid #efb4ad;
  border-radius: var(--radius);
  background: #fff7f6;
  color: #7a271a;
  overflow-wrap: anywhere;
}

.monthly-customer-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.monthly-row {
  padding: 4px 2px 10px;
  background: transparent;
  border: 0;
}

.calendar-weekdays,
.month-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-weekdays {
  margin-bottom: 4px;
  color: var(--muted);
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
}

.calendar-day {
  min-width: 0;
  aspect-ratio: 1 / 0.86;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 7px;
  font-size: 0.65rem;
  line-height: 1.15;
  color: var(--muted);
  background: #eef2f7;
}

.calendar-day.received {
  color: #087658;
  background: rgba(13, 156, 117, 0.12);
  font-weight: 700;
}

.calendar-day.not-received {
  color: #8a5a00;
  background: rgba(240, 180, 41, 0.15);
}

.calendar-day.unrecorded {
  color: #a0aab8;
  background: transparent;
}

.calendar-spacer {
  visibility: hidden;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 560px);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  z-index: 5;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 6px;
  border-radius: 12px;
  font-size: 0.78rem;
  min-width: 0;
  min-height: 44px;
  overflow-wrap: anywhere;
}

.nav-item.active {
  background: rgba(47, 111, 237, 0.1);
  color: var(--primary-dark);
}

@media (max-width: 440px) {
  .app-header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .app-main {
    padding-left: 12px;
    padding-right: 12px;
  }

  .summary-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .customer-row,
  .monthly-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .customer-amount,
  .history-item .amount {
    width: 100%;
    text-align: left;
  }

  .metric-card {
    min-height: 86px;
    padding: 12px;
  }

  .metric-card strong {
    font-size: 1.1rem;
    overflow-wrap: anywhere;
  }

  .bottom-nav {
    gap: 2px;
    padding-right: 4px;
    padding-left: 4px;
  }

  .nav-item {
    padding: 8px 2px;
    font-size: 0.66rem;
  }

  .calendar-weekdays,
  .month-calendar {
    gap: 2px;
  }

  .calendar-day {
    border-radius: 5px;
    font-size: 0.6rem;
  }
}
