/* Partner dashboard and admin (task 96): a working tool, not a page to sell — a quiet sidebar, white panels,
   rows that read like a checklist, numbers set in tabular figures. Light and dark from the site's tokens. */
.dash-body { background: var(--bg); }
.dash { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
@media (max-width: 860px) { .dash { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; } }

.side { background: var(--card); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
@media (max-width: 860px) { .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; align-items: center; align-content: flex-start; gap: 4px 8px; padding: 12px; } }
.side-brand { display: flex; align-items: center; gap: 10px; font: 600 20px/1 var(--serif); color: var(--ink); text-decoration: none; padding: 4px 10px 2px; }
.side-brand img { border-radius: 8px; }
.side-role { margin: 0 10px 14px; color: var(--muted); font-size: 13px; }
@media (max-width: 860px) { .side-role { display: none; } }
.side-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
@media (max-width: 860px) { .side-group { flex-direction: row; margin: 0; } }
.side-label { margin: 8px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
@media (max-width: 860px) { .side-label { display: none; } }
.side-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--ink); text-decoration: none;
  font: 500 15px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: none; border: 0; cursor: pointer; text-align: left; position: relative; }
.side-link:hover { background: var(--bg); }
.side-link.on { background: var(--bg); font-weight: 650; }
.side-link.on::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--green); }
@media (max-width: 860px) { .side-link.on::before { display: none; } }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; }
@media (max-width: 860px) { .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; } .side-user { display: none; } }
.side-user { margin: 0 10px 4px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ic { display: inline-flex; width: 18px; height: 18px; flex: none; }
.ic svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.dash-main { min-width: 0; padding: 28px clamp(16px, 3vw, 40px) 64px; max-width: 1100px; width: 100%; display: flex; flex-direction: column; gap: 18px; }
.dash-title { font: 600 clamp(28px, 3vw, 36px)/1.1 var(--serif); margin: 4px 0 4px; letter-spacing: -0.01em; }

.banner { display: flex; gap: 12px; align-items: flex-start; background: var(--leaf); color: var(--green-deep); border-radius: 14px; padding: 14px 18px; }
.banner p { margin: 0; font-size: 15px; }
.banner .ic { margin-top: 2px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.panel-head h2 { font: 600 20px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; margin: 0; letter-spacing: 0; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi strong { font: 600 24px/1.15 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
.kpi-hint { font-size: 12px; color: var(--muted); }

.steps-list { display: flex; flex-direction: column; margin: 0 -22px -20px; border-top: 1px solid var(--line); }
.step { display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center; padding: 16px 22px; background: none; border: 0;
  border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; color: var(--ink); font: inherit; }
.step:last-child { border-bottom: 0; border-radius: 0 0 16px 16px; }
.step:hover { background: var(--bg); }
.step-ic { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.step-text { display: flex; flex-direction: column; gap: 2px; }
.step-text strong { font-weight: 600; }
.step-text span { font-size: 14px; color: var(--muted); }
.step-action { font-size: 13px; color: var(--green); font-weight: 600; max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .step-action { display: none; } }

.chart { margin: 0; }
.chart svg { width: 100%; height: 150px; display: block; }
.b-visits { fill: var(--leaf); }
.b-installs { fill: var(--green); }
.b-taps { fill: #d9822b; }
.chart figcaption { display: flex; gap: 8px 16px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: -10px; }
.lg-visits { background: var(--leaf); } .lg-installs { background: var(--green); } .lg-taps { background: #d9822b; border-radius: 50%; }

.dtable { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; background: none; }
.dtable th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.dtable td { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.dtable tr:last-child td { border-bottom: 0; }

.link-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.link-row code, .panel > code { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; overflow-wrap: anywhere; }
.link-row code { flex: 1 1 280px; }
.panel > code { flex: none; align-self: stretch; }

.input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); min-width: 0; width: 100%; }
.input:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.field-label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row .input { width: auto; flex: 1 1 140px; }

.btn { font: 600 15px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding: 11px 18px; border-radius: 10px; border: 1px solid var(--green-deep);
  background: var(--green-deep); color: #fff; cursor: pointer; align-self: flex-start; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.ghost.danger { color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 13px; }
@media (prefers-color-scheme: dark) { .btn { background: var(--leaf-ink); border-color: var(--leaf-ink); color: #102414; } .btn.ghost { color: var(--ink); background: var(--card); border-color: var(--line); } }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; align-self: flex-start; }
.seg button { font: 600 14px/1 system-ui, sans-serif; padding: 8px 14px; background: var(--card); color: var(--muted); border: 0; cursor: pointer; }
.seg button.on { background: var(--bg); color: var(--ink); }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); }
.pill.ok { background: var(--leaf); color: var(--green-deep); }
.app-row { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.app-row:first-of-type { border-top: 0; padding-top: 0; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.dash-kit img { height: 150px; background: var(--bg); }
.dash-kit a { color: var(--ink); }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(100%, 400px); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { font: 600 28px/1.1 var(--serif); margin: 8px 0 0; }
.auth-card .google-button { align-self: stretch; }
.auth-card .btn { align-self: stretch; }
.or { margin: 4px 0; text-align: center; color: var(--muted); font-size: 13px; }
.loading { min-height: 60vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--green); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.wide-form { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.panel textarea.input { resize: vertical; }

/* Hardening (task 101): status lines, refused fields, long names that must not push the layout. */
.status:empty { display: none; }
.status { font-size: 14px; }
.status[data-tone="error"] { color: var(--danger); font-weight: 600; }
.input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.btn[aria-busy="true"] { cursor: progress; }
.dash-title:focus { outline: none; }
.dash-title:focus-visible { outline: 3px solid var(--green); outline-offset: 4px; }
.step-text, .app-row > div { min-width: 0; overflow-wrap: anywhere; }
.kpi strong { overflow-wrap: anywhere; }
.link-row .status { flex-basis: 100%; }

/* AI health (task 103): a verdict per chain, then every link with its state and what to do about it. */
.stack-lg { display: flex; flex-direction: column; gap: 18px; }
/* New free models (task 138): one block per run, its table and what it switched off. */
.discover-run { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.kpi.good { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.kpi.good strong { color: var(--green); }
.kpi.bad { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); }
.kpi.bad strong { color: var(--danger); }
.pill.st-ok { background: var(--leaf); color: var(--green-deep); }
.pill.st-key_rejected, .pill.st-no_credits, .pill.st-model_gone, .pill.st-no_key, .pill.st-error {
  background: color-mix(in srgb, var(--danger) 14%, var(--card)); color: var(--danger); }
.pill.st-rate_limited, .pill.st-down, .pill.st-timeout, .pill.st-unreachable, .pill.st-bad_answer {
  background: color-mix(in srgb, #d9822b 16%, var(--card)); color: color-mix(in srgb, #d9822b 70%, var(--ink)); }
.panel { min-width: 0; }
.ai-table td { vertical-align: top; }
.ai-table .who { display: flex; flex-direction: column; gap: 2px; white-space: normal; min-width: 9em; max-width: 16em; overflow-wrap: anywhere; }
.dtable td .why { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; white-space: normal; min-width: 14em; max-width: 30em; }
.dtable td .detail { overflow-wrap: anywhere; white-space: normal; display: block; max-width: 34em; }
.bad-num { color: var(--danger); font-weight: 600; }
/* On a phone every link is a small card: service and answer time, what for, then the state and what to do. */
@media (max-width: 600px) {
  .ai-table thead { display: none; }
  .ai-table, .ai-table tbody { display: block; }
  .ai-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
  .ai-table tr:last-child { border-bottom: 0; }
  .ai-table td { display: block; padding: 0; border: 0; white-space: normal; }
  .ai-table td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .ai-table td:nth-child(4) { grid-column: 2; grid-row: 1; color: var(--muted); font-size: 13px; }
  .ai-table td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; color: var(--muted); font-size: 13px; }
  .ai-table td:nth-child(3) { grid-column: 1 / -1; grid-row: 3; }
  .ai-table .who, .dtable.ai-table td .why { min-width: 0; max-width: none; }
}

/* Partner terms (task 104): three ways to pay, chosen like a setting, not a dropdown. */
.choices { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.choice { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; font-size: 15px; min-height: 44px; }
.choice:has(input:checked) { border-color: var(--green); background: color-mix(in srgb, var(--leaf) 45%, var(--card)); font-weight: 600; }
.choice input { accent-color: var(--green); margin: 0; }
.nowrap { flex-wrap: nowrap; }
.partner-cell { display: flex; flex-direction: column; gap: 4px; }
.partner-cell .row { margin-top: 4px; gap: 6px; }
.field-legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 6px; width: 100%; }
.choices[hidden] { display: none; }

/* AI chains run by the owner (task 106): a numbered list per chain, reserve dimmed, Up / Down / On-Off at hand. */
.link-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.link-item { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 0; border-top: 1px solid var(--line); }
.link-item:first-child { border-top: 0; }
.link-item.off { opacity: 0.72; }
.link-item.off .link-order { color: var(--muted); }
.link-order { font: 600 16px/28px var(--serif); color: var(--green); text-align: center; }
.link-main { display: grid; gap: 6px; min-width: 0; }
@media (min-width: 900px) { .link-main { grid-template-columns: minmax(12em, 1fr) minmax(0, 1.4fr); gap: 16px; } }
.link-main .why { min-width: 0; max-width: none; white-space: normal; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.link-main .who { overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 2px; }
.link-controls { display: flex; gap: 6px; align-items: center; }
.btn.icon { min-width: 36px; padding-inline: 0; justify-content: center; font-size: 16px; }
.btn:disabled:not([aria-busy="true"]) { cursor: default; opacity: 0.35; }
@media (max-width: 600px) {
  .link-item { grid-template-columns: 24px minmax(0, 1fr); }
  .link-controls { grid-column: 2; }
}
.feedback-table td .detail { max-width: 26em; }

/* Phones (owner 2026-10-02, «адаптируй на мобильные»): the logo and sign-out in one row, the tabs in one strip
   under them that scrolls sideways and stays at the top; tables become cards of «label: value». */
.side-nav { display: contents; }
@media (max-width: 860px) {
  .side { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 8px; padding: 10px 12px 0; position: sticky; top: 0; z-index: 10; }
  .side-brand { grid-column: 1; grid-row: 1; }
  .side-foot { grid-column: 2; grid-row: 1; margin: 0; }
  .side-nav { grid-column: 1 / -1; grid-row: 2; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 4px 12px 10px;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent); }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-group { flex: none; gap: 2px; }
  .side-link { white-space: nowrap; padding: 8px 12px; border-radius: 999px; font-size: 14px; }
  .side-link .ic { width: 16px; height: 16px; }
  .side-link.on { background: var(--leaf); color: var(--green-deep); }
}
@media (max-width: 600px) {
  .dtable:not(.ai-table) thead { display: none; }
  .dtable:not(.ai-table), .dtable:not(.ai-table) tbody { display: block; }
  .dtable:not(.ai-table) tr { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .dtable:not(.ai-table) tr:last-child { border-bottom: 0; }
  .dtable:not(.ai-table) td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 0; border: 0; white-space: normal; text-align: right; }
  .dtable:not(.ai-table) td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; max-width: 55%; }
  .dtable:not(.ai-table) td:first-child { font-weight: 650; font-size: 15px; text-align: left; }
  .dtable:not(.ai-table) td:first-child::before { content: none; }
  .dtable:not(.ai-table) td:not([data-label])::before { content: none; }
  .scroll:has(> .dtable) { overflow: visible; }
}

/* Team keys (task 137): one group per AI service — its Supabase secret, then the team's keys, oldest first. */
.keys-service { display: grid; gap: 6px; padding: 12px 0; border-top: 1px solid var(--line); }
.keys-service:first-of-type { border-top: 0; }
.keys-service .link-list { margin-top: 2px; }
