/* Design tokens. Every component below reads from these; avoid raw hex in rules. */
:root {
  color-scheme: light;

  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e3e8ee;
  /* Control borders (inputs, buttons) must clear 3:1 per WCAG 1.4.11 — they are
     what identifies the component. --border stays a decorative hairline. */
  --border-strong: #7d8b9f;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #6b7280;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --on-primary: #ffffff;

  --success: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;

  --ring: #2563eb;
  --scrim: rgba(15, 23, 42, .55);

  --sidebar: #111827;
  --sidebar-2: #1f2937;
  --sidebar-text: #cbd5e1;
  --sidebar-text-dim: #94a3b8;
  --sidebar-border: rgba(255, 255, 255, .08);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px; --s8: 40px;

  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-full: 999px;

  --e1: 0 1px 2px rgba(16, 24, 40, .05);
  --e2: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --e3: 0 4px 12px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .04);
  --e4: 0 20px 40px rgba(16, 24, 40, .16), 0 2px 8px rgba(16, 24, 40, .08);

  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px;
  --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px;

  --dur-fast: 120ms; --dur: 180ms;
  --ease: cubic-bezier(.2, .8, .3, 1);

  --topbar-h: 60px;
  --sidebar-w: 232px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
}

/* Dark theme is authored as its own set of pairs, not an inversion of the light
   values. Contrast is verified separately for each mode. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0b0f16;
    --surface: #131924;
    --surface-2: #1a212e;
    --surface-3: #212936;
    --border: #262e3d;
    --border-strong: #5d6878;
    --text: #e8edf5;
    --text-2: #a8b3c4;
    --text-3: #8592a6;

    --primary: #5b8dfa;
    --primary-hover: #7aa3fb;
    --primary-soft: #16233c;
    --primary-border: #2d4272;
    --on-primary: #0b0f16;

    --success: #4ade80;
    --success-soft: #112318;
    --success-border: #1f4d32;
    --warning: #fbbf24;
    --warning-soft: #241a08;
    --warning-border: #573f13;
    --danger: #f87171;
    --danger-hover: #fca5a5;
    --danger-soft: #2a1416;
    --danger-border: #5c2427;

    --ring: #7aa3fb;
    --scrim: rgba(2, 4, 8, .7);

    --sidebar: #0e131c;
    --sidebar-2: #1c2431;
    --sidebar-text: #b4c0d1;
    --sidebar-text-dim: #7d8a9d;
    --sidebar-border: rgba(255, 255, 255, .07);

    --e1: 0 1px 2px rgba(0, 0, 0, .4);
    --e2: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .3);
    --e3: 0 4px 12px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .3);
    --e4: 0 20px 40px rgba(0, 0, 0, .6), 0 2px 8px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base)/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* One focus treatment for the whole app. Components that sit flush against an
   edge override this with an inset ring rather than removing it. */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

svg { flex-shrink: 0; }
.icon { display: block; }

/* ---------- Login ---------- */

