*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ede7dd;
  --surface: #f7f3ee;
  --border: #d4cdc4;
  --text: #1c1917;
  --text-muted: #7a7068;
  --accent: #1a7f5a;
  --accent-hover: #155f44;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warning-bg: #fef3c7;
  --warning-border: #f59e0b;
  --warning-text: #b45309;
  --radius: 6px;
  --shadow: 0 1px 4px rgba(28,25,23,0.09);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  padding: 32px 16px 64px;
}

header {
  max-width: 720px;
  margin: 0 auto 28px;
}

h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

main {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Summary ── */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-label {
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

/* Base size for Annual and Renewing Soon */
.summary-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

/* Monthly gets the most visual weight */
#total-monthly {
  font-size: 2.4rem;
}

/* Annual is secondary */
#total-annual {
  font-size: 1.9rem;
}

/* Renewing Soon: amber tint on the card when nonzero, neutral when zero */
#renewal-card.has-renewals {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

#renewal-card.has-renewals .summary-value {
  color: var(--warning-text);
}

/* ── Controls ── */
.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

fieldset {
  border: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

legend {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 8px;
}

.form-row label {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(26,127,90,0.15);
}

.form-error {
  font-size: 0.8rem;
  color: var(--danger);
  min-height: 1.2em;
}

.list-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.list-controls label {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

.list-controls select {
  width: auto;
  flex: 1;
}

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  align-self: flex-start;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  margin-left: auto;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

/* ── Subscription list ── */
.subscriptions {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#subscription-list {
  list-style: none;
}

.sub-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sub-item:last-child {
  border-bottom: none;
}

.sub-item.warning {
  background: var(--warning-bg);
  border-left: 3px solid var(--warning-border);
  padding-left: 17px;
}

.sub-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.sub-raw {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

.sub-monthly {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  white-space: nowrap;
}

.sub-renewal {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.sub-renewal.overdue {
  color: var(--danger);
  font-weight: 600;
}

.sub-renewal.soon {
  color: var(--warning-text);
  font-weight: 600;
}

.sub-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.1s, background 0.1s;
}

.delete-btn:hover {
  color: var(--danger);
  background: rgba(220,38,38,0.07);
}

/* ── Empty state ── */
.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p:first-child {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

/* ── Responsive ── */
@media (max-width: 520px) {
  .summary {
    grid-template-columns: 1fr 1fr;
  }

  #renewal-card {
    grid-column: span 2;
  }

  .sub-item {
    grid-template-columns: 1fr auto auto;
    grid-template-rows: auto auto;
  }

  .sub-monthly {
    grid-row: 1;
    grid-column: 2;
  }

  .sub-raw {
    grid-row: 2;
    grid-column: 2;
  }

  .sub-renewal {
    grid-row: 2;
    grid-column: 1;
    text-align: left;
  }

  .delete-btn {
    grid-row: 1 / 3;
    grid-column: 3;
    align-self: center;
  }
}
