/* Arena Monitor — shared stylesheet, in the style of the CoreUI admin template.

   Layout: a fixed dark sidebar with section titles, a white sticky header with a
   breadcrumb row, a light grey page, white cards with header bars, and a footer.
   Colours are CoreUI's (primary indigo, danger, warning, success, info), with a
   light and a dark colour mode chosen from the header.

   The variable names below are the ones every template already uses. The plain
   state colours (--red, --yellow, --green, --blue) are safe for text on the
   current background; the -fill versions are CoreUI's swatches for solid
   surfaces such as widgets, badges and primary buttons. */

:root,
:root[data-theme="light"] {
    color-scheme: light;

    --bg: #f3f4f7;            /* page */
    --bg2: #ffffff;           /* cards, header, footer */
    --bg3: #f3f4f7;           /* table heads, chips, nested forms */
    --field: #ffffff;         /* inputs */
    --navy: #212631;          /* sidebar */
    --border: #dbdfe6;
    --border-bright: #b9bec7;

    --text-bright: #1b1f27;
    --text: #333b48;
    --text-dim: #6b7785;

    --primary: #5856d6;
    --primary-hover: #4644ab;
    --primary-text: #5856d6;

    --red: #d93737;
    --yellow: #9a6700;
    --green: #177d33;
    --blue: #1f6fbf;
    --code: #d63384;

    --shadow: 0 0.5rem 1rem rgb(8 10 12 / 0.15);
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #1d2129;
    --bg2: #252a34;
    --bg3: #2c323d;
    --field: #21262f;
    --navy: #1a1d24;
    --border: #3a4150;
    --border-bright: #4c5465;

    --text-bright: #f1f2f4;
    --text: #d5d8de;
    --text-dim: #9aa1ad;

    --primary: #5856d6;
    --primary-hover: #6d6be0;
    --primary-text: #a3a2f5;

    --red: #f47c7c;
    --yellow: #f9b115;
    --green: #4cc574;
    --blue: #6cb6ff;
    --code: #e685b5;

    --shadow: 0 0.5rem 1rem rgb(0 0 0 / 0.45);
}

:root {
    --red-fill: #e55353;
    --yellow-fill: #f9b115;
    --green-fill: #1b9e3e;
    --blue-fill: #3399ff;

    --red-tint: color-mix(in srgb, var(--red-fill) 12%, transparent);
    --red-line: color-mix(in srgb, var(--red-fill) 45%, transparent);
    --yellow-tint: color-mix(in srgb, var(--yellow-fill) 16%, transparent);
    --yellow-line: color-mix(in srgb, var(--yellow-fill) 55%, transparent);
    --green-tint: color-mix(in srgb, var(--green-fill) 12%, transparent);
    --green-line: color-mix(in srgb, var(--green-fill) 45%, transparent);
    --blue-tint: color-mix(in srgb, var(--blue-fill) 12%, transparent);
    --blue-line: color-mix(in srgb, var(--blue-fill) 45%, transparent);
    --primary-tint: color-mix(in srgb, var(--primary) 25%, transparent);
    --hover: color-mix(in srgb, var(--text-bright) 4%, transparent);
    --card-cap: color-mix(in srgb, var(--text-bright) 3%, var(--bg2));

    --sidebar-width: 256px;
    --sidebar-text: rgb(255 255 255 / 0.6);
    --sidebar-title: rgb(255 255 255 / 0.38);
    --sidebar-line: rgb(255 255 255 / 0.075);
    --sidebar-hover: rgb(255 255 255 / 0.05);

    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif;
    --display: var(--sans);
    --mono: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

    --r-panel: 6px;
    --r-control: 6px;
    --r-chip: 4px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--primary-text); text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
