/*
 * Shared web UI stylesheet (WEB_UI_PROMPTS.md Phases 1–6).
 * Linked from resources/views/layouts/app.blade.php before @stack('styles'), so page styles still override.
 * No build step: plain CSS, tokens only. Views should use these custom properties, not new hex values or pixel font sizes.
 */

:root {
    /* Colours */
    --bg: #1e1e1e;
    --panel: #252526;
    --panel-2: #2d2d30;
    --border: #3e3e42;
    --input-bg: #3c3c3c;
    --hover: #2a2d2e;
    --text: #d4d4d4;
    /*
     * --muted was #858585 (4.52:1 on --bg, 4.15:1 on --panel). #959595 gives
     * 5.57:1 on --bg #1e1e1e, 5.11:1 on --panel #252526, 4.58:1 on --panel-2 #2d2d30
     * (WCAG 2.x relative-luminance ratios, calculated for Phase 1).
     */
    --muted: #959595;
    --accent: #3794ff;
    /* Focus ring: 6.60:1 on --bg, 6.06:1 on --panel, 4.37:1 on --input-bg (non-text needs 3:1). */
    --focus: #58a6ff;
    --critical: #f14c4c;
    --warning: #cca700;
    --info: #4ec9b0;
    --ok: #89d185;
    --ok-border: #3a5f38;
    --button-bg: #0e639c;
    --button-border: #1177bb;
    --on-strong: #fff;     /* text on --button-bg / --critical */
    --on-light: var(--bg); /* text on --warning / --info */
    --overlay: rgba(0, 0, 0, .5);
    /* Log level palette (Logs page, Phase 4): the colours the standalone viewer used. */
    --log-critical: #ff0000;
    --log-error: #f48771;
    --log-warning: #dcdcaa;
    --log-notice: #569cd6;
    --log-info: var(--info);
    --log-debug: var(--muted);
    --log-project: #c586c0;
    --log-context: #ce9178;

    /* Type */
    --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --text-xs: 12px;
    --text-sm: 13px;
    --text-md: 14px;
    --text-lg: 16px;
    --text-xl: 20px;
    --text-2xl: 24px;

    /* Spacing and shape */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --radius: 4px;

    /* Shell (Phase 2). Breakpoints used below: 600 / 768 / 1024. */
    --sidebar-width: 220px;
    --topbar-height: 52px;
    --control-height: 32px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: var(--text-md);
    line-height: 1.5;
}

a { color: var(--accent); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

/* Controls */
button, .button {
    background: var(--button-bg);
    border: 1px solid var(--button-border);
    color: var(--on-strong);
    min-height: var(--control-height);
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: var(--text-sm);
    font-family: inherit;
    line-height: 1.4;
    text-decoration: none;
}
.button { display: inline-flex; align-items: center; }
button.secondary, .button.secondary { background: var(--input-bg); border-color: var(--border); color: var(--text); }
button:disabled { opacity: .5; cursor: default; }
/* Compact size for dense table actions only. */
.button-sm, button.button-sm { min-height: 24px; padding: 2px 8px; font-size: var(--text-xs); }

select, textarea, input:not([type="checkbox"]):not([type="radio"]) {
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text);
    min-height: var(--control-height);
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-family: inherit;
    line-height: 1.4;
}
/* A long option label never pushes a select wider than its container (Phase 3). */
select { max-width: 100%; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--accent); vertical-align: middle; }

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

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .02em; }
/* Long unbroken values (URLs, ids, CVE titles) wrap instead of widening the table. */
td { overflow-wrap: anywhere; }

/*
 * Responsive tables (Phase 3): every table sits in .table-wrap, which scrolls sideways on its own
 * so the page never does. The min-width stops columns crushing; .table-wrap-sm is for 2–4 column
 * tables inside panels. Edge shadows show only while there is more to scroll (background-attachment trick).
 */
.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    background:
        linear-gradient(to right, var(--surface, var(--bg)) 30%, transparent) left / 24px 100% no-repeat local,
        linear-gradient(to left, var(--surface, var(--bg)) 30%, transparent) right / 24px 100% no-repeat local,
        radial-gradient(farthest-side at 0 50%, var(--overlay), transparent) left / 10px 100% no-repeat scroll,
        radial-gradient(farthest-side at 100% 50%, var(--overlay), transparent) right / 10px 100% no-repeat scroll;
}
.table-wrap > table { min-width: 640px; }
.table-wrap-sm > table { min-width: 320px; }
.panel .table-wrap { --surface: var(--panel); }

