:root {
  color-scheme: light;
  --ink: #172128;
  --muted: #62717a;
  --line: #d8e0e2;
  --surface: #ffffff;
  --canvas: #f3f6f6;
  --accent: #12655f;
  --accent-strong: #0b4d48;
  --accent-soft: #e3f1ef;
  --positive: #16734c;
  --negative: #b43f42;
  --warning: #a06c00;
  --warning-soft: #fff4d6;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font-size: 15px; line-height: 1.45; letter-spacing: 0; }
button, input, select { font: inherit; }
button, .button { min-height: 42px; border: 1px solid var(--accent); border-radius: 6px; padding: 9px 15px; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button:hover, .button:hover { background: var(--accent-strong); }
button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
button.secondary:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(18, 101, 95, .24); outline-offset: 2px; }
input, select { width: 100%; min-height: 44px; border: 1px solid #cbd5d7; border-radius: 6px; padding: 9px 11px; color: var(--ink); background: #fff; }
label { display: grid; gap: 6px; color: #34444c; font-size: 13px; font-weight: 700; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 32px; line-height: 1.12; }
h2 { margin-bottom: 5px; font-size: 20px; }
small { display: block; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: 8px; color: var(--accent); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }
.warning-text { color: var(--warning) !important; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eaf0ef; }
.auth-shell { width: min(980px, 100%); display: grid; grid-template-columns: 1.2fr .8fr; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; box-shadow: 0 18px 50px rgba(22, 43, 45, .12); }
.auth-shell.single { grid-template-columns: minmax(0, 620px); justify-content: center; background: transparent; border: 0; box-shadow: none; }
.auth-brand { min-height: 520px; padding: 56px; display: flex; flex-direction: column; justify-content: center; color: #fff; background: #143f3c; }
.auth-brand .eyebrow { color: #7fd4ca; }
.auth-brand h1 { max-width: 460px; font-size: 48px; }
.auth-brand > p:not(.eyebrow) { color: #d2e1df; max-width: 480px; font-size: 18px; }
.auth-points { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.auth-points span { border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 7px 10px; font-size: 12px; }
.auth-card { padding: 48px 38px; align-self: center; }
.auth-card h2 { font-size: 28px; }
.install-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 18px 50px rgba(22, 43, 45, .12); }
.stack-form { display: grid; gap: 16px; margin-top: 24px; }
.message { padding: 11px 13px; border-left: 3px solid; background: #eef4f4; }
.message.error { color: var(--negative); border-color: var(--negative); background: #fff0f0; }
.message.warning { color: #684900; border-color: var(--warning); background: var(--warning-soft); }

.topbar { position: sticky; top: 0; z-index: 30; height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; color: #fff; background: #113a37; border-bottom: 1px solid #28514e; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 6px; background: #fff; color: var(--accent-strong); font-weight: 900; }
.brand strong, .brand small { display: block; color: #fff; line-height: 1.1; }
.brand small { margin-top: 3px; color: #b8d2cf; }
.topbar-meta, .user-menu, .user-menu form { display: flex; align-items: center; gap: 14px; margin: 0; }
.user-menu > span { text-align: right; }
.user-menu strong, .user-menu small { display: block; color: #fff; }
.user-menu small { color: #b8d2cf; }
.data-status { font-size: 12px; color: #b8d2cf; }
.data-status[data-kind="error"] { color: #ffc7c7; }
.data-status[data-kind="ok"] { color: #aee8c8; }
.icon-button { width: 42px; padding: 0; background: transparent; border-color: rgba(255,255,255,.28); font-size: 22px; }

.app-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.sidebar { position: sticky; top: 68px; height: calc(100vh - 68px); padding: 18px 12px; background: #fff; border-right: 1px solid var(--line); }
.nav-item { width: 100%; min-height: 42px; justify-content: flex-start; margin-bottom: 4px; border-color: transparent; background: transparent; color: #405057; font-weight: 650; }
.nav-item:hover { background: #edf4f3; color: var(--accent); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.workspace { min-width: 0; padding: 28px; }
.view { display: none; max-width: 1500px; margin: 0 auto; }
.view.active { display: block; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-head .muted { margin-bottom: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-card { min-height: 150px; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.metric-card > span { color: var(--muted); font-size: 13px; }
.metric-card > strong { display: block; margin: 8px 0 2px; font-size: 23px; line-height: 1.2; }
.metric-result { margin-top: 18px; font-weight: 800; }
.action-metric { background: var(--accent-soft); border-color: #b6d8d3; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(280px, .8fr); gap: 16px; }
.panel { min-width: 0; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; }
.panel-head { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel-head p { margin: 0; color: var(--muted); font-size: 13px; }
.quality-key { color: var(--muted); font-size: 12px; }
.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 13px; text-align: left; white-space: nowrap; color: #4d5d65; background: #edf2f2; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; }
td { padding: 12px 13px; border-bottom: 1px solid #e7ecec; vertical-align: middle; white-space: nowrap; }
td:first-child { white-space: normal; min-width: 130px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7fafa; }
td small { margin-top: 2px; max-width: 230px; white-space: normal; }
.empty { padding: 30px !important; color: var(--muted); text-align: center; }
.quality { width: 28px; height: 28px; display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 800; }
.quality-A { background: var(--positive); }.quality-B { background: #4c8f66; }.quality-C { background: var(--warning); }.quality-D,.quality-E { background: var(--negative); }
.pill { display: inline-flex; align-items: center; min-height: 26px; border-radius: 999px; padding: 3px 9px; background: #edf1f1; color: #46545b; font-size: 11px; font-weight: 800; }
.pill.buy, .pill.ok { background: #e4f4eb; color: var(--positive); }
.pill.sell { background: #fbe8e8; color: var(--negative); }
.pill.warning { background: var(--warning-soft); color: #725000; }
.health-list { display: grid; padding: 6px 18px 14px; }
.health-list > div { display: flex; justify-content: space-between; gap: 14px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.health-list > div:last-child { border-bottom: 0; }
.health-list span { color: var(--muted); }
.health-list strong { text-align: right; }
.account-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; padding: 18px; }
.account-list article { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 6px; }
.account-list strong, .account-list small { display: block; }
.text-button { min-height: 32px; padding: 4px 8px; border: 0; background: transparent; color: var(--accent); }
.text-button.danger { color: var(--negative); }

dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 22px 70px rgba(11, 48, 45, .24); }
dialog::backdrop { background: rgba(9, 25, 27, .58); }
.dialog-form { padding: 22px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.dialog-head .icon-button { color: var(--ink); border-color: var(--line); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 90; max-width: min(420px, calc(100% - 40px)); padding: 13px 16px; border-radius: 6px; color: #fff; background: var(--accent-strong); box-shadow: 0 10px 30px rgba(0,0,0,.2); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--negative); }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .topbar { padding: 0 14px; }
  .data-status, .user-menu > span { display: none; }
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 68px; z-index: 20; width: 100%; height: auto; display: flex; gap: 4px; padding: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-item { width: auto; min-width: max-content; margin: 0; justify-content: center; }
  .workspace { padding: 18px 12px 90px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { min-height: 270px; padding: 36px; }
  .auth-brand h1 { font-size: 38px; }
}

@media (max-width: 540px) {
  h1 { font-size: 27px; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 126px; }
  .form-grid { grid-template-columns: 1fr; }
  .auth-page { padding: 10px; }
  .auth-brand, .auth-card { padding: 28px 22px; }
  .auth-brand h1 { font-size: 34px; }
  .auth-points { margin-top: 14px; }
  .dialog-form { padding: 16px; }
  .dialog-actions { position: sticky; bottom: 0; padding-top: 12px; background: #fff; }
}