.login-shell { min-height: 100dvh; display: grid; place-items: center; padding: var(--s6); background: var(--bg); }
.login-panel { width: min(100%, 440px); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--e3); overflow: hidden; }
.brand-block { padding: var(--s7) var(--s7) var(--s6); background: var(--sidebar); color: #fff; }
.login-brand-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.login-brand-row .brand-mark { background: var(--primary); color: #fff; }
.login-badge { color: var(--sidebar-text); font-size: var(--fs-xs); padding: var(--s1) var(--s2); border: 1px solid var(--sidebar-border); border-radius: var(--r-full); }
.brand-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-md); background: var(--primary); color: #fff; font-weight: 700; }
.brand-name { margin: var(--s5) 0 var(--s2); font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.01em; }
.brand-copy { margin: 0; color: var(--sidebar-text); font-size: var(--fs-sm); line-height: 1.6; }
.login-form { padding: var(--s7); }
.login-heading { margin: 0 0 var(--s2); font-size: var(--fs-lg); font-weight: 650; }
.login-description { margin: 0 0 var(--s6); color: var(--text-3); font-size: var(--fs-sm); }
.login-form .field { margin-bottom: var(--s5); }
.login-form .field input, .login-form .button.full { min-height: 44px; }
.login-password { position: relative; }
.login-password input { padding-right: 68px; }
.password-toggle { position: absolute; right: var(--s1); top: 0; bottom: 0; padding: 0 var(--s3); border: 0; background: transparent; color: var(--primary); font-size: var(--fs-xs); font-weight: 600; border-radius: var(--r-sm); }
.password-toggle:focus-visible { outline-offset: -3px; }
.login-error { color: var(--danger); background: var(--danger-soft); border: 1px solid var(--danger-border); border-radius: var(--r-md); padding: var(--s3); margin: 0 0 var(--s4); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.login-scope { padding: var(--s3) var(--s5); border-top: 1px solid var(--border); color: var(--text-3); background: var(--surface-2); text-align: center; font-size: var(--fs-xs); }
.login-foot { color: var(--text-3); font-size: var(--fs-xs); margin: var(--s4) 0 0; line-height: 1.6; }
.login-tab { border: 0; padding: 0 0 var(--s2); color: var(--text-3); background: transparent; border-bottom: 2px solid transparent; }
.login-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- Form controls ---------- */

.field { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.field label { color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 9px var(--s3);
  background: var(--surface);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.field input:disabled, .field select:disabled, .field textarea:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  min-height: 36px;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  /* No transform on hover: buttons sit inside table rows and toolbars where a
     1px shift would nudge neighbouring content. */
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.button:hover { background: var(--surface-3); border-color: var(--border-strong); }
.button:active { background: var(--surface-3); box-shadow: inset 0 1px 2px rgba(16, 24, 40, .1); }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; box-shadow: var(--e1); }
.button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.button.danger { color: var(--danger); border-color: var(--danger-border); background: var(--danger-soft); }
.button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.button.compact { min-height: 30px; padding: var(--s1) var(--s2); font-size: var(--fs-xs); }
.button.full { width: 100%; min-height: 40px; }
.button:disabled { cursor: not-allowed; opacity: .5; box-shadow: none; }
.button:disabled:hover { background: var(--surface); border-color: var(--border-strong); }
.button.primary:disabled:hover { background: var(--primary); border-color: var(--primary); }

.icon-button {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.icon-button:hover { background: var(--surface-3); color: var(--text); }
.icon-button:disabled { cursor: not-allowed; opacity: .5; }

/* ---------- Workspace shell ---------- */

.workspace { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0;
  align-self: start;
  height: 100dvh;
  overflow-y: auto;
  padding: var(--s5) var(--s3);
  background: var(--sidebar);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
}
.sidebar .brand-row { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2) var(--s5); border-bottom: 1px solid var(--sidebar-border); }
.sidebar .brand-mark { width: 32px; height: 32px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.sidebar .brand-title { color: #fff; font-size: var(--fs-md); font-weight: 650; letter-spacing: -.01em; }
.sidebar .brand-subtitle { color: var(--sidebar-text-dim); font-size: var(--fs-xs); margin-top: 1px; }
.nav-group { padding-top: var(--s5); display: grid; gap: 2px; }
.nav-label { margin: 0 var(--s2) var(--s2); color: var(--sidebar-text-dim); font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--s3);
  width: 100%;
  border: 0; border-radius: var(--r-md);
  padding: var(--s2) var(--s3);
  color: var(--sidebar-text);
  background: transparent;
  text-align: left;
  font-size: var(--fs-base);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
/* Hover and active are deliberately distinct — hovering must never look like
   "you are here". */
.nav-item:hover { color: #fff; background: var(--sidebar-2); }
.nav-item.active { color: #fff; background: color-mix(in srgb, var(--primary) 20%, transparent); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 50%; translate: 0 -50%;
  width: 3px; height: 18px; border-radius: 0 var(--r-full) var(--r-full) 0;
  background: var(--primary);
}
.nav-item.active .nav-icon { color: var(--primary); }
.nav-item:focus-visible { outline-offset: -2px; }
.nav-icon { display: grid; place-items: center; width: 18px; color: var(--sidebar-text-dim); transition: color var(--dur-fast) var(--ease); }
.nav-item:hover .nav-icon { color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  min-height: var(--topbar-h);
  padding: var(--s3) var(--s6);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(12px);
}
.page-title { font-size: var(--fs-md); font-weight: 650; letter-spacing: -.01em; }
.page-note { margin-top: 1px; color: var(--text-3); font-size: var(--fs-xs); }
.account-menu { display: flex; align-items: center; gap: var(--s3); }
.account-id { color: var(--text-2); font-size: var(--fs-sm); }
.content { flex: 1; min-width: 0; padding: var(--s6); }

/* ---------- Metrics ---------- */

.summary-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--border); border-radius: var(--r-lg);
  overflow: hidden; background: var(--surface); box-shadow: var(--e2);
}
.metric { min-width: 0; padding: var(--s4) var(--s5); border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric-label { color: var(--text-3); font-size: var(--fs-xs); font-weight: 500; }
.metric-value { margin-top: var(--s2); overflow: hidden; font-size: var(--fs-xl); font-weight: 650; letter-spacing: -.01em; text-overflow: ellipsis; white-space: nowrap; }
.metric-value.small { font-size: var(--fs-md); }

/* ---------- Sections, tables ---------- */

.section { margin-top: var(--s6); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s3); gap: var(--s4); }
.section-title { margin: 0; font-size: var(--fs-md); font-weight: 650; }
.section-description { margin: 2px 0 0; color: var(--text-3); font-size: var(--fs-xs); }
.toolbar { display: flex; align-items: center; gap: var(--s2); }

.search { position: relative; width: 260px; }
.search .icon { position: absolute; left: var(--s3); top: 50%; translate: 0 -50%; color: var(--text-3); pointer-events: none; }
.search input {
  width: 100%;
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  padding: var(--s2) var(--s3) var(--s2) 34px;
  background: var(--surface); outline: none;
  font-size: var(--fs-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.search input::placeholder { color: var(--text-3); }
.search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--e2); }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 860px; }
th, td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
/* `.table-wrap` is the scroll container (overflow-x makes both axes scrollable),
   so the header sticks to the top of that box — top must stay 0 or it would
   float down over the first rows. */
th {
  position: sticky; top: 0; z-index: 1;
  color: var(--text-2); background: var(--surface-2);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
}
td { color: var(--text); font-size: var(--fs-sm); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover { background: var(--surface-2); }

.mono { font-family: var(--font-mono); font-size: var(--fs-xs); }
.muted { color: var(--text-3); }

.empty { display: grid; justify-items: center; gap: var(--s2); padding: var(--s8) var(--s4); color: var(--text-3); text-align: center; font-size: var(--fs-sm); }
.empty .icon { color: var(--border-strong); }
.empty-title { color: var(--text-2); font-size: var(--fs-base); font-weight: 600; }

/* Skeletons stand in for content while it loads so the layout does not jump. */
.skeleton-rows { display: grid; gap: var(--s3); padding: var(--s5); }
.skeleton {
  height: 14px; border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton:nth-child(even) { width: 78%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.tag {
  display: inline-flex; align-items: center;
  min-height: 22px; border-radius: var(--r-full);
  padding: 2px var(--s2);
  border: 1px solid transparent;
  font-size: var(--fs-xs); font-weight: 500;
}
.tag.success { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.tag.warning { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }
.tag.neutral { color: var(--text-2); background: var(--surface-3); border-color: var(--border); }

.action-row { display: flex; align-items: center; gap: var(--s3); white-space: nowrap; }
.link-action {
  display: inline-flex; align-items: center; gap: var(--s1);
  border: 0; padding: 0;
  color: var(--primary); background: transparent;
  font-size: var(--fs-xs); font-weight: 500;
  border-radius: var(--r-sm);
  transition: color var(--dur-fast) var(--ease);
}
.link-action:hover { color: var(--primary-hover); text-decoration: underline; }
.link-action.danger { color: var(--danger); }
.link-action.danger:hover { color: var(--danger-hover); }

.settings-tabs { display: flex; gap: var(--s5); margin-bottom: var(--s5); border-bottom: 1px solid var(--border); }
.field .json-editor { height: 320px; min-height: 160px; font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.6; tab-size: 2; }
.handler-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s5); }
.handler-fields label { overflow-wrap: anywhere; }
.handler-fields label span { display: block; font-weight: 400; }

/* ---------- Modal ---------- */

.modal-layer {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: var(--s5);
  background: var(--scrim);
  backdrop-filter: blur(2px);
  animation: layer-in var(--dur) var(--ease);
}
.modal {
  width: min(100%, 600px);
  max-height: calc(100dvh - var(--s8));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--e4);
  animation: modal-in var(--dur) var(--ease);
}
.modal.wide { width: min(100%, 800px); }
@keyframes layer-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; translate: 0 8px; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.modal-title { margin: 0; min-width: 0; font-size: var(--fs-md); font-weight: 650; overflow-wrap: anywhere; }
.close-button {
  display: grid; place-items: center;
  flex-shrink: 0;
  width: 32px; height: 32px;
  border: 0; border-radius: var(--r-md);
  color: var(--text-3); background: transparent;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.close-button:hover { background: var(--surface-3); color: var(--text); }
.modal-body { padding: var(--s5); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--border); background: var(--surface-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s4); }
.form-grid .wide-field { grid-column: 1 / -1; }

/* Domain availability card picker */
.domain-card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); margin-top: var(--s1); }
.domain-card {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: var(--s3) var(--s2);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); cursor: pointer; text-align: center;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.domain-card input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.domain-card:hover { border-color: var(--primary); background: var(--primary-soft); }
.domain-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 22%, transparent); }
.domain-card-tld { font-size: var(--fs-md); font-weight: 700; color: var(--text); line-height: 1.2; }
.domain-card-sld { font-size: var(--fs-xs); font-family: var(--font-mono); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.domain-card-price { margin-top: var(--s1); font-size: var(--fs-xs); font-weight: 600; color: var(--success); }
.domain-card:has(input:checked) .domain-card-tld { color: var(--primary); }
.domain-card:has(input:checked) .domain-card-price { color: var(--primary); }
.switch-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); margin: var(--s2) 0 var(--s5); }
.switch-control { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); font-size: var(--fs-sm); }
.switch-control input { width: 38px; height: 20px; accent-color: var(--primary); }