/* Text and status */
.muted { color: var(--muted); }
.error { color: var(--critical); }
.badge { display: inline-block; padding: 1px 6px; border-radius: var(--radius); font-size: var(--text-xs); font-weight: 600; }
.sev-critical { background: var(--critical); color: var(--on-strong); }
.sev-warning { background: var(--warning); color: var(--on-light); }
.sev-info { background: var(--info); color: var(--on-light); }
.state-firing { color: var(--critical); font-weight: 600; }
.state-recovering { color: var(--warning); }
.state-pending { color: var(--muted); }
.state-normal { color: var(--ok); }

/* Blocks */
.banner { padding: var(--space-2) var(--space-3); border-radius: var(--radius); margin-bottom: var(--space-3); }
.banner.degraded { background: rgba(241, 76, 76, .15); border: 1px solid var(--critical); }
.banner.unknown { background: rgba(204, 167, 0, .15); border: 1px solid var(--warning); }
.banner.ok { background: rgba(137, 209, 133, .08); border: 1px solid var(--ok-border); }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); margin-bottom: var(--space-3); }
/* min() keeps a single column from overflowing when the content is narrower than 260px. */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: var(--space-3); }
.grid > * { min-width: 0; }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 3px 10px; }
.kv dt { color: var(--muted); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }
pre, code, kbd, samp { font-family: var(--font-mono); font-size: var(--text-sm); }
pre { white-space: pre-wrap; word-break: break-word; background: var(--panel-2); padding: var(--space-2); border-radius: var(--radius); }

/* ---------- Shared page patterns (Phases 5–6) ---------- */

/* Short explanation under the top bar title. */
.page-intro { margin-bottom: var(--space-3); color: var(--muted); }

/* Summary tiles (Attention, Active Alerts). */
.summary { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-3); }
.tile { min-width: 150px; padding: var(--space-2) var(--space-4); background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.tile .n { font-size: var(--text-xl); font-weight: 600; }
.tile.hot .n { color: var(--critical); }

/*
 * Filter rows: each .filter is a label above its control. Pages with more than four filters keep
 * the main ones in the row and put the rest in .more-filters, whose summary shows how many hidden
 * filters are set (updateMoreFilters() in the layout script). .clear-filters shows only when a filter is set.
 */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.filter { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.filter > label, .filter-label { color: var(--muted); font-size: var(--text-xs); }
.filter.grow { flex: 1 1 220px; }
.check-label { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--control-height); }
.clear-filters[hidden] { display: none; }
.more-filters { margin-bottom: var(--space-3); }
.more-filters summary { display: inline-flex; align-items: center; min-height: var(--control-height); color: var(--muted); font-size: var(--text-sm); cursor: pointer; }
.more-filters > .filters { margin: var(--space-1) 0 0; }

/* Toolbars: freshness and refresh controls above a table, or pagination below it. */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.toolbar .spacer { flex: 1; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: var(--space-2) 0 var(--space-3); }

/* Empty, loading and error states: "Loading…", "No … match these filters.", "Failed to load: …". */
.empty { padding: var(--space-4) var(--space-3); color: var(--muted); }
td.empty { padding: var(--space-3) var(--space-2); }
.empty.error { color: var(--critical); }

/* Small inline facts: uppercase status words, warning notes and outlined flags (text, not colour alone). */
.status { font-weight: 600; text-transform: uppercase; font-size: var(--text-xs); }
.note-warn { color: var(--warning); font-size: var(--text-xs); }
.sub { margin-top: 2px; color: var(--muted); font-size: var(--text-sm); }
.flag { display: inline-block; padding: 0 6px; border: 1px solid currentColor; border-radius: var(--radius); font-size: var(--text-xs); font-weight: 600; line-height: 1.5; white-space: nowrap; }
.flag-critical { color: var(--critical); }
.stack-top { margin-top: var(--space-3); }
/* Forms: JSON editors, help disclosures, action rows under a form. */
.code-input { display: block; width: 100%; margin: var(--space-2) 0; font-family: var(--font-mono); }
.help { margin: var(--space-2) 0; }
.form-actions { margin: var(--space-2) 0 0; }
.note-form { margin-bottom: var(--space-2); }
.note-form textarea { display: block; width: 100%; margin-bottom: var(--space-2); }

/* Heading on detail pages (alert, monitor) under their back link. */
.detail-title { margin: var(--space-2) 0 var(--space-1); }

/* Charts (Services metrics, Uptime monitor). */
.metric-chart { display: block; width: 100%; height: auto; }

/* Monitor states and uptime levels (Uptime list and monitor pages; class maps in uptime/script.blade.php). */
.state-down { color: var(--critical); }
.state-failing { color: var(--warning); }
.state-unknown, .state-paused { color: var(--muted); }
.state-up { color: var(--ok); }
.uptime-good { color: var(--ok); }
.uptime-degraded { color: var(--warning); }
.uptime-bad { color: var(--critical); }
.cert-warning { color: var(--warning); }
.cert-critical, .cert-expired { color: var(--critical); font-weight: 600; }

/* ---------- Shell: sidebar + content (Phase 2) ---------- */

.shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.sidebar .brand {
    display: block;
    padding: var(--space-4) var(--space-4) var(--space-3);
    color: var(--text);
    font-size: var(--text-lg);
    font-weight: 600;
    text-decoration: none;
}
.sidebar nav { flex: 1; padding: 0 var(--space-2) var(--space-3); }
.nav-group + .nav-group { margin-top: var(--space-3); }
.nav-heading {
    padding: var(--space-1) var(--space-2);
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
}
.nav-group ul { list-style: none; }
.nav-group a {
    display: flex;
    align-items: center;
    min-height: var(--control-height);
    padding: var(--space-1) var(--space-2);
    border-left: 3px solid transparent;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
}
.nav-group a:hover { background: var(--hover); }
.nav-group a[aria-current="page"] { background: var(--hover); border-left-color: var(--accent); color: var(--accent); font-weight: 600; }

.sidebar-foot { padding: var(--space-3) var(--space-4) var(--space-4); border-top: 1px solid var(--border); }
.sidebar-foot .user { display: block; margin-bottom: var(--space-2); color: var(--muted); font-size: var(--text-sm); overflow-wrap: anywhere; }

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--topbar-height);
    padding: var(--space-2) var(--space-5);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.topbar .page-title { flex: 1; min-width: 0; font-size: var(--text-lg); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.menu-button { display: none; }

main { flex: 1; min-width: 0; padding: var(--space-5); overflow-wrap: break-word; }
code { overflow-wrap: anywhere; }

.nav-overlay { position: fixed; inset: 0; z-index: 30; background: var(--overlay); }
.nav-overlay[hidden] { display: none; }

/* Under 1024px the sidebar is an off-canvas drawer opened from the top bar. */
@media (max-width: 1023.98px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(var(--sidebar-width), 85vw);
        height: auto;
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform .2s ease, visibility .2s;
    }
    body.nav-open .sidebar { transform: none; visibility: visible; }
    body.nav-open { overflow: hidden; }
    .menu-button { display: inline-flex; align-items: center; }
}

