/* ============================================================
   Kotsch.Works — Component & Layout Library ("Engineering Console")
   Technical / blueprint aesthetic. Reproduces every legacy class
   from the old layout so all existing pages inherit the new look.
   Depends on tokens.css.
   ============================================================ */

/* ---------- Reset & base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg-base);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.65;
    overflow-x: hidden;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color .16s var(--ease-out); }
a:hover { color: var(--primary-strong); }
img { max-width: 100%; height: auto; }
p { margin: 0 0 1.1rem; color: var(--muted); }

h1, h2, h3, h4 {
    margin: 0 0 1rem;
    color: var(--text);
    line-height: 1.05;
    letter-spacing: -0.02em;
    font-family: var(--font-display);
    font-weight: 700;
}
h1 { font-size: clamp(2.5rem, 7vw, 5rem); }
h2 { font-size: clamp(1.85rem, 4vw, 2.9rem); }
h3 { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; }

.lead { max-width: 760px; color: var(--muted); font-size: clamp(1.05rem, 2vw, 1.2rem); }

/* Eyebrow = monospace technical label */
.eyebrow {
    display: inline-block;
    margin-bottom: 0.85rem;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}
.eyebrow::before { content: "// "; opacity: 0.7; }

/* ---------- Accessibility helpers ---------- */
.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: var(--z-modal);
    padding: 0.7rem 1.1rem; border: 1px solid var(--accent);
    border-radius: var(--radius-sm); background: var(--surface-strong);
    color: var(--text); font-family: var(--font-mono); font-weight: 600;
}
.skip-link:focus { left: 1rem; top: 1rem; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* ---------- Technical grid backdrop + 3D scene ---------- */
.aurora-bg {
    position: fixed; inset: 0; z-index: -2; pointer-events: none; overflow: hidden;
    background-color: var(--bg-base);
    background-image:
        linear-gradient(var(--line) 1px, transparent 1px),
        linear-gradient(90deg, var(--line) 1px, transparent 1px);
    background-size: 46px 46px;
    background-position: center;
}
.aurora-bg::before {
    /* signal glow at top */
    content: ""; position: absolute; inset: 0;
    background:
        radial-gradient(70vw 50vh at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
        radial-gradient(60vw 50vh at 85% 110%, color-mix(in srgb, var(--primary) 12%, transparent), transparent 60%);
}
.aurora-bg::after {
    /* vignette so the grid fades at the edges */
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(130vw 120vh at 50% 30%, transparent 45%, var(--bg-deep) 100%);
}

.scene-canvas {
    position: fixed; inset: 0; width: 100%; height: 100%;
    z-index: var(--z-scene); pointer-events: none; display: block;
    opacity: 0; transition: opacity 1.2s ease;
}
.scene-canvas.is-ready { opacity: 0.85; }

/* ---------- Header / Navigation (console bar) ---------- */
.site-header {
    position: sticky; top: 0; z-index: var(--z-header);
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg-base) 97%, transparent);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}
.site-header .header-inner {
    max-width: 1180px; min-height: 60px; margin: 0 auto;
    padding: 0 1.25rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand {
    display: inline-flex; align-items: center; gap: 0.6rem;
    color: var(--text); font-family: var(--font-mono);
    font-size: 0.98rem; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap;
}
.brand:hover { color: var(--text); }
.main-nav { display: flex; align-items: center; justify-content: flex-end; gap: 0.15rem; }
.main-nav a,
.logout-link {
    position: relative;
    min-height: 2.3rem; display: inline-flex; align-items: center;
    padding: 0.35rem 0.8rem; border: 0; border-radius: var(--radius-sm);
    background: transparent; color: var(--muted);
    font-family: var(--font-mono); font-size: 0.82rem; font-weight: 500;
    letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
    transition: color .16s var(--ease-out), background .16s var(--ease-out);
}
.main-nav a:hover,
.main-nav a.active,
.logout-link:hover { color: var(--text); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.main-nav a.active { color: var(--accent); }
.main-nav a.active::after {
    content: ""; position: absolute; left: 0.8rem; right: 0.8rem; bottom: 0.18rem;
    height: 2px; background: var(--accent);
}
.header-actions { display: flex; align-items: center; gap: 0.5rem; }
.theme-toggle,
.menu-toggle {
    width: 2.35rem; height: 2.35rem; display: inline-grid; place-items: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); background: var(--surface);
    cursor: pointer; transition: border-color .16s var(--ease-out), color .16s var(--ease-out);
}
.theme-toggle:hover, .menu-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg, .menu-toggle svg { width: 1.1rem; height: 1.1rem; }
.menu-toggle { display: none; }

/* ---------- Layout shells ---------- */
.page-main { min-height: calc(100dvh - 220px); position: relative; z-index: var(--z-base); }
.page-shell, .wide-shell { max-width: 1180px; margin: 0 auto; padding: 5.5rem 1.25rem; }
.narrow-shell { max-width: 920px; margin: 0 auto; padding: 5.5rem 1.25rem; }
.section-band {
    position: relative;
    border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
}
.section-kicker {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 2rem; margin-bottom: 2.35rem;
}
.section-kicker p { max-width: 600px; margin-bottom: 0; }

/* ---------- Grids ---------- */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------- Cards (flat technical panels w/ corner ticks) ---------- */
.card,
.ak-card {
    position: relative;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}
.card { padding: 1.55rem; }
.card p:last-child { margin-bottom: 0; }
/* blueprint corner ticks */
.card::before,
.card::after,
.ak-card::before,
.ak-card::after {
    content: ""; position: absolute; width: 11px; height: 11px;
    border-color: var(--line-2); border-style: solid; pointer-events: none;
    transition: border-color .2s var(--ease-out);
}
.card::before, .ak-card::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.card::after,  .ak-card::after  { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }

.card,
.ak-card,
.button,
.tag,
.status,
.glass-tile {
    transition: transform .18s var(--ease-out), border-color .18s var(--ease-out),
                box-shadow .18s var(--ease-out), background .18s var(--ease-out), color .16s var(--ease-out);
}
.card:hover,
.ak-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
    box-shadow: var(--shadow);
}
.card:hover::before, .card:hover::after,
.ak-card:hover::before, .ak-card:hover::after { border-color: var(--accent); }