code { font-family: var(--mono); font-size: 0.875em; color: var(--code); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ── Sidebar ───────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1035;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--navy);
    color: var(--sidebar-text);
    transition: transform 0.2s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 64px;
    padding: 0 16px;
    border-bottom: 1px solid var(--sidebar-line);
}
.sidebar-brand a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #ffffff;
    text-decoration: none;
    font-size: 18px;
    font-weight: 600;
}
.sidebar-brand svg { flex-shrink: 0; }
.sidebar-close {
    display: none;
    margin-left: auto;
    background: none;
    border: 0;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 6px;
}
.sidebar-close:hover { color: #ffffff; }

.sidebar-nav { flex: 1; overflow-y: auto; padding-bottom: 16px; scrollbar-color: rgb(255 255 255 / 0.2) transparent; }
.nav-title {
    padding: 12px 16px 8px;
    margin-top: 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--sidebar-title);
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14.5px;
    line-height: 1.3;
    cursor: pointer;
    list-style: none;
}
.nav-link:hover { color: #ffffff; background: var(--sidebar-hover); }
.nav-link.active { color: #ffffff; background: var(--sidebar-hover); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.75; }
.nav-link:hover .nav-icon, .nav-link.active .nav-icon { opacity: 1; }
.nav-dot {
    width: 18px;
    display: inline-flex;
    justify-content: center;
    flex-shrink: 0;
}
.nav-dot::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: 0.6; }

.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary .nav-caret { margin-left: auto; opacity: 0.6; transition: transform 0.15s; }
.nav-group[open] { background: rgb(0 0 0 / 0.2); }
.nav-group[open] > summary { color: #ffffff; }
.nav-group[open] > summary .nav-caret { transform: rotate(90deg); }
.nav-group .nav-link:not(summary) { padding-left: 16px; font-size: 14px; }

/* ── Header ────────────────────────────────────────── */
.wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-left: var(--sidebar-width);
    transition: padding-left 0.2s ease;
}
.header {
    position: sticky;
    top: 0;
    z-index: 1020;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}
.header-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    padding: 0 24px;
}
.header-toggler, .header-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: -8px;
    border: 0;
    border-radius: var(--r-control);
    background: none;
    color: var(--text-dim);
    cursor: pointer;
    list-style: none;
}
.header-icon-btn { margin-left: 0; }
.header-toggler:hover, .header-icon-btn:hover { color: var(--text-bright); }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.header .vr { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.monitor-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.monitor-pill:hover { color: var(--text-bright); border-color: var(--border-bright); }

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.dropdown { position: relative; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 1030;
    min-width: 180px;
    padding: 6px 0;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--r-panel);
    box-shadow: var(--shadow);
}
.dropdown-header {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    background: var(--card-cap);
    border-bottom: 1px solid var(--border);
    margin: -6px 0 6px;
    white-space: nowrap;
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 16px;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.dropdown-item:hover { background: var(--bg3); color: var(--text-bright); }
.dropdown-item.active { background: var(--primary); color: #ffffff; }

.header-crumbs { border-top: 1px solid var(--border); padding: 10px 24px; }
.breadcrumb { display: flex; flex-wrap: wrap; list-style: none; font-size: 14px; }
.breadcrumb li { color: var(--text-dim); }
.breadcrumb li + li::before { content: '/'; padding: 0 8px; color: var(--text-dim); }
.breadcrumb a { text-decoration: none; }

/* ── Page ──────────────────────────────────────────── */
.body { flex: 1; }
.container { max-width: 1320px; margin: 0 auto; padding: 0 24px 24px; }

.footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 24px;
    min-height: 56px;
    align-items: center;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    color: var(--text);
}
.footer a { text-decoration: none; }

.page-header {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 16px;
    flex-wrap: wrap;
}
.page-header > span,
.page-header > div:last-child:not(:first-child) { font-size: 14px; color: var(--text-dim); }

h1 { font-size: 24px; font-weight: 500; line-height: 1.2; color: var(--text-bright); }
h2 { font-size: 16px; font-weight: 600; line-height: 1.3; color: var(--text-bright); margin-bottom: 14px; }
h3 { font-size: 14px; font-weight: 600; color: var(--text-bright); }

.mono { font-family: var(--mono); }
.dim { color: var(--text-dim); }

/* ── Cards ─────────────────────────────────────────── */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--r-panel);
    padding: 16px 20px;
    margin-bottom: 24px;
}
/* A card's leading heading becomes its CoreUI header bar */
.card > h2:first-child {
    margin: -16px -20px 16px;
    padding: 11px 20px;
    background: var(--card-cap);
    border-bottom: 1px solid var(--border);
    border-radius: var(--r-panel) var(--r-panel) 0 0;
    font-size: 15px;
    font-weight: 600;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: -16px -20px 16px;
    padding: 10px 20px;
    min-height: 48px;
    background: var(--card-cap);
    border-bottom: 1px solid var(--border);
    border-radius: var(--r-panel) var(--r-panel) 0 0;
}
.card-header h2 { margin: 0; font-size: 15px; }
.card-footer {
    margin: 16px -20px -16px;
    padding: 12px 20px;
    background: var(--card-cap);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--r-panel) var(--r-panel);
}