.notice { margin: 0 0 var(--s4); padding: var(--s3); border: 1px solid var(--primary-border); border-left: 3px solid var(--primary); border-radius: var(--r-md); background: var(--primary-soft); color: var(--text-2); font-size: var(--fs-xs); line-height: 1.6; }
.detail-list { display: grid; grid-template-columns: 130px 1fr; gap: var(--s2) var(--s4); margin: 0; font-size: var(--fs-sm); }
.detail-list dt { color: var(--text-3); }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.required { color: var(--danger); }

.toast {
  position: fixed; right: var(--s6); bottom: var(--s6); z-index: 50;
  max-width: min(420px, calc(100vw - var(--s8)));
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  color: #fff; background: #1f2937;
  border: 1px solid rgba(255, 255, 255, .1);
  box-shadow: var(--e4);
  font-size: var(--fs-sm);
  opacity: 0; translate: 0 12px;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), translate var(--dur) var(--ease);
}
.toast.show { opacity: 1; translate: 0 0; }
.toast.error { background: var(--danger); border-color: transparent; color: #fff; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- APP management pages ---------- */

.contract-transfer-actions { display: flex; gap: var(--s2); }
.contract-import-summary { margin-top: var(--s4); padding: var(--s3); border: 1px solid var(--success-border); border-radius: var(--r-md); background: var(--success-soft); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.contract-import-summary p { margin-bottom: 0; }

.content:has(.contract-page) { padding: var(--s5) var(--s6); }
.contract-page { min-width: 0; }
.contract-page h2 { margin: 0; font-size: var(--fs-base); font-weight: 650; }

.contract-page-toolbar {
  display: flex; align-items: center; gap: var(--s4);
  margin-bottom: var(--s4);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--e1);
}
.contract-app-picker { display: flex; flex: 1; align-items: center; gap: var(--s3); min-width: 180px; max-width: 480px; margin: 0; }
.contract-app-picker label { white-space: nowrap; }
.contract-app-picker select { min-width: 0; padding: var(--s2) var(--s3); font-size: var(--fs-sm); }
.contract-save-state { display: grid; gap: 1px; font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; }
.contract-save-state small { font-size: var(--fs-xs); }
.contract-page-actions { display: flex; gap: var(--s2); margin-left: auto; white-space: nowrap; }

.contract-section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s3); }
.contract-section-head > .muted { font-size: var(--fs-xs); }

