/* Shared presentation contract, loaded after the section styles. */
:root {
  --border: var(--line);
  --panel: var(--surface);
  --text-muted: var(--muted);
  --accent-dim: var(--accent-soft);
  --radius: 12px;
}

html { scroll-padding-block: 24px; }
body { line-height: 1.6; }
h1, h2, h3, h4 { text-wrap: balance; }
h1, h2, h3, h4, [id] { scroll-margin-block-start: 24px; }
p, dd, li, .page-subtitle { overflow-wrap: anywhere; }
button, .button, summary, label, a { touch-action: manipulation; }
a, button, summary, input, select, textarea { scroll-margin-block: 16px; }
.muted { color: var(--muted); }

.page-heading, .panel-header, .section-header { min-width: 0; }
.page-heading > *, .panel-header > *, .section-header > * { min-width: 0; }
.heading-actions { flex-shrink: 1; flex-wrap: wrap; justify-content: flex-end; }
.panel-header { flex-wrap: wrap; gap: 12px; }
.panel-header h2 { overflow-wrap: anywhere; }
.panel > h2 { margin-bottom: 16px; }
.panel > p:last-child { margin-bottom: 0; }
.panel > details:last-child { margin-bottom: 0; }
.detail-page .page-back { margin-bottom: 0; }
.detail-page .toolbar, .detail-page .section-tabs { margin-bottom: 0; }
.detail-page .toolbar .field-help { margin: 0; }
.detail-panel .advanced-settings { margin-top: 20px; }
body:not(.detail-page):not(.provider-vm-page) .main-content > .panel + .panel { margin-top: 20px; }
.context-return { display: inline-flex; margin-top: 16px; }
.status-badge { max-width: 100%; white-space: normal; overflow-wrap: normal; }
.page-footer { gap: 8px 20px; }
.breadcrumb a { min-width: 0; overflow-wrap: anywhere; }
.provider-account-row > .button[data-open-dialog] { align-self: flex-start; min-height: 40px; }

/* Filtering has its own row; creating a record belongs to the page heading. */
.resource-list-page .toolbar { margin-bottom: 20px; }
.resource-list-page .search-form { flex: 1; flex-wrap: wrap; align-items: center; }
.resource-list-page .search-form input,
.resource-list-page .search-form select { margin: 0; width: auto; min-height: 42px; }
.resource-list-page .search-form input[type=search] { flex: 1 1 240px; max-width: 440px; min-width: 140px; }
.resource-list-page .search-form select { flex: 0 1 220px; max-width: 100%; }
.resource-list-page .search-form .button { flex: none; min-height: 42px; }
.resource-list-page .panel-header h2 { font-size: 15px; }
.resource-list-page .empty-state { border: 0; background: transparent; padding: 28px 16px; }
.resource-list-page .empty-state p { margin-bottom: 0; }
.resource-list-page .empty-state .button { margin-top: 16px; }

/* Dense data stays readable; long IDs never force the page wider. */
.table-wrap, .table-scroll { max-width: 100%; min-width: 0; overscroll-behavior-x: contain; }
.table-scroll { border: 1px solid var(--line); border-radius: 10px; scrollbar-width: thin; }
table caption { padding: 12px 16px; text-align: left; color: var(--muted); font-size: 12px; }
td, th { overflow-wrap: break-word; }
td a, td strong { overflow-wrap: anywhere; }
td > input[type=checkbox] { display: inline-block; margin: 0 6px 0 0; vertical-align: middle; }
td form { min-width: 0; }
.row-actions { gap: 8px 12px; align-items: center; }
.row-actions > a:not(.button) { min-height: 34px; align-items: center; white-space: nowrap; }
.price-line { white-space: normal; flex-wrap: wrap; gap: 4px 16px; }
.tariff-form .daily-price-editor tr { content-visibility: visible; contain-intrinsic-size: none; }
.table-footer { overflow-wrap: anywhere; }

