/*
 * The app's standard modal: dark card, one blue, the same backdrop, header,
 * footer and buttons everywhere. Loaded on every page by the base layouts.
 * Open and close modals with UIModal (js/universal_modal.js).
 *
 *   <div id="x-modal" class="ui-modal-backdrop" aria-hidden="true">
 *     <div class="ui-modal ui-modal--md" role="dialog" aria-modal="true" aria-labelledby="x-modal-title">
 *       <div class="ui-modal-header">
 *         <div>
 *           <h3 class="ui-modal-title" id="x-modal-title">Title</h3>
 *           <p class="ui-modal-subtitle">Optional one line.</p>
 *         </div>
 *         <button type="button" class="ui-modal-close" data-ui-modal-close aria-label="Close">…</button>
 *       </div>
 *       <div class="ui-modal-body">…</div>
 *       <div class="ui-modal-footer">
 *         <button type="button" class="ui-btn ui-btn--secondary" data-ui-modal-close>Cancel</button>
 *         <button type="button" class="ui-btn ui-btn--primary">Confirm</button>
 *       </div>
 *     </div>
 *   </div>
 *
 * Add data-ui-modal-static to the backdrop when a stray click outside must
 * not close it (forms with input, destructive confirms). Esc still closes.
 *
 * Variables are prefixed --ui- so they cannot collide with the page-level
 * variables the redesigned pages define for themselves.
 */
:root {
  --ui-bg-surface:   #21252e;
  --ui-bg-elevated:  #272b35;
  --ui-bg-card:      #2d323d;
  --ui-bg-inset:     #1a1d23;
  --ui-border:       rgba(255,255,255,0.08);
  --ui-border-strong: rgba(255,255,255,0.14);
  --ui-text-primary:   #eef0f4;
  --ui-text-secondary: #b4b9c6;
  --ui-text-muted:     #8b90a0;
  --ui-blue:       #4d8ef0;
  --ui-blue-hover: #3b7ce0;
  --ui-blue-dim:   rgba(77,142,240,0.14);
  --ui-green:  #34d399;
  --ui-yellow: #fbbf24;
  --ui-red:    #f87171;
  --ui-red-solid: #dc2626;
  --ui-red-solid-hover: #b91c1c;
}

/* The page behind an open modal does not scroll. */
html.ui-modal-locked, html.ui-modal-locked body { overflow: hidden; }

/* ── Backdrop and card ── */
.ui-modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 70;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(3px);
  overflow-y: auto;
}
.ui-modal-backdrop.is-open { display: flex; }

.ui-modal {
  display: flex; flex-direction: column;
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px); margin: auto;
  background: var(--ui-bg-elevated); color: var(--ui-text-primary);
  border: 1px solid var(--ui-border-strong); border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
  font-family: 'DM Sans', 'Inter', sans-serif;
  animation: ui-modal-in 0.16s ease both;
}
.ui-modal:focus { outline: none; }
@keyframes ui-modal-in { from { opacity: 0; transform: scale(0.97) translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .ui-modal { animation: none; } }

.ui-modal--sm { max-width: 400px; }
.ui-modal--md { max-width: 560px; }
.ui-modal--lg { max-width: 720px; }
.ui-modal--xl { max-width: 960px; }

/* Header and footer stay put; only the body scrolls. */
.ui-modal-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 18px 20px 14px; border-bottom: 1px solid var(--ui-border); flex-shrink: 0;
}
.ui-modal-title { font-size: 16px; font-weight: 700; line-height: 1.3; color: var(--ui-text-primary); margin: 0; }
.ui-modal-subtitle { font-size: 12.5px; color: var(--ui-text-muted); margin: 4px 0 0; line-height: 1.45; }
.ui-modal-close {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
  background: transparent; border: 1px solid var(--ui-border-strong); color: var(--ui-text-muted);
  transition: background 0.12s, color 0.12s;
}
.ui-modal-close:hover { background: var(--ui-bg-card); color: var(--ui-text-primary); }
.ui-modal-close svg { width: 12px; height: 12px; }

.ui-modal-body {
  padding: 18px 20px; overflow-y: auto; flex: 1 1 auto; min-height: 0;
  font-size: 13.5px; line-height: 1.55; color: var(--ui-text-secondary);
  word-wrap: break-word;
}
.ui-modal-body > * + * { margin-top: 12px; }

.ui-modal-footer {
  display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-shrink: 0;
  padding: 14px 20px; border-top: 1px solid var(--ui-border);
  background: var(--ui-bg-surface); border-radius: 0 0 12px 12px;
}

/* Message modals: the heading takes the colour of what happened. */
.ui-modal-title.is-success { color: var(--ui-green); }
.ui-modal-title.is-error   { color: var(--ui-red); }
.ui-modal-title.is-warning { color: var(--ui-yellow); }
.ui-modal-title.is-info    { color: var(--ui-blue); }