.contract-configuration {
  display: grid;
  grid-template-columns: minmax(300px, .85fr) minmax(0, 2.15fr);
  align-items: stretch; gap: var(--s4);
  min-height: 554px;
  height: calc(100dvh - var(--topbar-h) - 128px);
}
.contract-mappings, .contract-event-card, .contract-interface-list, .contract-response-panel {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--e1);
  min-width: 0;
}
.contract-mappings { display: flex; flex-direction: column; padding: var(--s4); overflow-y: auto; }
.contract-mappings .contract-section-head { margin-bottom: var(--s1); }
.contract-mapping-help { margin: 0 0 var(--s2); color: var(--text-3); font-size: var(--fs-xs); }

.contract-field-group { display: flex; flex-direction: column; }
.contract-field-group:first-of-type { flex: 2; }
.contract-field-group:last-of-type { flex: 1; margin-top: var(--s2); }
.contract-field-group h3 { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin: 0; padding: var(--s2) 0; font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); }
.contract-field-group h3 span { font-size: var(--fs-xs); font-weight: 400; color: var(--text-3); }

.contract-mapping-row { display: grid; grid-template-columns: minmax(106px, 1fr) minmax(90px, 1fr); flex: 1; align-items: center; gap: var(--s2); min-height: 44px; padding: var(--s1) 0; }
.contract-mapping-row label { min-width: 0; }
.contract-mapping-row label > span { font-weight: 600; }
.contract-mapping-row small { display: block; color: var(--text-3); font-size: var(--fs-xs); line-height: 1.45; overflow-wrap: anywhere; }
.contract-mapping-row input { width: 100%; min-width: 0; border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: var(--s2); background: var(--surface); font-size: var(--fs-xs); outline: none; transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.contract-mapping-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }

