/* ==========================================================================
   Nusa Farm UI — compatibility layer
   1. Maps the old per-page tokens (--background-color, --panel-bg, …) onto the
      Modern theme tokens, so page CSS written against them re-themes itself.
      Pages must NOT redefine these in their own :root.
   2. Low-specificity (:where) element defaults that replace what
      terminal.min.css used to provide. Any page/class rule overrides them.
   ========================================================================== */

:root {
    --global-font-size: var(--fs);
    --global-line-height: 1.45em;
    --global-space: 10px;
    --font-stack: var(--font-ui);
    --mono-font-stack: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --page-width: 1100px;

    --background-color: var(--bg);
    --font-color: var(--text);
    --invert-font-color: var(--on-primary);
    --secondary-color: var(--text-2);
    --tertiary-color: var(--text-3);
    --primary-color: var(--primary);
    --primary-dim: color-mix(in srgb, var(--primary) 80%, #000);
    --error-color: var(--bad);
    --success-color: var(--ok);
    --warning-color: var(--warn);
    --code-bg-color: var(--surface);
    --block-background-color: var(--surface);
    --progress-bar-background: var(--surface-2);
    --progress-bar-fill: var(--primary);
    --input-style: solid;
    --display-h1-decoration: none;

    --panel-bg: var(--surface);
    --panel-border: var(--border);
    --panel-header: var(--surface-2);
    --input-bg: var(--bg);
    --input-border: var(--border-strong);
    --input-focus: var(--primary);
    --glow: rgba(90, 169, 255, .08);
    --glow-md: rgba(90, 169, 255, .16);
    --glow-lg: rgba(90, 169, 255, .06);
    --divider: var(--border);
}

::selection { background: var(--primary); color: var(--on-primary); }

/* ── Element defaults (previously terminal.min.css) ────────────────────── */
/* bare links only — component links (cards, buttons, nav) keep their own colour */
:where(.content) a:not([class]) { color: var(--primary); }
:where(.content) h2, :where(.content) h3, :where(.content) h4 { font-weight: 600; }
:where(.content) p { margin: 0 0 .8em; }
:where(.content) img { max-width: 100%; }
:where(.content) hr { border: 0; border-bottom: 1px solid var(--border); margin: 24px 0; }
:where(.content) code { font-family: var(--mono-font-stack); background: var(--surface-2); padding: 1px 5px; border-radius: var(--radius-xs); font-size: .9em; }
:where(.content) pre { font-family: var(--mono-font-stack); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; overflow-x: auto; }

:where(.content) table { width: 100%; border-collapse: collapse; color: var(--text); font-size: .92em; }
:where(.content) th, :where(.content) td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; text-align: left; }
:where(.content) thead th { font-weight: 600; color: var(--text-2); background: var(--surface-2); vertical-align: middle; }
:where(.content) td { font-variant-numeric: tabular-nums; }

:where(.content) fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0; }
:where(.content) legend { padding: 0 6px; font-size: .78em; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--primary); }
:where(.content) label { color: var(--text-2); }

/* type filter inside :where() so the rule stays at element specificity (0,0,1); a bare
   :not() chain would weigh (0,6,1) and override page rules like .fld-input */
:where(.content) input:where(:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=submit]):not([type=button])),
:where(.content) select,
:where(.content) textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-variant-numeric: tabular-nums;
}
:where(.content) textarea { resize: vertical; }
:where(.content) input:focus, :where(.content) select:focus, :where(.content) textarea:focus {
    outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary);
}
:where(.content) input::placeholder, :where(.content) textarea::placeholder { color: var(--text-3); opacity: 1; }
:where(.content) input[type=checkbox], :where(.content) input[type=radio] { accent-color: var(--primary); }
:where(.content) input:-webkit-autofill { -webkit-box-shadow: 0 0 0 40px var(--bg) inset; -webkit-text-fill-color: var(--text); }

:where(.content) .form { width: 100%; }
:where(.content) .form-group { margin-bottom: 14px; }

/* terminal.css button variants still used by some pages */
.btn-block { display: flex; width: 100%; }
.btn-small { padding: 6px 12px !important; min-height: 32px; font-size: .8em !important; }
.btn-ghost { background: transparent; }
.btn-default { background: var(--surface-2); color: var(--text); }
.btn-error { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-error.btn-ghost { background: transparent; color: var(--bad); }
.btn-primary.btn-ghost { background: transparent; color: var(--primary); }

.terminal-alert { padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); margin-bottom: 10px; }
.terminal-alert-error { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: var(--bad-soft); }
.terminal-alert-primary { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 45%, transparent); background: var(--primary-soft); }

.progress-bar { height: 8px; background: var(--surface-2); border-radius: 4px; margin: 12px 0; overflow: hidden; }
.progress-bar-filled { height: 100%; background: var(--primary); transition: width .3s ease; }

/* ── Shared page helpers for migrated pages ─────────────────────────────── */
/* .main is the content wrapper most legacy pages used; keep it centred. */
.content > .main { width: 100%; max-width: var(--page-width); margin: 0 auto; padding: 0; }