/* A card that folds away (<details class="card">): its summary is the header bar */
details.card > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -16px -20px 16px;
    padding: 11px 20px;
    background: var(--card-cap);
    border-bottom: 1px solid var(--border);
    border-radius: var(--r-panel) var(--r-panel) 0 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-bright);
    cursor: pointer;
    list-style: none;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .count { color: var(--text-dim); font-weight: 400; }
details.card > summary .caret { margin-left: auto; color: var(--text-dim); transition: transform 0.15s; }
details.card[open] > summary .caret { transform: rotate(90deg); }
details.card:not([open]) > summary { margin-bottom: -16px; border-bottom: 0; border-radius: var(--r-panel); }
details.card > summary:hover .caret { color: var(--text-bright); }

.section-title {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-bright);
    margin-bottom: 14px;
}

.add-form, .edit-form { border-radius: var(--r-panel); }
.add-form { background: var(--bg3); }

/* ── Buttons ───────────────────────────────────────
   .btn          outline secondary: edit, cancel, copy
   .btn-blue     outline primary: load, generate, check
   .btn-green    primary: save, add, run, start
   .btn-yellow   warning: changes something without alerting anyone
   .btn-red      outline danger: removes or stops                        */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border-bright);
    border-radius: var(--r-control);
    background: var(--bg2);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--bg3); border-color: var(--text-dim); color: var(--text-bright); }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 4px var(--primary-tint); }
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-green { background: var(--primary); border-color: var(--primary); color: #ffffff; }
.btn-green:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #ffffff; }

.btn-blue { background: transparent; border-color: var(--primary); color: var(--primary-text); }
.btn-blue:hover { background: var(--primary); border-color: var(--primary); color: #ffffff; }

.btn-yellow { background: var(--yellow-fill); border-color: var(--yellow-fill); color: #1b1f27; }
.btn-yellow:hover { background: #e2a00f; border-color: #e2a00f; color: #1b1f27; }

.btn-red { background: transparent; border-color: var(--red-fill); color: var(--red); }
.btn-red:hover { background: var(--red-fill); border-color: var(--red-fill); color: #ffffff; }

.btn-sm { padding: 3px 8px; font-size: 13px; border-radius: 4px; }

/* ── Badges ────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 7px;
    border-radius: var(--r-control);
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    background: var(--bg3);
    color: var(--text);
}
.badge-red { background: var(--red-fill); color: #ffffff; }
.badge-green { background: var(--green-fill); color: #ffffff; }
.badge-yellow { background: var(--yellow-fill); color: #1b1f27; }
.badge-blue { background: var(--blue-fill); color: #ffffff; }
.badge-dim { background: color-mix(in srgb, var(--text-dim) 16%, transparent); color: var(--text); }

/* Status dots */
.led, #nav-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--border-bright);
}
.led.red, .led.offline { background: var(--red-fill); }
.led.yellow, .led.crashed, #nav-status-dot.crashed { background: var(--yellow-fill); }
.led.green, .led.running, #nav-status-dot.running { background: var(--green-fill); }

/* ── Forms ─────────────────────────────────────────── */
input, select, textarea {
    width: 100%;
    background: var(--field);
    border: 1px solid var(--border);
    border-radius: var(--r-control);
    color: var(--text-bright);
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    padding: 6px 12px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    border-color: color-mix(in srgb, var(--primary) 50%, var(--field));
    box-shadow: 0 0 0 4px var(--primary-tint);
}
input:not([type="checkbox"]):not([type="radio"]):focus-visible,
select:focus-visible, textarea:focus-visible { outline: none; }
input[type="checkbox"], input[type="radio"] {
    width: auto;
    padding: 0;
    accent-color: var(--primary);
    box-shadow: none;
}
input[type="checkbox"]:focus, input[type="radio"]:focus { box-shadow: none; }
select { cursor: pointer; }
::placeholder { color: var(--text-dim); opacity: 0.8; }
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-bright);
    -webkit-box-shadow: 0 0 0 1000px var(--field) inset;
    caret-color: var(--text-bright);
}

label {
    display: block;
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-bright);
    margin-bottom: 6px;
}
.field { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; align-items: flex-end; }
.form-row .field { flex: 1; margin-bottom: 0; }

/* ── Tables ────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th {
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-bright);
    text-align: left;
    padding: 9px 12px;
    background: var(--bg3);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--hover); }

/* ── Alerts (flash messages) ───────────────────────── */
.flashes { margin-bottom: 16px; }
.flash {
    padding: 12px 16px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--r-panel);
    font-size: 14px;
    background: var(--bg2);
    color: var(--text-bright);
}
.flash.success {
    background: color-mix(in srgb, var(--green-fill) 14%, var(--bg2));
    border-color: color-mix(in srgb, var(--green-fill) 40%, var(--bg2));
    color: var(--green);
}
.flash.error {
    background: color-mix(in srgb, var(--red-fill) 12%, var(--bg2));
    border-color: color-mix(in srgb, var(--red-fill) 40%, var(--bg2));
    color: var(--red);
}

