:root {
  --canvas: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #553de9;
  --primary-soft: #eeebfd;
  --success: #15803d;
  --failure: #b91c1c;
  --active: #1d4ed8;
  --queued: #b45309;
  --neutral: #475569;
  --radius: 4px;
  color-scheme: light;
  accent-color: var(--primary);
}

::selection { background: var(--primary-soft); color: var(--text); }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[hidden] { display: none !important; }

.muted { color: var(--muted); }

.icon { width: 16px; height: 16px; fill: currentColor; flex: none; }

/* Header */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: var(--radius); background: var(--primary); color: #fff; font-size: 14px;
}
.page-tabs { display: flex; gap: 4px; }
.page-tabs button, .tab-list button {
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 500;
  padding: 8px 12px; border-bottom: 2px solid transparent; cursor: pointer;
}
.page-tabs button[aria-selected="true"], .tab-list button[aria-selected="true"] {
  color: var(--primary); border-bottom-color: var(--primary);
}
.header-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-left: auto; min-width: 0; }
.connection { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.connection .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); flex: none; }
.connection[data-state="connected"] .dot { background: var(--success); }
.connection[data-state="disconnected"] .dot { background: var(--failure); }

/* Button widget */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 0; border-radius: var(--radius);
  background: var(--primary); color: #fff; font: inherit; font-weight: 500; cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-small { padding: 4px 10px; font-size: 13px; background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

main { padding: 16px; max-width: 1440px; margin: 0 auto; }
.page { display: grid; gap: 16px; }
.page > *, .stat-row > *, .chart-row > *, .chart-grid > * { min-width: 0; }

/* Container widget */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.card-title { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.card-note { margin: 0 0 8px; color: var(--muted); font-size: 12px; }

/* Statbox widget */
.stat-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.statbox {
  display: flex; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
}
.stat-body { min-width: 0; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-note { color: var(--muted); font-size: 12px; }
.stat-icon {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: var(--radius); background: var(--primary-soft); color: var(--primary);
}
.stat-icon .icon { width: 20px; height: 20px; }

/* Chart widget */
.chart-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.chart-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.chart { height: 280px; width: 100%; }

/* Tabs widget */
.tabs { padding-top: 0; }
.tab-list { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin: 0 -16px 12px; padding: 0 8px; }

/* Select widget */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 500; margin-bottom: 8px; max-width: 100%; }
.toolbar .field { margin-bottom: 0; }
select, .table-search {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 8px; min-width: 0; max-width: 100%;
}

/* Text widget used as an error state */
.alert { border: 1px solid #fecaca; background: #fef2f2; color: #7f1d1d; border-radius: var(--radius); padding: 12px 16px; }
.alert-title { display: block; }
.alert p { margin: 4px 0 0; overflow-wrap: anywhere; }

/* Table v2 widget */
.table-search { width: 240px; margin-bottom: 8px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--canvas); }
th { background: var(--canvas); padding: 0; }
th .sort {
  width: 100%; padding: 8px 10px; border: 0; background: none; font: inherit; font-weight: 600;
  color: var(--text); text-align: left; cursor: pointer; white-space: nowrap;
}
th[aria-sort="ascending"] .sort::after { content: " ▲"; color: var(--primary); }
th[aria-sort="descending"] .sort::after { content: " ▼"; color: var(--primary); }
td.empty { color: var(--muted); text-align: center; padding: 24px; }
td.status { font-weight: 600; }
.success { color: var(--success); }
.failure { color: var(--failure); }
.active { color: var(--active); }
.queued { color: var(--queued); }
.neutral { color: var(--neutral); }
.table-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.pager { display: flex; align-items: center; gap: 8px; }
.pager-arrow { padding: 4px 6px; }

/* Text widget used as a section heading */
.section-head { margin-top: 16px; }
.section-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.section-head p { margin: 2px 0 0; font-size: 13px; }

/* ROI calculator: Currency Input widgets and a Table v2 with one editable column */
.calc-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 8px 16px; }
.calc-head .card-note { margin-bottom: 0; max-width: 72ch; }
.calc-body { display: grid; gap: 16px; margin-top: 16px; }
.calc-body > *, .calc-costs > * { min-width: 0; } /* the table scrolls inside its card */
.calc-costs { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); align-items: end; }
.cost-field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.cost-field label { color: var(--muted); font-weight: 500; font-size: 13px; }
.money {
  display: flex; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.money:focus-within { outline: 2px solid var(--primary); outline-offset: 1px; }
.money span { padding: 0 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.money input {
  flex: 1; min-width: 0; padding: 6px 0; border: 0; background: none;
  font: inherit; font-weight: 600; color: var(--text); text-align: right; font-variant-numeric: tabular-nums;
}
.money input:focus-visible { outline: none; }
.money:has(input[aria-invalid="true"]), .minutes input[aria-invalid="true"] { border-color: var(--failure); }
.calc th { padding: 8px 10px; font-weight: 600; }
.calc .num { text-align: right; font-variant-numeric: tabular-nums; }
.minutes { display: inline-flex; align-items: center; gap: 6px; }
.minutes input {
  width: 64px; padding: 3px 6px; font: inherit; color: var(--text); text-align: right; font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.link {
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--primary); text-align: left;
}
.link:hover { text-decoration: underline; text-underline-offset: 2px; }
.calc tr.selected td { background: var(--primary-soft); }
.calc td:first-child { white-space: normal; overflow-wrap: anywhere; min-width: 8em; } /* Table v2 cell wrapping */
.calc-totals { margin: 12px 0 0; font-size: 13px; }
td, .stat-value { font-variant-numeric: tabular-nums; }

/* Language Button widget: shows the current language, a click switches it */
.lang { min-width: 40px; justify-content: center; font-weight: 600; letter-spacing: 0.02em; }
.lang-corner { position: absolute; top: 12px; right: 16px; }

/* Sign-in page */
.login { display: grid; gap: 8px; max-width: 360px; margin: 48px auto 0; padding: 24px; }
.login .brand-name { margin: 0; font-size: 15px; }
.login p { margin: 0 0 8px; }
.login label, .modal-form label { color: var(--muted); font-weight: 500; }
.login input, .modal-form input {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px; margin-bottom: 8px;
}
.login .btn { justify-content: center; padding: 8px 12px; }
.login .login-error, .modal-form .login-error { margin: 0; min-height: 1.45em; color: var(--failure); }

/* Modal widget */
.modal { border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(440px, calc(100% - 32px)); color: var(--text); }
.modal::backdrop { background: rgb(15 23 42 / 0.4); }
.modal-form { display: grid; gap: 4px; padding: 20px 24px; }
.modal-form p { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 600px) {
  main { padding: 16px; }
  .header-right { margin-left: 0; }
  .table-search { width: 100%; }
  .chart { height: 240px; }
}
