:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #eef6f5;
  --text: #17202a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --accent: #14b8a6;
  --warning: #f59e0b;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 18px;
  align-items: center;
  padding: 16px clamp(16px, 4vw, 48px);
  background: rgba(247, 248, 250, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand span {
  font-size: 20px;
  font-weight: 800;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.topbar__nav {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: #eef1f5;
  border-radius: 8px;
}

.topbar__nav a {
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 6px;
  color: #4b5563;
  font-size: 14px;
  font-weight: 700;
}

.topbar__nav a:hover {
  background: var(--surface);
}

main {
  display: grid;
  gap: 22px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 22px;
  align-items: stretch;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 24px;
  align-items: center;
  padding: clamp(24px, 4vw, 42px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero h1 {
  max-width: 700px;
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.04;
  letter-spacing: 0;
}

.hero p {
  max-width: 620px;
  color: var(--muted);
  font-size: 17px;
}

.hero__actions,
.settings__actions,
.drawer__actions,
.subscription-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.hero__snapshot {
  display: grid;
  gap: 8px;
  min-height: 190px;
  padding: 22px;
  align-content: center;
  background: #0f172a;
  color: #ffffff;
  border-radius: 8px;
}

.hero__snapshot span,
.hero__snapshot small {
  color: #cbd5e1;
}

.hero__snapshot strong {
  overflow-wrap: anywhere;
  font-size: 34px;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.button,
.icon-button,
.text-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.button {
  min-height: 42px;
  padding: 10px 15px;
}

.button--small {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 13px;
}

.button--primary {
  background: var(--primary);
  color: #ffffff;
}

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

.button--secondary {
  background: #eef1f5;
  color: #243040;
}

.button--danger {
  background: #fee2e2;
  color: var(--danger);
}

.text-button {
  min-height: 32px;
  padding: 6px 8px;
  background: transparent;
  color: var(--primary);
}

.text-button:hover {
  background: #eff6ff;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.metric-card,
.panel,
.subscription-card,
.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

.metric-card span,
.metric-card small,
.subscription-card span,
.subscription-card small,
.upcoming-item span,
.insight-card span,
.insight-card p,
.insight-line span,
.settings p {
  color: var(--muted);
}

.metric-card strong {
  overflow-wrap: anywhere;
  font-size: 26px;
  line-height: 1.14;
}

.panel {
  padding: 22px;
}

.quick-add {
  min-height: 100%;
}

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

.section-heading h2 {
  margin: 0;
  font-size: 22px;
}

.section-heading--stack {
  align-items: center;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field span,
.controls span {
  color: #374151;
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea,
.controls select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  color: var(--text);
}

.field textarea {
  resize: vertical;
}

.field em {
  color: var(--danger);
  font-size: 13px;
  font-style: normal;
}

.field--hidden {
  display: none;
}

.field--search input {
  min-height: 48px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.preset-card {
  display: grid;
  gap: 4px;
  min-height: 76px;
  padding: 14px;
  text-align: left;
  background: #fbfcfe;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.preset-card:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.12);
}

.preset-card strong {
  overflow-wrap: anywhere;
}

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

.panel--upcoming,
.panel--category {
  margin-top: 16px;
}

.upcoming-list,
.subscription-list,
.insight-list {
  display: grid;
  gap: 10px;
}

.upcoming-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.upcoming-item:last-child {
  border-bottom: 0;
}

.upcoming-item div {
  display: grid;
  gap: 3px;
}

.upcoming-item__meta {
  text-align: right;
}

.category-bars {
  display: grid;
  gap: 14px;
}

.category-row {
  display: grid;
  gap: 6px;
}

.category-row__label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.bar {
  height: 10px;
  overflow: hidden;
  background: #edf2f7;
  border-radius: 999px;
}

.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.controls label {
  display: grid;
  gap: 4px;
  min-width: 160px;
}

.subscription-section {
  scroll-margin-top: 90px;
}

.subscription-card {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.subscription-card__main,
.subscription-card__meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.subscription-card__main > div,
.subscription-card__meta > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.subscription-card strong {
  overflow-wrap: anywhere;
}

.subscription-card__meta {
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
}

.status {
  flex: 0 0 auto;
  align-self: start;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.status--active {
  background: #dcfce7;
  color: #166534;
}

.status--watching {
  background: #fef3c7;
  color: #92400e;
}

.status--cancel-planned {
  background: #dbeafe;
  color: #1e40af;
}

.status--cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.insights {
  scroll-margin-top: 90px;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.insight-card {
  min-height: 140px;
  padding: 18px;
}

.insight-card strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 24px;
}

.insight-line {
  display: grid;
  gap: 4px;
  padding: 14px;
  background: var(--surface-soft);
  border-radius: 8px;
}

.settings {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.empty-text,
.empty-state {
  color: var(--muted);
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 24px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.42);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(480px, 100%);
  height: 100vh;
  padding: 24px;
  overflow-y: auto;
  background: var(--surface);
  box-shadow: -16px 0 50px rgba(15, 23, 42, 0.18);
}

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

.drawer__header h2 {
  margin: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  background: #eef1f5;
  color: #243040;
  font-size: 24px;
  line-height: 1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.checkbox-field {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 12px 0 20px;
  color: #374151;
  font-weight: 700;
}

.drawer__actions {
  justify-content: flex-end;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 36px));
  padding: 13px 16px;
  background: #111827;
  color: #ffffff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-weight: 800;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topbar__nav {
    display: none;
  }

  .dashboard-grid,
  .hero,
  .metrics,
  .insight-grid {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  main {
    width: min(100% - 24px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    padding: 12px;
  }

  .brand span {
    font-size: 18px;
  }

  .topbar > .button {
    min-height: 38px;
    padding: 8px 10px;
  }

  .hero,
  .panel {
    padding: 18px;
  }

  .hero h1 {
    font-size: 36px;
  }

  .hero__snapshot {
    min-height: 150px;
  }

  .metrics,
  .preset-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .section-heading--stack,
  .subscription-card__main,
  .subscription-card__meta,
  .upcoming-item,
  .settings {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    justify-content: stretch;
  }

  .controls label,
  .controls select {
    min-width: 100%;
  }

  .upcoming-item__meta {
    text-align: left;
  }

  .drawer {
    padding: 18px;
  }
}
