/* Meridian console: base and shared components. Tokens live in tokens.css. */

/* -- base ---------------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--body); font-size: 16px; line-height: 1.5; color: var(--t1); background: var(--bg);
  min-height: 100vh; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
h1, h2 { font-family: var(--heading); font-weight: 600; letter-spacing: -.015em; line-height: 1.2; }
:lang(fa) h1, :lang(fa) h2, :lang(zh) h1, :lang(zh) h2 { letter-spacing: 0; font-weight: 700; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.125rem; }
a { color: var(--ac-text); }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: .9em; }
.mono { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--ac-text); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--ac2); }
.muted { color: var(--t2); }
.small { font-size: .875rem; }
.strong { font-weight: 600; }
.label { font-size: .75rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--t3); }
:lang(fa) .label, :lang(zh) .label { letter-spacing: 0; text-transform: none; font-size: .8rem; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
  stroke-linejoin: round; flex-shrink: 0; }
[dir="rtl"] .icon-flip, [dir="rtl"] .back .icon { transform: scaleX(-1); }
.noscript { padding: 24px; text-align: center; color: var(--t2); }

/* -- boot and spinner ----------------------------------------------------------------------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--b1); border-top-color: var(--ac-ui);
  display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } * { transition: none !important; } }

/* -- buttons -------------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: var(--r); border: 1px solid transparent; font-weight: 600; font-size: .95rem; text-decoration: none;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, filter .12s, transform .06s;
  -webkit-user-select: none; user-select: none; flex-shrink: 0; overflow-wrap: normal; word-break: normal;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .875rem; }
.btn-primary { background: var(--ac); color: var(--on-ac); }
.btn-primary:hover { background: var(--ac-hover); }
.btn-soft { background: var(--ac2); color: var(--ac-text); }
.btn-soft:hover { border-color: var(--ac); }
.btn-ghost { background: var(--s1); border-color: var(--b1); color: var(--t1); }
.btn-ghost:hover { border-color: var(--b2); background: var(--s2); }
.btn-danger { background: var(--err); color: var(--on-err); }
.btn-danger:hover { filter: brightness(1.08); }
.btn-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r);
  border: 1px solid transparent; background: none; color: var(--t2); cursor: pointer; }
.btn-icon:hover { background: var(--s2); color: var(--t1); }

/* -- forms ---------------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: .875rem; font-weight: 600; color: var(--t1); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--control-border);
  background: var(--s1); color: var(--t1); font-size: 1rem;
}
select { padding-inline-end: 32px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ac-text); box-shadow: 0 0 0 3px var(--ac2); }
textarea { resize: vertical; min-height: 100px; }
input::placeholder { color: var(--t3); }
.code-input { font-family: var(--mono); letter-spacing: .3em; font-size: 1.25rem; text-align: center; direction: ltr; }
.hint { font-size: .8125rem; color: var(--t2); }
.form-error { color: var(--err); font-size: .875rem; min-height: 0; }
.form-error:empty { display: none; }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); padding: var(--space-1); border-radius: var(--r2); background: var(--s2);
  border: 1px solid var(--b1); }
.segmented button { border: 0; background: none; padding: var(--space-2) var(--space-3); border-radius: var(--r); cursor: pointer; color: var(--t2);
  font-weight: 600; font-size: .875rem; }
.segmented button.active { background: var(--s1); color: var(--t1); box-shadow: inset 0 0 0 1px var(--ac-text), var(--shadow-sm); }

/* -- pills, tags, dots ---------------------------------------------------------------------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; font-size: .75rem;
  font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.pill-ok, .status-chip-success { background: var(--ok2); color: var(--ok); }
.pill-err, .status-chip-danger { background: var(--err2); color: var(--err); }
.pill-warn, .status-chip-warn { background: var(--warn2); color: var(--ac-text); }
.pill-info, .pill-muted, .status-chip-neutral { background: var(--s2); color: var(--t2); border-color: var(--b1); }
.tag { font-size: .6875rem; font-weight: 700; color: var(--t3); border: 1px solid var(--b1); border-radius: 6px;
  padding: 0 6px; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok2); }
.dot-err { background: var(--err); box-shadow: 0 0 0 3px var(--err2); }
.dot-warn { background: var(--ac-ui); box-shadow: 0 0 0 3px var(--warn2); }
.dot-neutral { background: var(--t2); }

/* Shared read rows, meters, calm empty states, and action bars. */
.kv-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: var(--space-3);
  align-items: baseline; padding-block: var(--space-3); border-block-end: 1px solid var(--b1); }