/* Forms and selected choices share one size and one keyboard focus treatment. */
.app-page input:not([type=checkbox]):not([type=radio]):not([type=hidden]),
.app-page select { min-height: 42px; font-size: 14px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
label:has(> input[type=checkbox]):not(.server-option) {
  display: flex; flex-direction: row; align-items: flex-start; gap: 9px;
}
label > input[type=checkbox] { margin-top: 4px; }
.form-actions { gap: 10px; align-items: center; }
.form-actions > .button, .form-actions > button { max-width: 100%; }
.billing-type-card, .server-option { margin-bottom: 0; }
.catalog-fieldset > legend { margin-bottom: 8px; }
.provider-form label small { color: var(--muted); }
.infrastructure-form > .panel > h2 { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.infrastructure-form > .panel > label:last-child { margin-bottom: 0; }
.infrastructure-form .form-actions { margin-top: 0; }
.login-card { padding: 28px; }
.login-card > .muted:last-child { text-align: center; margin: 0; font-size: 12px; }
.login-card .primary { margin-bottom: 16px; }

/* Disclosure panels are compact when closed and spacious when expanded. */
.provider-section > summary { font-size: 16px; font-weight: 600; min-height: 32px; color: var(--text); }
.provider-section { padding: 18px 20px; }
.provider-section[open] > summary { margin-bottom: 16px; }
.advanced-settings > summary { min-height: 32px; }
.provider-overview-grid .panel, .provider-tabs ~ .account-overview { padding: 20px; }
.provider-overview-grid { gap: 16px; }
.provider-form .secret-toggle { min-height: 32px; }
.credentials-form .provider-form-actions { align-self: end; }
.credentials-form .provider-form-actions .button { min-height: 38px; font-size: 12px; }
.provider-finance .finance-caption { font-size: 12px; line-height: 1.6; }
.provider-finance .finance-details > summary,
.provider-finance .provider-topup > summary { min-height: 32px; font-size: 12px; line-height: 1.6; }
.expense-figure strong, .provider-finance .expense-figure strong,
.provider-finance .balance-badge strong { font-size: 20px; }
.provider-finance .expense-figure { padding: 10px; }
.expense-figure { flex-direction: column; align-items: flex-start; gap: 4px; }
.project-resource-heading { min-height: 34px; }
.project-summary-heading .button { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.sync-region-choices label { min-height: 32px; align-items: center; }
.sync-region-choices label > input[type=checkbox] { margin: 0; }
.vm-controls .button { min-height: 36px; }
.vm-password-status:empty, [data-copy-status]:empty { display: none; }
.node-title h3, .node-title > * { min-width: 0; overflow-wrap: anywhere; }
.server-stack:has(> .node-card:nth-child(51)) > .node-card { content-visibility: auto; contain-intrinsic-size: auto 240px; }

/* All confirmations have the same surface, spacing and close target. */
.provider-action-dialog, .server-action-dialog, .vm-control-dialog {
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto; padding: 24px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  overflow: auto; overscroll-behavior: contain; box-shadow: 0 20px 70px #0008;
}
dialog::backdrop { background: #03080db3; }
.dialog-heading, .server-dialog-heading { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; margin-bottom: 16px; }
.dialog-heading h2, .server-dialog-heading h2, .vm-control-dialog h2 { font-size: 20px; line-height: 1.4; margin: 0; }
.dialog-heading button[aria-label], .server-dialog-heading button[aria-label] { width: 40px; min-height: 40px; padding: 0; flex: none; font-size: 22px; }
.dialog-actions, .server-dialog-actions, .vm-control-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.provider-action-dialog .dialog-confirmation { align-items: flex-start; line-height: 1.6; }
.provider-action-dialog .dialog-confirmation input { margin-top: 4px; }

@media (max-width: 980px) {
  .heading-actions { justify-content: flex-start; }
  .server-page .page-heading { flex-wrap: wrap; }
  .server-page .heading-actions { margin-left: 0; }
}

@media (min-width: 781px) {
  .resource-list-page td:first-child { min-width: 120px; }
}

@media (max-width: 780px) {
  .main-content { padding-inline: max(16px, env(safe-area-inset-left)); }
  .page-heading > .button { align-self: flex-start; }
  .heading-actions { width: 100%; }
  .panel-header .button { min-height: 40px; }
  .provider-overview-grid .panel, .provider-tabs ~ .account-overview, .provider-section { padding: 16px; }
  .server-stack:has(> .node-card:nth-child(51)) > .node-card { contain-intrinsic-size: auto 300px; }
  .expense-figures { gap: 8px; }
  .expense-figure strong, .provider-finance .expense-figure strong { font-size: 18px; }

  /* Explicit roles in interface.js preserve table semantics in the card layout. */
  .responsive-table { display: block; width: 100%; min-width: 0; table-layout: auto; }
  .responsive-table > thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .responsive-table > tbody { display: grid; gap: 12px; padding: 0; }
  .responsive-table > tbody > tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px;
    padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  }
  .responsive-table > tbody > tr > td {
    display: block; min-width: 0; max-width: none; padding: 0; border: 0; font-size: 13px;
  }
  .responsive-table > tbody > tr > td::before {
    content: attr(data-label); display: block; margin-bottom: 4px;
    color: var(--muted); font-size: 12px; font-weight: 400;
  }
  .responsive-table > tbody > tr > td:first-child,
  .responsive-table > tbody > tr > td:last-child,
  .responsive-table > tbody > tr > td[colspan] { grid-column: 1 / -1; }
  .responsive-table td[colspan]::before { display: none; }
  .responsive-table td pre { max-width: none; }
  .coverage-editor.responsive-table { min-width: 0; }
  .coverage-editor.responsive-table > tbody { padding: 0; }
  .coverage-editor.responsive-table > tbody > tr { padding: 14px; border: 1px solid var(--line); }
  .coverage-editor.responsive-table > tbody > tr > td { width: auto; padding: 0; }
  .coverage-editor.responsive-table input, .coverage-editor.responsive-table select { min-width: 0; width: 100%; margin: 0; }
  .responsive-table .row-actions { align-items: flex-start; }
  .responsive-table .row-actions a, .responsive-table .row-actions button { min-height: 40px; }
  .responsive-table .row-actions details { margin: 0; }
  .table-wrap:has(> .responsive-table), .table-scroll:has(> .responsive-table) { background: transparent; border: 0; border-radius: 0; }

  /* Proxy addresses and every action fit on the screen without horizontal scrolling. */
  .proxy-table.responsive-table { min-width: 0; table-layout: auto; }
  .proxy-table.responsive-table > tbody > tr { grid-template-columns: 24px minmax(0, 1fr); gap: 12px; }
  .proxy-table.responsive-table > tbody > tr > td { width: auto; grid-column: 1 / -1; }
  .proxy-table.responsive-table > tbody > tr > .proxy-select-cell { grid-column: 1; grid-row: 1; padding-top: 2px; }
  .proxy-table.responsive-table > tbody > tr > .proxy-name-cell { grid-column: 2; grid-row: 1; font-size: 15px; }
  .proxy-table .proxy-select-cell::before, .proxy-table .proxy-name-cell::before { display: none; }
  .proxy-line-inline { grid-template-columns: minmax(0, 1fr); }
  .proxy-line-cell textarea { min-height: 68px; font-size: 13px; }
  .proxy-line-inline .button { min-height: 40px; padding: 8px 12px; font-size: 12px; }
  .proxy-actions { gap: 8px; }
  .proxy-actions .button { min-height: 40px; font-size: 12px; padding: 8px; }
}

@media (max-width: 520px) {
  .app-page input:not([type=checkbox]):not([type=radio]):not([type=hidden]),
  .app-page select, .app-page textarea, .auth-page input { font-size: 16px; }
  .button, button, .row-actions > a:not(.button) { min-height: 44px; }
  .resource-list-page .search-form input[type=search] { flex-basis: 100%; max-width: none; }
  .resource-list-page .search-form select { flex: 1 1 100%; }
  .resource-list-page .search-form .button { flex: 1; }
  .resource-list-page .heading-actions, .resource-list-page .page-heading > .button { width: 100%; }
  .responsive-table > tbody { gap: 8px; }
  .responsive-table > tbody > tr { padding: 14px; gap: 12px; }
  .section-tabs { gap: 4px; }
  .section-tabs a { padding: 9px 10px; min-height: 44px; }
  .form-actions > .primary, .form-actions > .danger { flex: 1 1 100%; }
  .form-actions > .ghost { flex: 1; }
  .provider-action-dialog, .server-action-dialog, .vm-control-dialog { padding: 20px; }
  .dialog-actions > .button, .server-dialog-actions > .button, .vm-control-dialog-actions > .button { flex: 1; }
  .expense-figures { grid-template-columns: minmax(0, 1fr); }
  .expense-figure { flex-direction: row; justify-content: space-between; align-items: center; }
  .provider-finance .expense-figure { padding: 10px 12px; }
  .sync-region-choices { gap: 4px 12px; }
  .sync-region-choices label { min-height: 40px; }
  .sync-selection-form > .button { width: 100%; }
  .provider-form .secret-input input { font-size: 16px; }
  .proxy-table .proxy-actions .button, .proxy-line-inline .button { min-height: 44px; }
  .proxy-heading-actions .primary { order: -1; flex-basis: 100%; }
  .proxy-heading-actions .ghost { flex: 1; }
  .provider-account-row > .account-summary-link { flex-basis: 100%; }
  .provider-account-row > .button[data-open-dialog] { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}

/* Provider accents are owner-selected; text contrast stays independent. */
.provider-badge{--provider-color:#60a5fa;color:var(--text);border-color:color-mix(in srgb,var(--provider-color) 60%,var(--line));background:color-mix(in srgb,var(--provider-color) 14%,var(--bg));gap:7px}
.provider-badge::before{content:"";width:8px;height:8px;border-radius:50%;background:var(--provider-color);flex:none}
a.provider-badge,a.server-name-badge{font-weight:700;min-height:32px;white-space:normal;overflow-wrap:anywhere;touch-action:manipulation}
a.provider-badge:hover{color:var(--text);border-color:var(--provider-color);background:color-mix(in srgb,var(--provider-color) 24%,var(--bg))}
.server-name-badge{color:#8ae8dd;background:#163733;border-color:#36635d}.server-name-badge:hover{color:#c0fff5;border-color:var(--accent);background:#204a43}
.provider-form-page .form-grid{grid-template-columns:repeat(3,minmax(0,1fr));align-items:start}.provider-form-page input[type="color"]{width:100%;height:44px;padding:5px;cursor:pointer}.provider-form-page .field{justify-content:flex-start;min-width:0}
@media(max-width:700px){.provider-form-page .form-grid{grid-template-columns:minmax(0,1fr)}a.provider-badge,a.server-name-badge{min-height:44px}}

/* Owner decision: action buttons use one accent; destructive actions use red.
   Emoji tiles retain their selected-state treatment. */
:is(button, .button):not(.display-emoji-option):not(.dns-domain-copy) {
  background: var(--accent);
  border-color: var(--accent);
  color: #08352e;
}
:is(button, .button):not(.display-emoji-option):not(.dns-domain-copy):not(:disabled):not([aria-disabled="true"]):hover {
  background: #67e4d2;
  border-color: #67e4d2;
  color: #08352e;
}
:is(button, .button).danger {
  background: #c43e4c;
  border-color: #c43e4c;
  color: #fff;
}
:is(button, .button).danger:not(:disabled):not([aria-disabled="true"]):hover {
  background: #b33240;
  border-color: #b33240;
  color: #fff;
}
:is(button, .button)[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

/* Environment is named in text as well as color. */
.brand strong{white-space:nowrap}
.brand-dev{color:#67e8a5;font-size:.72em}
.mobile-brand{display:none}
@media(max-width:900px){
  .nav-ready .mobile-brand{display:inline;color:inherit;font-size:12px}
  .nav-ready .menu-toggle{gap:8px}
  .nav-ready .sidebar .brand strong{font-size:21px}
}