.contract-events { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); gap: var(--s4); min-width: 0; }
.contract-event-card { display: flex; flex-direction: column; padding: var(--s4); }
.contract-event-heading { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 2px var(--s2); margin-bottom: var(--s3); }
.contract-event-heading .mono { font-size: var(--fs-xs); }
.contract-event-body { display: flex; flex-direction: column; gap: var(--s2); margin: 0; flex: 1; min-height: 0; }
.contract-event-hint { font-size: var(--fs-xs); color: var(--text-3); }
.contract-event-hint.invalid { color: var(--danger); }
.contract-code[aria-invalid="true"] { border-color: var(--danger); }

.contract-insert { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1); }
.contract-insert > span { font-size: var(--fs-xs); color: var(--text-3); margin-right: 2px; }
.contract-insert .token-button {
  min-height: 26px; padding: 2px var(--s2);
  border-radius: var(--r-sm);
  font: var(--fs-xs)/1.4 var(--font-mono);
  background: var(--primary-soft); border-color: var(--primary-border); color: var(--primary);
}
.contract-insert .token-button:hover { background: color-mix(in srgb, var(--primary) 14%, var(--surface)); border-color: var(--primary); }

.field .contract-code { font: var(--fs-xs)/1.6 var(--font-mono); tab-size: 2; background: var(--surface-2); border-radius: var(--r-md); }
.contract-event-body .contract-code { min-height: 120px; flex: 1; resize: none; padding: var(--s2); }