.service-card { min-height: 100%; }
.project-card { display: flex; flex-direction: column; min-height: 100%; }
.project-card .button { margin-top: auto; align-self: flex-start; }

/* ---------- Buttons ---------- */
.button-row { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 1.85rem; }
.button {
    min-height: 2.85rem; display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem; padding: 0.7rem 1.25rem;
    border: 1px solid var(--accent); border-radius: var(--radius-sm);
    color: #03130f; background: var(--accent);
    font-family: var(--font-mono); font-size: 0.85rem; font-weight: 600;
    letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
    touch-action: manipulation;
}
.button:hover { color: #03130f; background: var(--accent-strong); border-color: var(--accent-strong); box-shadow: var(--glow); transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button.secondary {
    color: var(--text); background: transparent; border-color: var(--border);
}
.button.secondary:hover { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); box-shadow: none; }

/* ---------- Tags / status / notice ---------- */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 1.1rem 0; }
.tag, .status {
    display: inline-flex; align-items: center; gap: 0.4rem; width: fit-content;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 0.24rem 0.6rem; color: var(--muted); background: var(--surface-soft);
    font-family: var(--font-mono); font-size: 0.74rem; font-weight: 500; letter-spacing: 0.04em;
}
.status { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.status::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%;
    background: var(--accent); box-shadow: 0 0 8px var(--accent);
}
.notice {
    border: 1px solid var(--border); border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm); background: var(--surface);
    padding: 1rem 1.15rem; margin-bottom: 1.5rem;
}
pre, code, kbd, samp { font-family: var(--font-mono); }
pre {
    overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--code-bg); padding: 1rem; font-size: 0.9rem;
}

/* ---------- Forms ---------- */
.glass-input,
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]),
select, textarea {
    width: 100%; min-height: 2.85rem; padding: 0.65rem 0.9rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit;
    transition: border-color .16s var(--ease-out), box-shadow .16s var(--ease-out);
}
input::placeholder, textarea::placeholder { color: var(--subtle); }
input:focus, select:focus, textarea:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none;
}
label { font-family: var(--font-mono); font-size: 0.85rem; font-weight: 500; color: var(--text); letter-spacing: 0.03em; }

