:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-2: #199e70;
  --danger: #e66767;

  --cat-1: #3987e5;
  --cat-2: #d95926;
  --cat-3: #199e70;
  --cat-4: #c98500;
  --cat-5: #d55181;
  --cat-6: #008300;
  --cat-7: #9085e9;
  --cat-8: #e66767;

  --radius: 14px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.4;
}

a {
  color: inherit;
}

button {
  font: inherit;
}

/* ---------- Auth page ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #14171f 0%, var(--page) 60%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.auth-logo {
  font-size: 40px;
  margin-bottom: 8px;
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0 0 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.auth-form label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
}

.auth-form button {
  margin-top: 20px;
}

/* ---------- Form controls ---------- */

input[type="text"],
input[type="password"],
input[type="date"],
select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.btn-primary:hover {
  background: #4f97ea;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  margin: 0 0 16px;
}

.alert-error {
  background: rgba(230, 103, 103, 0.15);
  color: #f3a6a6;
  border: 1px solid rgba(230, 103, 103, 0.35);
}

/* ---------- App shell ---------- */

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-logo {
  font-size: 26px;
}

.topbar-title h1 {
  font-size: 20px;
  margin: 0;
}

.topbar-greeting {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

/* ---------- Tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tile-label {
  font-size: 13px;
  color: var(--text-muted);
}

.tile-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Panels ---------- */

.panels {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.panel h2 {
  font-size: 15px;
  margin: 0 0 16px;
  color: var(--text-secondary);
}

.empty-hint {
  color: var(--text-muted);
  font-size: 14px;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

/* ---------- Subscription list ---------- */

.sub-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sub-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--gridline);
}

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

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

.sub-name {
  font-weight: 600;
  font-size: 15px;
}

.sub-meta {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub-side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sub-price {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 80px;
  text-align: right;
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.delete-form {
  margin: 0;
  display: inline-flex;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  margin: 0 0 18px;
  font-size: 18px;
}

.modal form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* ---------- Responsive ---------- */

@media (max-width: 760px) {
  .tiles {
    grid-template-columns: 1fr;
  }

  .panels {
    grid-template-columns: 1fr;
  }

  .sub-item {
    flex-wrap: wrap;
  }
}