.contract-interfaces { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: var(--s4); min-height: 554px; height: calc(100dvh - var(--topbar-h) - 128px); }
.contract-interface-list { display: flex; flex-direction: column; overflow: hidden; }
.contract-interface-list .contract-section-head { padding: var(--s4); margin: 0; border-bottom: 1px solid var(--border); }
.contract-interface-items { overflow-y: auto; padding: var(--s2); }
.contract-interface-item {
  width: 100%; display: grid; gap: var(--s1);
  text-align: left;
  padding: var(--s3);
  margin-bottom: 2px;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.contract-interface-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contract-interface-item:hover { background: var(--surface-2); }
.contract-interface-item.active { border-color: var(--primary-border); background: var(--primary-soft); color: var(--primary); }
.contract-interface-item:focus-visible { outline-offset: -2px; }

.contract-response-panel { padding: var(--s4); display: flex; flex-direction: column; }
.contract-endpoint-options { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: var(--s3); }
.contract-endpoint-options input, .contract-endpoint-options select { font-size: var(--fs-sm); }
.contract-response-field { display: flex; flex-direction: column; flex: 1; margin-bottom: 0; min-height: 0; gap: var(--s2); }
.contract-response-field .contract-code { flex: 1; resize: none; min-height: 200px; font-size: var(--fs-sm); }
.contract-draft-note { font-size: var(--fs-xs); color: var(--warning); margin: calc(-1 * var(--s1)) 0 var(--s3); }
.contract-editor { padding: 0; margin: 0; border: 0; min-width: 0; }
.contract-error { padding: var(--s3); margin-bottom: var(--s4); color: var(--danger); background: var(--danger-soft); border: 1px solid var(--danger-border); border-radius: var(--r-md); font-size: var(--fs-sm); overflow-wrap: anywhere; }

.contract-help {
  position: fixed; z-index: 35;
  right: 0; top: var(--topbar-h); bottom: 0;
  width: min(380px, 100vw);
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--e4);
}
.contract-help header { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.contract-help header h2 { font-size: var(--fs-md); }
.contract-help header p { margin: 2px 0 0; font-size: var(--fs-xs); color: var(--text-3); }
.contract-help-body { overflow-y: auto; padding: var(--s4) var(--s5); }
.contract-help h3 { font-size: var(--fs-sm); font-weight: 650; padding-bottom: var(--s2); border-bottom: 1px solid var(--border); }
.contract-help article { margin: var(--s3) 0 var(--s4); }
.contract-help article code { color: var(--primary); font-family: var(--font-mono); font-size: var(--fs-xs); }
.contract-help article p { margin: 2px 0; font-size: var(--fs-xs); }
.contract-help article small { color: var(--text-3); font-size: var(--fs-xs); }

/* ---------- Audit ---------- */

.audit-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s4);
  padding: var(--s5) var(--s6);
  border-bottom: 1px solid var(--border);
}
.audit-filters .field { min-width: 0; margin: 0; }
.audit-filter-actions { display: flex; align-items: end; gap: var(--s2); padding-bottom: 1px; }
.audit-pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: var(--s4) var(--s6); color: var(--text-3); font-size: var(--fs-sm); }
.audit-time { min-width: 168px; }
.audit-error { color: var(--danger); padding: 0 var(--s6) var(--s3); font-size: var(--fs-sm); }
.audit-metadata { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: var(--s2) var(--s5); margin: 0 0 var(--s6); font-size: var(--fs-sm); }
.audit-metadata dt { color: var(--text-3); }
.audit-metadata dd { margin: 0; overflow-wrap: anywhere; }
.audit-detail h3 { font-size: var(--fs-base); font-weight: 650; margin: var(--s6) 0 var(--s3); }
.audit-detail pre { max-height: 360px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border: 1px solid var(--border); padding: var(--s4); border-radius: var(--r-md); font-family: var(--font-mono); font-size: var(--fs-xs); }

/* ---------- Responsive ---------- */

/* Short-but-wide viewports (1366x768 laptops) can no longer stack all ten
   mapping rows in one column, because rows now honour the 44px touch floor and
   the 12px type floor. Widen the panel and let the two field groups sit side by
   side so every field stays on screen without an inner scrollbar. */
@media (min-width: 1151px) and (max-height: 860px) {
  .contract-configuration { grid-template-columns: minmax(430px, 1.4fr) minmax(0, 1.6fr); }
  .contract-mappings { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2) var(--s5); align-content: start; align-items: start; }
  .contract-mappings .contract-section-head, .contract-mapping-help { grid-column: 1 / -1; }
  .contract-field-group { min-width: 0; }
  .contract-field-group:first-of-type, .contract-field-group:last-of-type { flex: none; margin-top: 0; }
  .contract-mapping-row { flex: none; }
}

@media (max-width: 1150px) {
  .contract-page-toolbar { flex-wrap: wrap; gap: var(--s3); }
  .contract-configuration { height: auto; grid-template-columns: 1fr; }
  .contract-mappings { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3) var(--s5); }
  .contract-mappings .contract-section-head, .contract-mapping-help { grid-column: 1 / -1; }
  .contract-field-group:last-of-type { margin-top: 0; justify-content: flex-start; }
  .contract-field-group:last-of-type .contract-mapping-row { flex: none; }
  .contract-events { grid-template-rows: repeat(2, 290px); }
  .contract-endpoint-options { grid-template-columns: 1fr; }
}