/* ---------- Tables ---------- */
.glass-table { width: 100%; border-collapse: collapse; }
.glass-table th, .glass-table td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); text-align: left; }
.glass-table th { color: var(--subtle); font-family: var(--font-mono); font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Footer ---------- */
.site-footer {
    position: relative; z-index: var(--z-base); margin-top: 2rem;
    border-top: 1px solid var(--border); background: var(--surface);
    color: var(--muted);
}
.footer-inner {
    max-width: 1180px; margin: 0 auto; padding: 2.4rem 1.25rem;
    display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 2rem; align-items: start;
}
.footer-inner strong { color: var(--text); font-family: var(--font-mono); letter-spacing: 0.02em; }
.footer-links { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; justify-content: flex-end; }
.footer-links a { color: var(--muted); font-family: var(--font-mono); font-size: 0.82rem; }
.footer-links a:hover { color: var(--accent); }

/* ---------- Reveal-on-scroll ---------- */
.reveal-on-scroll { opacity: 0; transform: translateY(18px); transition: opacity .55s var(--ease-out), transform .55s var(--spring); will-change: opacity, transform; }
.reveal-on-scroll.is-visible { opacity: 1; transform: none; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
        scroll-behavior: auto !important; transition-duration: 0.001ms !important;
    }
    .reveal-on-scroll { opacity: 1; transform: none; }
    .scene-canvas { display: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .main-nav {
        display: none; position: absolute; top: 100%; left: 0; right: 0;
        align-items: stretch; flex-direction: column;
        border-bottom: 1px solid var(--border);
        background: color-mix(in srgb, var(--bg-base) 96%, transparent);
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
        padding: 0.5rem 1rem 0.8rem;
    }
    .main-nav.open { display: flex; }
    .main-nav a, .logout-link { justify-content: flex-start; width: 100%; }
    .main-nav a.active::after { display: none; }
    .menu-toggle { display: inline-grid; }
    .site-header .header-inner { position: relative; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .section-kicker { align-items: flex-start; flex-direction: column; }
    .page-shell, .wide-shell, .narrow-shell { padding: 4rem 1rem; }
    .footer-inner { grid-template-columns: 1fr; }
    .footer-links { justify-content: flex-start; }
}
@media (max-width: 560px) {
    h1 { font-size: clamp(2.1rem, 12vw, 3.1rem); }
    .button { width: 100%; }
}

/* ---------- Rich content defaults (inner / content pages) ---------- */
/* Give bare content real structure so pages don't read as empty/minimal. */

/* Headings inside content shells get a technical accent marker */
.page-shell h2,
.narrow-shell h2 { position: relative; padding-left: 0.9rem; }
.page-shell h2::before,
.narrow-shell h2::before {
    content: ""; position: absolute; left: 0; top: 0.12em; bottom: 0.12em;
    width: 3px; border-radius: 2px; background: var(--accent);
}
.section-kicker h2 { padding-left: 0; }
.section-kicker h2::before { display: none; }

/* Lists with signal markers */
.page-shell :is(ul, ol):not(.main-nav):not(.footer-links),
.narrow-shell :is(ul, ol):not(.main-nav):not(.footer-links) { margin: 0 0 1.2rem; padding-left: 1.35rem; }
.page-shell li,
.narrow-shell li { margin: 0.4rem 0; }
.page-shell ul li::marker,
.narrow-shell ul li::marker { color: var(--accent); }

/* Bare HTML tables (legacy pages) become technical data tables */
table { width: 100%; border-collapse: collapse; margin: 0 0 1.5rem; }
table:not(.table):not(.grid-view) {
    border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;
}
table:not(.table):not(.grid-view) th,
table:not(.table):not(.grid-view) td {
    padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border); text-align: left;
}
table:not(.table):not(.grid-view) thead th {
    background: var(--surface-soft); color: var(--muted);
    font-family: var(--font-mono); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
}
table:not(.table):not(.grid-view) tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }

/* Quotes, dividers, inline code */
blockquote {
    margin: 1.5rem 0; padding: 0.9rem 1.2rem;
    border: 1px solid var(--border); border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface); color: var(--muted);
}
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
:not(pre) > code {
    padding: 0.12em 0.42em; border: 1px solid var(--border); border-radius: 4px;
    background: var(--surface-soft); color: var(--accent-strong); font-size: 0.9em;
}

/* Inner content readability: limit prose line length */
.narrow-shell p,
.page-shell > p { max-width: 72ch; }
