/*
 * Anyori Console and Customer Portal. Builds on base.css (design tokens and basic components
 * shared with the sample apps). No external resources, no inline styles (CSP).
 */

:root { --sidebar: 228px; --ink-soft: color-mix(in srgb, var(--text) 78%, var(--bg)); }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── operator console shell ── */
body.console { background: var(--bg); }
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
/* the sidebar is sticky and one viewport tall; the column behind it keeps its colour on long pages */
.shell { background: linear-gradient(to right, var(--surface) 0, var(--surface) var(--sidebar), transparent var(--sidebar)); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 0 8px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a { padding: 8px 10px; border-radius: 8px; color: var(--ink-soft); text-decoration: none; font-weight: 500; }
.side-nav a:hover { background: var(--bg); color: var(--text); }
.side-nav a[aria-current] { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--accent); }
.side-foot { margin-top: auto; display: grid; gap: 12px; padding: 0 8px; }
.side-foot .lang { justify-self: start; }
.who { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 13px; }
.who a { color: var(--text); text-decoration: none; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-button:hover { color: var(--text); }
.content { min-width: 0; display: flex; flex-direction: column; }
.main { padding: 24px 28px 48px; max-width: 1280px; width: 100%; flex: 1; }
body.console .site-footer { text-align: left; padding: 14px 28px; }
body.portal .who { gap: 12px; }

/* ── page head ── */
.page-head { margin-bottom: 18px; }
.page-head .page-title { margin: 0; align-items: flex-start; }
.subtitle { color: var(--muted); margin: 4px 0 0; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); text-decoration: underline; }
.actions { justify-content: flex-end; }