/* ── Shared bits ───────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.empty-state { text-align: center; padding: 36px 20px; color: var(--text-dim); font-size: 14px; }
.empty-state svg { display: block; margin: 0 auto 12px; opacity: 0.4; }

.spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.id-name { display: inline-flex; flex-direction: column; gap: 1px; min-width: 0; }
.id-name-label { font-family: var(--sans); font-size: 13px; color: var(--text-bright); word-break: normal; }
.id-name-id { font-family: var(--mono); font-size: 11px; color: var(--text-dim); word-break: break-all; }

/* ── Sidebar hidden (desktop) and off-canvas (phone) ─ */
html.sidebar-hidden .sidebar { transform: translateX(-100%); }
html.sidebar-hidden .wrapper { padding-left: 0; }
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1034;
    background: rgb(0 0 0 / 0.5);
}

@media (max-width: 1100px) {
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .wrapper, html.sidebar-hidden .wrapper { padding-left: 0; }
    html.sidebar-open .sidebar { transform: none; }
    html.sidebar-open .sidebar-backdrop { display: block; }
    .sidebar-close { display: inline-flex; }
}

@media (max-width: 640px) {
    .header-bar, .header-crumbs { padding-left: 16px; padding-right: 16px; }
    .container { padding: 0 16px 16px; }
    .monitor-pill .pill-text { display: none; }
    .card { padding: 14px 16px; }
    .card > h2:first-child, .card-header, details.card > summary { margin: -14px -16px 14px; padding-left: 16px; padding-right: 16px; }
    details.card:not([open]) > summary { margin-bottom: -14px; }
    .card-footer { margin: 14px -16px -14px; padding-left: 16px; padding-right: 16px; }
    .form-row { flex-wrap: wrap; }
    .form-row .field { flex-basis: 100%; }
    .footer { padding: 12px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