/* ---------- Guest pages: centred card (layouts/guest.blade.php, Phase 4) ---------- */

.guest-main { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: var(--space-4); }
.auth-card { width: 100%; max-width: 400px; padding: var(--space-6); background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.brand-icon { display: inline-block; width: 32px; height: 32px; margin-right: 10px; border-radius: 7px; vertical-align: middle; flex-shrink: 0; }
.auth-card .brand { margin-bottom: var(--space-1); font-size: var(--text-2xl); font-weight: 600; text-align: center; }
.auth-card .lead { margin-bottom: var(--space-5); color: var(--muted); text-align: center; }
.field { margin-bottom: var(--space-4); }
.field label { display: block; margin-bottom: var(--space-1); }
.field input { width: 100%; }
.check { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.auth-card button[type="submit"] { width: 100%; font-weight: 600; }
.auth-card .banner p + p { margin-top: var(--space-1); }
@media (max-width: 599.98px) {
    .auth-card { padding: var(--space-5) var(--space-4); }
}

/* Small screens: 16px gutters and touch-sized controls. */
@media (max-width: 767.98px) {
    .topbar { padding: var(--space-2) var(--space-4); }
    main { padding: var(--space-4); }
}

/* Under 600px key/value lists stack the label above its value. */
@media (max-width: 599.98px) {
    .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .kv dt:not(:first-child) { margin-top: var(--space-2); }
    /* Filters go two to a row with full-width controls. */
    .filter, .filter.grow { flex: 1 1 140px; }
    .filter select, .filter input:not([type="checkbox"]):not([type="radio"]) { width: 100%; }
}

@media (max-width: 767.98px) {
    button, .button, .button-sm, button.button-sm, select, textarea,
    input:not([type="checkbox"]):not([type="radio"]), .nav-group a, .check-label, .more-filters summary {
        min-height: 44px;
    }
}

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