/* ── Buttons ── */
.ui-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: 8px; cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: inherit; white-space: nowrap;
  border: 1px solid transparent; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.ui-btn:focus-visible { outline: 2px solid var(--ui-blue); outline-offset: 2px; }
.ui-btn:disabled, .ui-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.ui-btn--primary { background: var(--ui-blue); color: #fff; }
.ui-btn--primary:hover:not(:disabled) { background: var(--ui-blue-hover); }
.ui-btn--secondary { background: transparent; color: var(--ui-text-primary); border-color: var(--ui-border-strong); }
.ui-btn--secondary:hover:not(:disabled) { background: var(--ui-bg-card); }
.ui-btn--danger { background: var(--ui-red-solid); color: #fff; }
.ui-btn--danger:hover:not(:disabled) { background: var(--ui-red-solid-hover); }
/* Text-only action inside a body, e.g. "Copy IPs". */
.ui-link-btn {
  background: none; border: none; padding: 0; cursor: pointer; font: inherit;
  font-size: 12px; font-weight: 600; color: var(--ui-blue);
}
.ui-link-btn:hover { text-decoration: underline; }

/* ── Body building blocks ── */

/* A tinted box for a group of related lines, e.g. "What This Means". */
.ui-callout {
  padding: 12px 14px; border-radius: 8px; font-size: 13px;
  background: var(--ui-bg-card); border: 1px solid var(--ui-border);
  color: var(--ui-text-secondary);
}
.ui-callout-title { font-size: 13px; font-weight: 700; color: var(--ui-text-primary); margin: 0 0 6px; }
.ui-callout-note { font-size: 12px; color: var(--ui-text-muted); }
.ui-callout ul { margin: 0; padding: 0; list-style: none; }
.ui-callout li + li { margin-top: 4px; }
.ui-callout--info    { background: rgba(77,142,240,0.08);  border-color: rgba(77,142,240,0.3); }
.ui-callout--info .ui-callout-title    { color: var(--ui-blue); }
.ui-callout--success { background: rgba(52,211,153,0.08);  border-color: rgba(52,211,153,0.3); }
.ui-callout--success .ui-callout-title { color: var(--ui-green); }
.ui-callout--warning { background: rgba(251,191,36,0.08);  border-color: rgba(251,191,36,0.32); }
.ui-callout--warning .ui-callout-title { color: var(--ui-yellow); }
.ui-callout--danger  { background: rgba(248,113,113,0.08); border-color: rgba(248,113,113,0.32); }
.ui-callout--danger .ui-callout-title  { color: var(--ui-red); }

/* Colour for a single word or line inside a body. */
.ui-text-success { color: var(--ui-green); }
.ui-text-warning { color: var(--ui-yellow); }
.ui-text-danger  { color: var(--ui-red); }
.ui-text-info    { color: var(--ui-blue); }
.ui-text-muted   { color: var(--ui-text-muted); }

/* Inline code and value chips (an IP, a hostname pattern). */
.ui-code {
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 0.92em;
  padding: 1px 5px; border-radius: 4px;
  background: var(--ui-bg-inset); border: 1px solid var(--ui-border); color: var(--ui-text-primary);
}
.ui-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ui-chip {
  display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 5px;
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px;
  background: var(--ui-bg-inset); border: 1px solid var(--ui-border-strong); color: var(--ui-text-primary);
}

/* "Label   old → new" rows for review-before-saving screens. */
.ui-change { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.ui-change + .ui-change { margin-top: 8px; }
.ui-change-label { font-weight: 600; color: var(--ui-text-primary); }
.ui-change-values { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ui-change-from { text-decoration: line-through; color: var(--ui-text-muted); }
.ui-change-to { font-weight: 700; color: var(--ui-text-primary); }

/* Radio cards: one choice out of a few, each with a line of explanation. */
.ui-options { display: flex; flex-direction: column; gap: 10px; }
.ui-option {
  display: flex; gap: 12px; padding: 14px; border-radius: 10px; cursor: pointer;
  background: var(--ui-bg-card); border: 1px solid var(--ui-border-strong);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.ui-option:hover { border-color: rgba(77,142,240,0.5); }
.ui-option input[type="radio"] { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--ui-blue); flex-shrink: 0; }
.ui-option.is-selected { border-color: var(--ui-blue); box-shadow: 0 0 0 1px var(--ui-blue); background: var(--ui-blue-dim); }
.ui-option.is-disabled { opacity: 0.5; cursor: not-allowed; }
.ui-option.is-disabled:hover { border-color: var(--ui-border-strong); }
.ui-option-title { display: block; font-size: 13.5px; font-weight: 600; color: var(--ui-text-primary); }
.ui-option-detail { display: block; font-size: 12.5px; color: var(--ui-text-muted); margin-top: 3px; }

/* Help documents passed to showHelpModal are free-form HTML. */
.ui-modal-help { color: var(--ui-text-secondary); }
.ui-modal-help h3 { color: var(--ui-text-primary); }
.ui-modal-help a { color: var(--ui-blue); }
.ui-modal-help code { color: var(--ui-text-primary); }
