:root {
  --bg: #06111f;
  --bg-deep: #030b15;
  --surface: rgba(13, 28, 46, 0.82);
  --surface-strong: rgba(16, 34, 55, 0.97);
  --surface-soft: rgba(21, 40, 62, 0.68);
  --border: rgba(144, 170, 203, 0.20);
  --border-strong: rgba(144, 170, 203, 0.34);
  --text: #f6f8fd;
  --muted: #9aa8c2;
  --muted-2: #6f7f9b;
  --blue: #2482ff;
  --blue-2: #0d55e8;
  --blue-soft: rgba(36, 130, 255, 0.13);
  --green: #2fd05a;
  --orange: #ff8a16;
  --purple: #b54cff;
  --red: #ff5b61;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #eef5ff;
  --bg-deep: #e4eefb;
  --surface: rgba(255, 255, 255, 0.91);
  --surface-strong: rgba(255, 255, 255, 0.99);
  --surface-soft: rgba(237, 245, 255, 0.96);
  --border: rgba(40, 76, 120, 0.14);
  --border-strong: rgba(40, 76, 120, 0.25);
  --text: #0d1b2e;
  --muted: #60728e;
  --muted-2: #8191a8;
  --blue-soft: rgba(36, 130, 255, 0.10);
  --shadow: 0 18px 45px rgba(43, 79, 122, 0.16);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { min-height: 100%; background: var(--bg-deep); }
body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 86% 18%, rgba(28, 111, 220, 0.16), transparent 34%),
    radial-gradient(circle at 10% 68%, rgba(0, 104, 214, 0.09), transparent 35%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  background-attachment: fixed;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button { color: inherit; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.mobile-shell {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 93%, transparent), var(--bg-deep));
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.22);
}
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--surface), color-mix(in srgb, var(--surface) 75%, transparent));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
:root[data-theme="light"] .panel { background: var(--surface); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: calc(72px + var(--safe-top));
  padding: calc(12px + var(--safe-top)) 18px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(22px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px;
  background: linear-gradient(145deg, #0a6cff, #0e49d8);
  box-shadow: 0 10px 24px rgba(0, 90, 255, 0.30);
  font-weight: 800; color: white;
}
.brand-copy strong { display: block; font-size: 19px; line-height: 1.05; }
.brand-copy span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.icon-button, .primary-button, .secondary-button, .danger-button, .ghost-button {
  border: 0; border-radius: 14px; cursor: pointer; transition: transform .15s ease, opacity .15s ease, border-color .15s ease;
}
.icon-button:active, .primary-button:active, .secondary-button:active, .danger-button:active, .ghost-button:active { transform: scale(.98); }
.icon-button {
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 1px solid var(--border-strong); background: var(--surface-soft);
}
.primary-button, .secondary-button, .danger-button, .ghost-button {
  min-height: 48px; padding: 12px 18px; font-weight: 700;
}
.primary-button { background: linear-gradient(145deg, var(--blue), var(--blue-2)); color: white; box-shadow: 0 12px 25px rgba(36, 130, 255, .25); }
.secondary-button { border: 1px solid rgba(36, 130, 255, .65); background: var(--blue-soft); color: var(--text); }
.danger-button { border: 1px solid rgba(255, 91, 97, .55); background: rgba(255, 91, 97, .12); }
.ghost-button { border: 1px solid var(--border); background: transparent; }
button[disabled] { opacity: .55; cursor: wait; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.button-row > * { flex: 1 1 160px; }

.page-main { padding: 24px 18px calc(108px + var(--safe-bottom)); }
.section { padding: 76px 0; }
.section-title { margin: 0 0 12px; font-size: clamp(28px, 5vw, 44px); letter-spacing: -1px; }
.section-subtitle { margin: 0; color: var(--muted); font-size: 18px; line-height: 1.6; }
.eyebrow { color: var(--blue); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 800; }

.field { display: grid; gap: 7px; }
.field label, .field-label { color: var(--muted); font-size: 14px; }
.input, .select, .textarea {
  width: 100%; min-width: 0; border: 1px solid var(--border-strong); border-radius: 14px;
  padding: 13px 14px; color: var(--text); background: var(--surface-soft); outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.textarea { min-height: 110px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.checkbox-row { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--blue); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { padding: 18px; }
.metric-label { color: var(--muted); font-size: 13px; }
.metric-value { margin-top: 7px; font-size: 30px; font-weight: 800; letter-spacing: -.6px; }
.metric-note { margin-top: 6px; color: var(--muted-2); font-size: 12px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--blue-soft); }
.table-action { border: 0; background: transparent; color: var(--blue); cursor: pointer; font-weight: 700; }

.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 6px 9px; font-size: 12px; font-weight: 700; }
.badge.active, .badge.done { background: rgba(47, 208, 90, .14); color: var(--green); }
.badge.suspended, .badge.review { background: rgba(255, 138, 22, .14); color: var(--orange); }
.badge.archived, .badge.requested { background: rgba(181, 76, 255, .14); color: var(--purple); }
.badge.working { background: rgba(36, 130, 255, .14); color: var(--blue); }
.badge.paused, .badge.expired { background: rgba(255, 91, 97, .14); color: var(--red); }

.progress { height: 14px; overflow: hidden; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue-2), var(--blue)); }

.empty-state { padding: 28px; text-align: center; color: var(--muted); }
.loading { padding: 50px 20px; text-align: center; color: var(--muted); }
.spinner { width: 30px; height: 30px; margin: 0 auto 14px; border: 3px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(100%, 440px); padding: 26px; }
.auth-card h1 { margin: 22px 0 8px; font-size: 34px; letter-spacing: -1px; }
.auth-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.5; }
.auth-form { display: grid; gap: 14px; }
.auth-logo { display: flex; align-items: center; gap: 12px; }
.auth-help { margin-top: 16px; color: var(--muted); font-size: 13px; text-align: center; }
.error-box { margin-bottom: 14px; padding: 12px 14px; border: 1px solid rgba(255,91,97,.4); border-radius: 13px; color: var(--red); background: rgba(255,91,97,.08); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px;
  background: rgba(1, 8, 16, .72); backdrop-filter: blur(10px);
}
.modal { width: min(100%, 760px); max-height: calc(100dvh - 36px); overflow-y: auto; padding: 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 25px; }
.modal-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 28px; }

.global-toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 200; max-width: min(90vw, 520px);
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  padding: 13px 17px; border: 1px solid var(--border-strong); border-radius: 14px;
  background: var(--surface-strong); color: var(--text); box-shadow: var(--shadow); transition: .22s ease;
}
.global-toast.show { transform: translate(-50%, 0); opacity: 1; }
.global-toast[data-type="error"] { border-color: rgba(255,91,97,.55); }
.global-toast[data-type="success"] { border-color: rgba(47,208,90,.55); }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .shell { width: min(100% - 22px, 1180px); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric-card { padding: 15px; }
  .metric-value { font-size: 26px; }
  .section { padding: 54px 0; }
}