/* ── cards and grids ── */
.card + .card, .card + .table-wrap, .table-wrap + .card, .grid + .card, .card + .grid, .grid + .grid, .tabs + .card, .notice + .card { margin-top: 16px; }
.card > h2:first-child, .card-head h2 { margin: 0; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card > .table-wrap:last-child .table, .card.flush .table { border: 0; border-radius: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 14px 16px 0; }
.card.flush > .empty { border: 0; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
.grid.two > .card + .card, .grid.three > .card + .card, .grid.kpis > .card + .card, .grid > .card + .card { margin-top: 0; }
a.card { color: inherit; text-decoration: none; display: block; }
a.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.kpi.ok .value { color: var(--ok); }
.kpi.warn .value { color: var(--warn); }
.kpi.bad .value { color: var(--bad); }
.stack { display: grid; gap: 16px; }
.stack > * { margin-top: 0 !important; }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.split > * { margin-top: 0 !important; min-width: 0; }

/* ── state ── */
.badge.state { display: inline-flex; align-items: center; gap: 6px; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.badge.state[data-state="starting"] .state-dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .badge.state .state-dot { animation: none; } }

/* ── definition lists ── */
.dl { margin: 0; display: grid; gap: 0; }
.dl > div { display: grid; grid-template-columns: minmax(120px, 34%) minmax(0, 1fr); gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; overflow-wrap: anywhere; }

/* ── tabs ── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 0 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current] { color: var(--accent); border-bottom-color: var(--accent); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 12px; text-align: center; color: var(--muted); }

/* ── tables ── */
.table td a { text-decoration: none; }
.table td a:hover { text-decoration: underline; }
.table .primary-cell { font-weight: 600; }
.table .sub { display: block; color: var(--muted); font-size: 13px; font-weight: 400; }
.table td.actions-cell { white-space: nowrap; text-align: right; }
.table td.actions-cell .inline-form { margin-left: 4px; }
.empty { border: 1px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center; color: var(--muted); background: var(--surface); }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.pagination { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; }

/* ── forms ── */
.form.wide { max-width: 860px; }
.form .cols { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field .optional { color: var(--muted); font-weight: 400; }
.field-help { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.field-error { color: var(--bad); font-size: 13px; margin: 2px 0 0; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.field.check label { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; }
.field.check input { width: auto; }
textarea { resize: vertical; min-height: 80px; }
.form-actions { margin-top: 4px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; display: grid; gap: 14px; }
legend { font-weight: 600; padding: 0 6px; font-size: 14px; }
.inline-form { display: inline-flex; margin: 0; }
.inline-form input { width: auto; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 0 0 14px; }
.filter-bar select, .filter-bar input { width: auto; min-width: 150px; }
.btn.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.notice.warn { background: color-mix(in srgb, var(--warn) 9%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 38%, transparent); }
.notice p:last-child { margin-bottom: 0; }

/* ── code, logs, copy ── */
.sha { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
pre.code, pre.log { margin: 0; padding: 12px 14px; border-radius: var(--radius); overflow: auto; font: 12.5px/1.55 var(--mono); }
pre.code { background: var(--bg); border: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
pre.log { background: #0f1419; color: #d7dde6; max-height: 520px; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid #2a3441; }
.copy-box { display: flex; gap: 8px; align-items: flex-start; }
.copy-box pre { flex: 1; min-width: 0; margin: 0; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font: 12.5px/1.5 var(--mono); overflow-x: auto; white-space: pre; }
.copy-box.multiline pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── charts ── */
.chart { margin: 0; }
.chart svg { width: 100%; height: 120px; display: block; }
.chart .bar { fill: var(--accent); opacity: 0.85; }
.chart .bar:hover { opacity: 1; }
.chart figcaption { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; }
.uptime-strip { display: flex; gap: 2px; height: 26px; }
.uptime-strip .cell { flex: 1; border-radius: 2px; background: var(--border); }
.uptime-strip .cell.ok { background: var(--ok); }
.uptime-strip .cell.warn { background: var(--warn); }
.uptime-strip .cell.bad { background: var(--bad); }

/* ── conversation (requests) ── */
.thread { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.thread .msg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.thread .msg.internal { background: color-mix(in srgb, var(--warn) 7%, var(--surface)); border-style: dashed; }
.thread .msg.staff { border-left: 3px solid var(--accent); }
.thread .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.thread .meta strong { color: var(--text); }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── site cards (portal and overview) ── */
.site-card { display: grid; gap: 8px; }
.site-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.site-card h3 { margin: 0; font-size: 16px; }
.site-card .host { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.meter { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* ── sign-in ── */
body.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 400px; }
.auth-card { padding: 28px 26px; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-card .form { margin-top: 18px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; margin-bottom: 18px; color: var(--muted); }
.auth-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.auth-foot { display: flex; justify-content: center; margin-top: 16px; }
.error-card { text-align: center; }
.error-status { font-size: 44px; font-weight: 700; color: var(--muted); margin: 0 0 6px; }

/* ── small screens ── */
@media (max-width: 900px) {
  /* rows: the header keeps its own height; on a short page the content takes the rest of the screen */
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; background: none; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; align-content: flex-start; gap: 10px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; padding-bottom: 2px; }
  .side-nav a { white-space: nowrap; padding: 6px 10px; }
  .side-foot { margin: 0 0 0 auto; display: flex; align-items: center; padding: 0; }
  .main { padding: 16px 14px 40px; }
  body.console .site-footer { padding: 14px; }
  .split { grid-template-columns: 1fr; }
  .dl > div { grid-template-columns: 1fr; gap: 2px; }
}

/* ── spacing fixes ── */
.card .dl + form, .card .dl + .form, .card p + form { margin-top: 16px; }
.card > :last-child { margin-bottom: 0; }

/* ── overview ── */
.attention { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.attention li { padding: 8px 12px; border-radius: 8px; border-left: 3px solid var(--border); background: var(--bg); }
.attention li.bad { border-left-color: var(--bad); }
.attention li.warn { border-left-color: var(--warn); }
.attention li.info { border-left-color: var(--info); }
.attention a { color: var(--text); text-decoration: none; }
.attention a:hover { text-decoration: underline; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.plain-list li > a { font-weight: 500; text-decoration: none; }
.plain-list li > a:hover { text-decoration: underline; }
.plain-list .row { margin-top: 4px; gap: 8px; }
.server-line { display: grid; gap: 4px; }
.server-line .row { justify-content: space-between; }
.server-line label { display: grid; gap: 2px; }
.card-head a.small { text-decoration: none; }
.grid + .split, .split + .card, .split + .grid, .notice + .grid, .notice + .split, .tabs + .split, .tabs + .grid, .filter-bar + .card { margin-top: 16px; }

/* long words (URLs, file names) in titles and first columns wrap instead of widening the page */
.page-title h1, .table .primary-cell, .site-card h3, .plain-list li > a { overflow-wrap: anywhere; }

/* buttons keep their label on one line (tables with action columns) */
.btn { white-space: nowrap; }

/* ── tables: alignment and narrow screens ── */
/* base.css aligns every heading to the left; a right-aligned column keeps its heading above its content */
.table th.right, .table td.right { text-align: right; }
/* The name column may break long words (see above), so it needs a floor: without one a table that is
   too wide for the screen squeezes it to one letter per line instead of scrolling sideways. */
.table td:has(> .primary-cell), .table td.name-col { min-width: min(10em, 42vw); }

/* ── forms: monospace fields are as tall as the fields next to them ── */
input.mono { line-height: 22.5px; }

/* ── figures that are words ("12 h 0 min", "12 小时 0 分钟") stay on one line, as tall as a number ── */
.kpi.text .value { font-size: 21px; line-height: 30.8px; word-break: keep-all; }
@media (max-width: 640px) { .kpi.text .value { font-size: 18px; line-height: 26.4px; } }

/* ── cards in a row ── */
.grid.even { align-items: stretch; }
.grid > .site-card { align-self: stretch; align-content: start; }
.card .dl + .row { margin-top: 12px; }
.server-line a { text-decoration: none; }
.server-line a:hover { text-decoration: underline; }

/* ── error page without a session: one card, not a card inside the sign-in card ── */
.auth-card .error-card { margin-top: 8px; }

/* ── keyboard focus inside boxes that clip (the language switch, scrolling tab bars): draw the ring inside ── */
.lang a:focus-visible, .tabs a:focus-visible, .side-nav a:focus-visible { outline-offset: -2px; }
.lang a[aria-current]:focus-visible { outline-color: var(--on-accent); }