.kv-row:last-child { border-block-end: 0; }
.kv-row dt { color: var(--t2); font-size: .875rem; }
.kv-row dt.has-tip, dt.has-tip, .title-row { display: flex; align-items: center; gap: var(--space-1); min-inline-size: 0; }
.kv-row dd { min-inline-size: 0; text-align: end; overflow-wrap: anywhere; }
.arrow-pair { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: .35em; max-inline-size: 100%; }
.meter { display: block; inline-size: 100%; block-size: var(--space-2); border: 0; border-radius: var(--r); overflow: hidden; }
.meter::-webkit-meter-bar { background: var(--s2); border: 0; border-radius: var(--r); }
.meter::-webkit-meter-optimum-value { background: var(--ok); border-radius: var(--r); }
.meter::-moz-meter-bar { background: var(--ok); border-radius: var(--r); }
.meter-warn::-webkit-meter-optimum-value { background: var(--ac-ui); }
.meter-warn::-moz-meter-bar { background: var(--ac-ui); }
.meter-danger::-webkit-meter-optimum-value { background: var(--err); }
.meter-danger::-moz-meter-bar { background: var(--err); }
.empty-state { display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-6) var(--space-4); text-align: center; color: var(--t2); }
.empty-state-check { display: grid; place-items: center; inline-size: var(--space-6); block-size: var(--space-6);
  border-radius: 50%; color: var(--ok); background: var(--ok2); }
.action-bar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-3);
  background: var(--s1); border: 1px solid var(--b1); border-radius: var(--r2); box-shadow: var(--shadow-sm); }
.sticky-actions { position: sticky; inset-block-end: var(--space-3); z-index: 10; }
.mode-disclosure > summary, .secondary-actions > summary { cursor: pointer; color: var(--t1); font-weight: 600;
  min-block-size: 44px; padding-block: var(--space-2); overflow-wrap: anywhere; }
.mode-content { display: flex; flex-direction: column; gap: var(--space-3); padding-block-start: var(--space-3); }
.mode-content > .card { border: 0; box-shadow: none; background: none; padding: 0; }
.mode-content > .server-capacity { border: 0; margin: 0; padding: 0; }
.card > .mode-disclosure { border-block-start: 1px solid var(--b1); }
.secondary-actions > summary { color: var(--ac-text); }
.secondary-actions .row-actions { padding-block-start: var(--space-2); }

/* -- notices, code, commands ---------------------------------------------------------------- */
.notice { padding: 12px 14px; border-radius: var(--r); font-size: .9rem; border: 1px solid var(--b1); background: var(--s2); }
.notice-err { background: var(--err2); border-color: color-mix(in srgb, var(--err) 30%, transparent); color: var(--t1); }
.notice-warn { background: var(--warn2); border-color: color-mix(in srgb, var(--ac) 40%, transparent); }
.notice ul { margin-top: 6px; padding-inline-start: 18px; }
.cmd { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; direction: ltr; background: var(--code-bg);
  border: 1px solid var(--b1); border-radius: 7px; padding: 2px 2px 2px 10px; }
.cmd code { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-copy { display: inline-grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 5px;
  background: none; color: var(--t3); cursor: pointer; }
.cmd-copy:hover { background: var(--s1); color: var(--t1); }
.cmd-copy .icon { width: 15px; height: 15px; }
.secret { display: block; font-family: var(--mono); font-size: 1rem; padding: 10px 12px; border-radius: var(--r);
  background: var(--code-bg); border: 1px solid var(--b1); word-break: break-all; direction: ltr; text-align: start; }
.secret-token { font-size: .875rem; margin: 12px 0; user-select: all; }
.link-text { display: block; font-family: var(--mono); font-size: .8125rem; color: var(--t2); word-break: break-all;
  direction: ltr; text-align: start; }
.hash { word-break: break-all; }

/* -- dialog and toast ----------------------------------------------------------------------- */
.dialog { margin: auto; width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); border: 1px solid var(--b1);
  border-radius: var(--r3); background: var(--s1); color: var(--t1); box-shadow: var(--shadow-lg); padding: 0; }
