/* ---------- Reset & base ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, figure {
    margin: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

::selection {
    background: var(--green-soft);
    color: var(--green-bright);
}

:focus-visible {
    outline: 2px solid var(--green-border);
    outline-offset: 2px;
}

/* Headings are focused programmatically on navigation (a11y). No visible ring. */
h1:focus {
    outline: none;
}

/* Subtle scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
    border: 3px solid var(--bg);
}

/* ---------- Typography helpers ---------- */

.mono {
    font-family: var(--font-mono);
    font-feature-settings: "ss01", "cv01";
}

.eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.link {
    color: var(--green);
    font-family: var(--font-mono);
}

.link:hover {
    color: var(--green-bright);
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease, opacity 120ms ease;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-primary {
    background: var(--green);
    color: var(--on-green);
}

.btn-primary:not(:disabled):hover {
    background: var(--green-bright);
}

.btn-ghost {
    background: var(--surface-strong);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-ghost:not(:disabled):hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
}

.btn-danger {
    background: var(--red-soft);
    color: var(--red);
    border: 1px solid var(--red-border);
}

.btn-danger:not(:disabled):hover {
    background: rgba(227, 123, 131, 0.18);
}

.btn-sm {
    height: 32px;
    padding: 0 13px;
    font-size: 13px;
}

/* Add button: icon-only on phones, labelled on desktop (Apps / Machines). */
.btn-add {
    flex: none;
}

@media (max-width: 820px) {
    .btn-add {
        width: 40px;
        padding: 0;
    }
}

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* ---------- Status badges & dots ---------- */

.dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    flex: none;
    background: var(--neutral);
}

.dot-green   { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot-amber   { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.dot-red     { background: var(--red);   box-shadow: 0 0 0 3px var(--red-soft); }
.dot-neutral { background: transparent; border: 1.5px solid var(--neutral); }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 28px;
    padding: 0 11px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.badge-green   { color: var(--green); background: var(--green-soft); border-color: var(--green-border); }
.badge-amber   { color: var(--amber); background: var(--amber-soft); border-color: var(--amber-border); }
.badge-red     { color: var(--red);   background: var(--red-soft);   border-color: var(--red-border); }
.badge-neutral { color: var(--text-dim); background: transparent;    border-color: var(--border); }

.badge-tag { text-transform: none; }

/* ---------- Chips (small inline labels) ---------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 24px;
    padding: 0 9px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.chip-amber { color: var(--amber); border-color: var(--amber-border); background: var(--amber-soft); }

/* ---------- Inputs ---------- */

.input {
    width: 100%;
    height: 42px;
    padding: 0 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    transition: border-color 120ms ease, background 120ms ease;
}

.input::placeholder {
    color: var(--text-dim);
}

.input:focus {
    outline: none;
    border-color: var(--green-border);
    background: var(--bg);
}

/* ---------- Modal close button (used across modal screens) ---------- */

.pipe-close {
    margin-left: auto;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: var(--text-dim);
    transition: background 120ms ease, color 120ms ease;
}

.pipe-close:hover {
    color: var(--text);
    background: var(--surface-strong);
}

/* ---------- Page scaffolding ---------- */

.page-head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 26px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.page-title {
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-lede {
    color: var(--text-muted);
    font-size: 14px;
}

.spacer {
    flex: 1;
}

/* ---------- Config tabs (shared) ---------- */

.cfg-lede {
    max-width: 72ch;
    margin-bottom: 22px;
    line-height: 1.6;
    color: var(--text-muted);
}

.cfg-error {
    margin: 12px 0;
    font-size: 13px;
    color: var(--red);
}

.cfg-empty {
    padding: 24px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-dim);
}

/* ---------- Sidebar nav (NavLink is a child component, so these are global) ---------- */

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 42px;
    padding: 0 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
    transition: background 120ms ease, color 120ms ease;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex: none;
    color: var(--text-dim);
    transition: color 120ms ease;
}

.nav-item:hover {
    background: var(--surface);
    color: var(--text);
}

.nav-item:hover svg {
    color: var(--text-muted);
}

.nav-item.active {
    background: var(--green-soft);
    color: var(--green);
}

.nav-item.active svg {
    color: var(--green);
}

/* Bottom tab bar recasts the same nav items as icon-over-label tabs. */
.bottomnav .nav-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    height: auto;
    padding: 8px 0 5px;
    border-radius: var(--radius-sm);
    font-size: 10.5px;
    font-weight: 500;
    color: var(--text-dim);
    background: none;
}

.bottomnav .nav-item svg {
    width: 22px;
    height: 22px;
}

.bottomnav .nav-item:hover {
    background: none;
    color: var(--text-muted);
}

.bottomnav .nav-item:hover svg {
    color: var(--text-muted);
}

.bottomnav .nav-item.active {
    background: none;
    color: var(--green);
}

.bottomnav .nav-item.active svg {
    color: var(--green);
}

/* ---------- Tabs (NavLink is a child component, so these are global) ---------- */

.tab {
    padding: 0 2px 14px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 120ms ease, border-color 120ms ease;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--text);
    border-bottom-color: var(--green);
}

/* ---------- Brand mark (shared: sidebar + mobile top bar) ---------- */

.brandmark {
    display: inline-flex;
    align-items: center;
    flex: none;
}

/* ---------- Show / hide utilities ---------- */

@media (min-width: 821px) {
    .mobile-only { display: none !important; }
}

@media (max-width: 820px) {
    .desktop-only { display: none !important; }
}

/* ---------- Responsive (shared primitives) ---------- */

/* On phones the page-head is the top app bar: a sticky, full-bleed strip. */
@media (max-width: 820px) {
    .page-head {
        position: sticky;
        top: 0;
        z-index: 30;
        gap: 12px;
        margin: -18px -18px 18px;
        padding: 13px 18px;
        background: var(--bg);
    }

    /* The descriptive subtitle would crowd the mobile app bar. */
    .page-lede {
        display: none;
    }
}

@media (max-width: 640px) {
    .page-title {
        font-size: 22px;
    }
}

/* ---------- Blazor reconnection overlay (replaces the framework default) ---------- */

#components-reconnect-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    place-items: center;
    padding: 24px;
    background: var(--overlay);
    backdrop-filter: blur(2px);
}

#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: grid;
}

.reconnect-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 340px;
    padding: 30px 28px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.reconnect-spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2.5px solid var(--border-strong);
    border-top-color: var(--green);
    animation: reconnect-spin 0.8s linear infinite;
}

@keyframes reconnect-spin {
    to { transform: rotate(360deg); }
}

.reconnect-msg {
    display: none;
    margin: 0;
    line-height: 1.5;
}

#components-reconnect-modal.components-reconnect-show .reconnect-msg-show,
#components-reconnect-modal.components-reconnect-failed .reconnect-msg-failed,
#components-reconnect-modal.components-reconnect-rejected .reconnect-msg-rejected {
    display: block;
}

/* Only the actively-retrying state spins. */
#components-reconnect-modal.components-reconnect-failed .reconnect-spinner,
#components-reconnect-modal.components-reconnect-rejected .reconnect-spinner {
    display: none;
}

.reconnect-btn {
    margin-left: 4px;
    color: var(--green);
    font-weight: 600;
    text-decoration: underline;
}

.reconnect-btn:hover {
    color: var(--green-bright);
}
