:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --text: #172033;
  --muted: #667085;
  --border: #dfe4ec;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --success: #067647;
  --success-bg: #dcfae6;
  --warning: #b54708;
  --warning-bg: #fef0c7;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --neutral-bg: #eef2f6;
  --shadow: 0 18px 50px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
a { color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
button { touch-action: manipulation; }

.shell {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 0 max(40px, env(safe-area-inset-bottom));
}

.masthead, .card-heading, .dialog-heading, .status-line, .card-actions,
.bulk-actions, .dialog-actions, .overview-actions {
  display: flex;
  align-items: center;
}

.masthead { justify-content: space-between; margin-bottom: 28px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.7rem, 4vw, 2.25rem); letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: 1.2rem; letter-spacing: -0.02em; }
.eyebrow { margin-bottom: 5px; color: var(--accent); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.14em; }
.muted { color: var(--muted); }

.login-panel, .overview, .alert-card, .bulk-actions {
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-panel {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 400px);
  gap: 40px;
  padding: clamp(24px, 5vw, 48px);
  border-radius: 24px;
}

.login-form, #alert-form { display: grid; gap: 12px; }
label { color: var(--text); font-size: 0.86rem; font-weight: 700; }
input, select {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-solid);
  color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }

.button, .icon-button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 750;
}
.button { min-height: 44px; padding: 10px 16px; }
.button.primary { background: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-strong); }
.button.secondary { background: var(--neutral-bg); color: var(--text); }
.button.warning { background: var(--warning-bg); color: var(--warning); }
.button.success { background: var(--success-bg); color: var(--success); }
.button.danger { background: var(--danger-bg); color: var(--danger); }
.button.subtle { background: transparent; color: var(--muted); }
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; white-space: nowrap; }
.button:disabled { cursor: not-allowed; opacity: 0.5; }

.overview {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(22px, 4vw, 36px);
  border-radius: 24px;
}
.status-line { flex-wrap: wrap; gap: 8px; margin-bottom: 26px; }
.instrument { margin-bottom: 6px; color: var(--muted); font-weight: 700; }
.price { margin-bottom: 6px; font-size: clamp(2.6rem, 8vw, 5rem); font-weight: 800; letter-spacing: -0.06em; line-height: 1; }
.price small { font-size: 0.25em; letter-spacing: 0.02em; }
.overview-actions { align-items: flex-end; flex-direction: column; justify-content: space-between; }
.overview-actions p { margin-bottom: 0; font-size: 0.82rem; text-align: right; }

.pill { display: inline-flex; padding: 6px 10px; border-radius: 999px; font-size: 0.76rem; font-weight: 800; }
.pill.success { background: var(--success-bg); color: var(--success); }
.pill.warning { background: var(--warning-bg); color: var(--warning); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill.neutral { background: var(--neutral-bg); color: var(--muted); }

.alert-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-top: 20px; }
.alert-card { padding: 24px; border-radius: 20px; }
.card-heading { justify-content: space-between; gap: 12px; }
.alert-card dl { margin: 28px 0; }
.alert-card dl div { display: flex; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.alert-card dt { color: var(--muted); }
.alert-card dd { margin: 0; font-weight: 750; text-align: right; }
.card-actions { gap: 10px; }
.card-actions .button { flex: 1; }
.bulk-actions { justify-content: flex-end; gap: 10px; margin-top: 20px; padding: 16px; border-radius: 18px; }

.tabs { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; overflow-x: auto; }
.tabs #refresh { margin-left: auto; }
.tab { min-height: 42px; padding: 9px 14px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 750; white-space: nowrap; }
.tab.active { background: var(--panel-solid); color: var(--accent); box-shadow: var(--shadow); }
.view { min-height: 300px; }
.status-line { margin-bottom: 16px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.metric-card, .table-wrap, .create-grid, .section-heading, .empty { border: 1px solid var(--border); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.metric-card { padding: 22px; }
.metric-card h2 { margin-bottom: 18px; font-size: 1.65rem; }
.metric-card dl { margin: 0; }
.metric-card dl div { display: flex; justify-content: space-between; gap: 18px; padding: 8px 0; border-top: 1px solid var(--border); }
.metric-card dt { color: var(--muted); }
.metric-card dd { margin: 0; font-weight: 700; text-align: right; }
.section-heading { display: flex; justify-content: space-between; padding: 20px; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 0.78rem; }
td .button { min-height: 36px; margin-right: 6px; padding: 7px 10px; }
.create-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto; gap: 12px; align-items: end; padding: 18px; margin-bottom: 14px; }
.create-grid label { display: grid; gap: 7px; }
.empty { padding: 30px; color: var(--muted); text-align: center; }
.api-heading { align-items: center; gap: 20px; }
.api-heading .muted { margin: 8px 0 0; }
.docs-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.docs-card { min-width: 0; padding: 22px; border: 1px solid var(--border); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.docs-wide { margin-top: 16px; }
.docs-list { margin: 18px 0 0; }
.docs-list div { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.docs-list dt { color: var(--muted); }
.docs-list dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.docs-note { margin: 18px 0 0; color: var(--muted); line-height: 1.65; }
.steps { margin: 18px 0 0; padding-left: 22px; }
.steps li { margin: 9px 0; line-height: 1.55; }
.docs-table { margin-top: 18px; box-shadow: none; }
.example-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
pre { margin: 18px 0 0; padding: 18px; overflow-x: auto; border-radius: 14px; background: #111827; color: #f8fafc; font-size: 0.82rem; line-height: 1.65; white-space: pre; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

dialog {
  width: min(480px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(16, 24, 40, 0.25);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.58); backdrop-filter: blur(4px); }
#alert-form { padding: 24px; }
.dialog-heading { justify-content: space-between; margin-bottom: 10px; }
.icon-button { width: 40px; height: 40px; background: var(--neutral-bg); color: var(--text); font-size: 1.5rem; }
.dialog-actions { justify-content: flex-end; gap: 10px; margin-top: 10px; }

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: min(420px, calc(100% - 36px));
  padding: 13px 16px;
  border-radius: 12px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
  font-weight: 700;
  text-align: center;
}

@media (max-width: 700px) {
  .shell { width: min(100% - 22px, 1100px); padding-top: max(18px, env(safe-area-inset-top)); }
  .masthead { margin-bottom: 18px; }
  .login-panel { grid-template-columns: 1fr; gap: 18px; padding: 22px; }
  .overview { flex-direction: column; }
  .overview-actions { align-items: stretch; gap: 12px; }
  .overview-actions p { text-align: left; }
  .alert-grid { grid-template-columns: 1fr; gap: 14px; margin-top: 14px; }
  .alert-card { padding: 20px; }
  .metric-grid { grid-template-columns: 1fr; }
  .docs-grid { grid-template-columns: 1fr; }
  .api-heading { align-items: stretch; flex-direction: column; }
  .create-grid { grid-template-columns: 1fr 1fr; }
  .create-grid .button { grid-column: 1 / -1; }
  .tabs #refresh { margin-left: 0; }
  .bulk-actions { margin-top: 14px; }
  .bulk-actions .button { flex: 1; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --panel: rgba(17, 24, 39, 0.9);
    --panel-solid: #111827;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #293548;
    --neutral-bg: #202b3c;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
  }
}