.dialog-wide { width: min(560px, calc(100vw - 24px)); }
.dialog { max-block-size: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow: hidden; }
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: rgba(20, 22, 30, .45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.dialog-head { display: flex; flex-shrink: 0; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 4px; }
.dialog-head h2 { overflow-wrap: anywhere; }
.dialog-body { padding: 8px 20px 20px; display: flex; flex: 1 1 auto; min-height: 0; flex-direction: column; gap: 12px; overflow-y: auto; overscroll-behavior: contain; }
.dialog-body > * { flex-shrink: 0; }
.dialog-footer { position: sticky; bottom: 0; z-index: 1; flex-shrink: 0; margin-top: 0; padding-block: 12px calc(6px + env(safe-area-inset-bottom)); background: var(--s1); border-top: 1px solid var(--b1); }
#toast { position: fixed; inset-inline: 0; bottom: max(20px, env(safe-area-inset-bottom)); display: flex;
  justify-content: center; pointer-events: none; z-index: 300; opacity: 0; transform: translateY(8px); visibility: hidden;
  transition: opacity .18s, transform .18s, visibility 0s .18s; }
#toast.show { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; }
#toast.show.has-action .toast { pointer-events: auto; }
.toast { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 99px; font-size: .9rem; font-weight: 600;
  box-shadow: var(--shadow-lg); max-width: calc(100vw - 32px); }
.toast-action { min-height: 32px; padding: 4px 12px; border: 1px solid currentColor; border-radius: 99px; background: none;
  color: inherit; font: inherit; cursor: pointer; }
.toast-action:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.toast-ok { background: var(--t1); color: var(--bg); }
.toast-error { background: var(--err); color: var(--on-err); }
.i18n-notice { position: fixed; z-index: 200; inset-inline: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; width: fit-content; max-width: calc(100% - 2rem); margin-inline: auto; font-size: .875rem; }
@media (pointer: coarse), (max-width: 640px) {
  button, .btn, .btn-sm, .btn-icon, .cmd-copy, [role="button"], .tab, .back, .top-brand, summary { min-height: 44px; min-width: 44px; }
  .btn-icon, .cmd-copy { width: 44px; height: 44px; }
  label:has(input[type="radio"]), label:has(input[type="checkbox"]) { min-height: 44px; }
}
@media (pointer: coarse) {
  summary { display: flex; align-items: center; }
}

/* Checkbox and radio rows, and the bordered group that holds them. */
.check-row { display: flex; align-items: center; gap: var(--space-2); min-block-size: 44px; cursor: pointer; }
.check-row > input[type="checkbox"], .check-row > input[type="radio"] { inline-size: 1.15rem; block-size: 1.15rem; margin: 0;
  flex: none; accent-color: var(--ac-ui); }
.choice-group { margin: 0; border: 1px solid var(--b1); border-radius: var(--r2); padding: .75rem; min-inline-size: 0; }
.choice-group > legend { color: var(--t2); font-weight: 600; padding-inline: .25rem; }
/* Toggletips: a 24 px info button (44 px hit area on phones and coarse pointers) and a viewport-fixed bubble. */
.tip { position: relative; display: inline-flex; vertical-align: middle; }
.tip-button { position: relative; display: inline-grid; place-items: center; inline-size: 24px; block-size: 24px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--t2); cursor: pointer; }
.tip-button .icon { width: 16px; height: 16px; }
.tip-button:hover, .tip-button[aria-expanded="true"] { color: var(--ac-text); background: var(--ac3); }
.tip-button:focus-visible { outline: 2px solid var(--ac-ui); outline-offset: 2px; }
.tip-bubble { position: fixed; z-index: 120; inline-size: max-content; max-inline-size: min(20rem, calc(100vw - 16px));
  padding: var(--space-2) var(--space-3); border: 1px solid var(--b2); border-radius: var(--r); background: var(--s1);
  color: var(--t1); box-shadow: var(--shadow-lg); font-family: var(--body); font-size: .875rem; font-weight: 400; line-height: 1.45;
  text-align: start; white-space: normal; text-transform: none; letter-spacing: normal; }
.tip-bubble[hidden] { display: none; }
.tip-bubble:focus { outline: none; }
/* The phone target rule sizes every button to 44 px; a tip keeps its 24 px face and gets that area from ::before. */
@media (pointer: coarse), (max-width: 640px) {
  .tip-button { min-height: 24px; min-width: 24px; }
  .tip-button::before { content: ""; position: absolute; inset: -10px; }
}