@media (max-width: 880px) {
  /* minmax(0, 1fr) rather than 1fr: a bare 1fr keeps an auto min-content floor,
     so the nav strip's full content width would inflate the column past the
     viewport and .nav-group's overflow-x could never engage. */
  .workspace { grid-template-columns: minmax(0, 1fr); }
  /* The sidebar becomes a horizontally scrollable tab strip pinned directly
     under the topbar, so navigation stays reachable on long pages. */
  .sidebar {
    position: sticky; top: var(--topbar-h); z-index: 29;
    min-width: 0;
    height: auto; overflow: visible;
    padding: var(--s2) var(--s3);
    border-right: 0; border-bottom: 1px solid var(--sidebar-border);
    order: -1;
  }
  .sidebar .brand-row, .sidebar .nav-label { display: none; }
  .nav-group {
    display: flex; gap: var(--s1);
    padding: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .nav-group::-webkit-scrollbar { display: none; }
  .nav-item { width: auto; flex: 0 0 auto; justify-content: center; min-height: 40px; padding: var(--s2) var(--s4); white-space: nowrap; }
  .nav-item.active::before { left: 50%; top: auto; bottom: 0; translate: -50% 0; width: 20px; height: 2px; border-radius: var(--r-full) var(--r-full) 0 0; }

  .content { padding: var(--s4); }
  .topbar { padding: var(--s3) var(--s4); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--border); }

  .contract-page-actions { flex-wrap: wrap; }
  .contract-interfaces { grid-template-columns: 190px minmax(0, 1fr); }
  .contract-help { top: 0; z-index: 45; }
}

@media (max-width: 680px) {
  .modal-foot { flex-wrap: wrap; }
}

@media (max-width: 600px) {
  .topbar:has(.contract-transfer-actions) { gap: var(--s2); padding: var(--s3); }
  .topbar:has(.contract-transfer-actions) .account-menu { gap: var(--s2); }
  .contract-transfer-actions { gap: var(--s1); }
  .contract-transfer-actions .button { font-size: var(--fs-xs); padding: var(--s2); }
  .audit-filters { grid-template-columns: 1fr; padding: var(--s4); }
  .audit-metadata { grid-template-columns: 1fr; gap: var(--s1); }
  .audit-metadata dd { margin-bottom: var(--s3); }
  .audit-pagination { padding: var(--s4); flex-wrap: wrap; }
  .audit-error { padding: 0 var(--s4) var(--s3); }
}

@media (max-width: 560px) {
  .section-header { align-items: stretch; flex-direction: column; }
  .handler-fields { grid-template-columns: 1fr; }
  .settings-tabs { gap: var(--s4); }
  .field .json-editor { height: 260px; }
  .login-shell { padding: 0; background: var(--surface); }
  .login-panel { border: 0; border-radius: 0; box-shadow: none; }
  .brand-block, .login-form { padding-left: var(--s5); padding-right: var(--s5); }
  .summary-grid, .form-grid, .switch-row { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--border); }
  .metric:last-child { border-bottom: 0; }
  .toolbar { flex-wrap: wrap; }
  .search { width: 100%; }
  .account-id { display: none; }
  .form-grid .wide-field { grid-column: auto; }

  .content:has(.contract-page) { padding: var(--s3); }
  .contract-page-toolbar { padding: var(--s3); }
  .contract-app-picker { max-width: none; flex-basis: 100%; }
  .contract-page-actions { margin-left: 0; }
  .contract-mappings, .contract-events, .contract-interfaces { grid-template-columns: 1fr; }
  .contract-events { grid-template-rows: none; grid-auto-rows: 300px; }
  .contract-interfaces { height: auto; }
  .contract-interface-items { max-height: 190px; }
  .contract-response-field .contract-code { min-height: 280px; }
  .contract-mappings .contract-section-head { grid-column: auto; }
  .contract-field-group:last-of-type { margin-top: var(--s2); }
  .toast { right: var(--s3); left: var(--s3); bottom: var(--s3); max-width: none; }
}

/* Touch devices get comfortable hit areas regardless of viewport width. */
@media (pointer: coarse) {
  .icon-button, .close-button { width: 44px; height: 44px; }
  .nav-item { min-height: 44px; }
  .link-action { min-height: 44px; }
  .button { min-height: 44px; }
  .button.compact { min-height: 36px; }
  .contract-insert .token-button { min-height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
