/*
 * SOE Simple shared design foundation.
 *
 * Source of truth for portal and edge UI tokens. App-specific styles may keep
 * legacy variable names while they migrate, but new UI should use the guide
 * names and component classes defined here.
 */

:root,
html[data-theme="light"] {
    color-scheme: light;
    --font-main: Arial, Helvetica, sans-serif;

    --radius-xs: 3px;
    --radius-sm: 5px;
    --radius-md: 7px;
    --radius-lg: 9px;
    --radius-pill: 999px;

    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;

    --font-size-page-title: 26px;
    --font-size-section-title: 18px;
    --font-size-card-title: 16px;
    --font-size-body: 14px;
    --font-size-table: 13px;
    --font-size-label: 11px;
    --font-size-caption: 12px;
    --font-size-metric: 32px;

    --font-weight-normal: 400;
    --font-weight-medium: 600;
    --font-weight-bold: 800;

    --bg-page: #f3f5f7;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f8fafc;
    --bg-sidebar: #111820;
    --bg-sidebar-hover: #1b2631;
    --bg-sidebar-active: #243241;

    --text-main: #111827;
    --text-muted: #667085;
    --text-soft: #98a2b3;
    --text-inverse: #f9fafb;

    --border: #dde3ea;
    --border-strong: #c9d2dc;

    --primary: #1f6feb;
    --primary-hover: #185cc7;
    --accent: #0ea5e9;

    --success: #16803c;
    --warning: #b7791f;
    --danger: #c03221;
    --offline: #64748b;

    --success-bg: #e8f7ee;
    --warning-bg: #fff3d6;
    --danger-bg: #fde8e5;
    --offline-bg: #e8edf2;

    --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.08);
    --shadow-float: 0 8px 20px rgba(16, 24, 40, 0.08);

    /* Compatibility aliases for legacy portal/edge CSS. */
    --bg-color: var(--bg-page);
    --bg: var(--bg-page);
    --widget-bg: var(--bg-surface);
    --panel: var(--bg-surface);
    --panel-strong: var(--bg-surface-alt);
    --panel-soft: var(--bg-surface-alt);
    --soft-surface: var(--bg-surface-alt);
    --surface-1: var(--bg-surface);
    --surface-2: var(--bg-surface-alt);
    --surface-3: #edf2f8;
    --surface-strong: var(--bg-surface-alt);
    --surface-soft: var(--bg-page);
    --sidebar-bg: var(--bg-sidebar);
    --banner-bg: var(--bg-sidebar);
    --banner-text: var(--text-inverse);
    --tab-strip-bg: var(--bg-surface);
    --tab-bg: var(--bg-surface-alt);
    --tab-bg-hover: #edf2f8;
    --tab-bg-active: var(--primary);
    --tab-text: var(--text-main);
    --tab-muted: var(--text-muted);
    --panel-header-bg: var(--bg-surface-alt);
    --control-bg: var(--bg-surface-alt);
    --control-bg-hover: #edf2f8;
    --input-bg: var(--bg-surface-alt);
    --text-primary: var(--text-main);
    --text-secondary: var(--text-muted);
    --text: var(--text-main);
    --muted: var(--text-muted);
    --border-color: var(--border);
    --line: var(--border);
    --line-strong: var(--border-strong);
    --accent-primary: var(--primary);
    --accent-primary-hover: var(--primary-hover);
    --accent-hover: var(--primary-hover);
    --accent-secondary: var(--success);
    --accent-danger: var(--danger);
    --accent-strong: var(--primary-hover);
    --danger-hover: #a5281c;
    --offline-color: var(--offline);
    --shadow-color: rgba(16, 24, 40, 0.08);
    --shadow: var(--shadow-card);
    --card-gradient: var(--bg-surface);
    --hero-gradient: var(--bg-surface);
    --page-gradient: var(--bg-page);
    --radius: var(--radius-sm);
    --radius-sharp: var(--radius-sm);
}

html[data-theme="dark"],
body.dark-mode {
    color-scheme: dark;
    --bg-page: #0d1117;
    --bg-surface: #151b23;
    --bg-surface-alt: #1b232d;
    --bg-sidebar: #070a0e;
    --bg-sidebar-hover: #111820;
    --bg-sidebar-active: #1c2833;

    --text-main: #f3f6fa;
    --text-muted: #a5b0be;
    --text-soft: #778392;
    --text-inverse: #f9fafb;

    --border: #2a3542;
    --border-strong: #3a4654;

    --primary: #2f81f7;
    --primary-hover: #58a6ff;
    --accent: #38bdf8;

    --success: #5ee08a;
    --warning: #f4c152;
    --danger: #ff7b72;
    --offline: #b7c0cc;

    --success-bg: rgba(46, 160, 67, 0.18);
    --warning-bg: rgba(187, 128, 9, 0.22);
    --danger-bg: rgba(248, 81, 73, 0.18);
    --offline-bg: rgba(139, 148, 158, 0.18);

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-float: 0 10px 24px rgba(0, 0, 0, 0.28);

    --bg-color: var(--bg-page);
    --bg: var(--bg-page);
    --widget-bg: var(--bg-surface);
    --panel: var(--bg-surface);
    --panel-strong: var(--bg-surface-alt);
    --panel-soft: var(--bg-surface);
    --soft-surface: var(--bg-surface);
    --surface-1: var(--bg-surface-alt);
    --surface-2: #171f29;
    --surface-3: #202a36;
    --surface-strong: var(--bg-surface-alt);
    --surface-soft: var(--bg-surface-alt);
    --sidebar-bg: var(--bg-sidebar);
    --banner-bg: var(--bg-sidebar);
    --banner-text: var(--text-inverse);
    --tab-strip-bg: var(--bg-surface);
    --tab-bg: #111820;
    --tab-bg-hover: var(--bg-sidebar-hover);
    --tab-bg-active: var(--primary);
    --tab-text: var(--text-main);
    --tab-muted: var(--text-muted);
    --panel-header-bg: var(--bg-surface-alt);
    --control-bg: #111820;
    --control-bg-hover: var(--bg-sidebar-hover);
    --input-bg: #111820;
    --text-primary: var(--text-main);
    --text-secondary: var(--text-muted);
    --text: var(--text-main);
    --muted: var(--text-muted);
    --border-color: var(--border);
    --line: var(--border);
    --line-strong: var(--border-strong);
    --accent-primary: var(--primary);
    --accent-primary-hover: var(--primary-hover);
    --accent-hover: var(--primary-hover);
    --accent-secondary: var(--success);
    --accent-danger: var(--danger);
    --accent-strong: var(--primary);
    --danger-hover: #da3633;
    --offline-color: var(--offline);
    --shadow-color: rgba(0, 0, 0, 0.28);
    --shadow: var(--shadow-card);
    --card-gradient: var(--bg-surface);
    --hero-gradient: var(--bg-surface);
    --page-gradient: var(--bg-page);
    --radius: var(--radius-sm);
    --radius-sharp: var(--radius-sm);
}

:where(html) {
    background: var(--bg-page);
    color: var(--text-main);
    font-family: var(--font-main);
}

:where(body) {
    background: var(--bg-page);
    color: var(--text-main);
    font-family: var(--font-main);
    font-size: var(--font-size-body);
}

:where(button, input, textarea, select) {
    font: inherit;
}

:where(.app) {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 250px 1fr;
}

:where(.main) {
    padding: var(--space-xl);
    overflow: auto;
}

:where(.sidebar) {
    background: var(--bg-sidebar);
    color: var(--text-inverse);
}

:where(.nav-item) {
    min-height: 38px;
    border-radius: var(--radius-sm);
}

:where(.page-title h1) {
    margin: 0;
    font-size: var(--font-size-page-title);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0;
}

:where(.page-title p) {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: var(--font-size-body);
}

:where(.card) {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: var(--space-lg);
}

:where(.card-header) {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-md);
    margin-bottom: 14px;
}

:where(.card-title) {
    margin: 0;
    font-size: var(--font-size-card-title);
    font-weight: var(--font-weight-bold);
}

:where(.card-subtitle) {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: var(--font-size-table);
    line-height: 1.4;
}

:where(.btn, button.btn) {
    min-height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    padding: 0 14px;
    font-size: 13px;
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

:where(.btn-primary, .btn.primary, .primary-btn) {
    background: var(--primary);
    color: #ffffff;
}

:where(.btn-primary, .btn.primary, .primary-btn):hover {
    background: var(--primary-hover);
}

:where(.btn-secondary, .btn.secondary, button.secondary, .ghost-btn) {
    background: var(--bg-surface);
    color: var(--text-main);
    border-color: var(--border);
}

:where(.btn-secondary, .btn.secondary, button.secondary, .ghost-btn):hover {
    background: var(--bg-surface-alt);
    border-color: var(--border-strong);
}

:where(.btn-danger, .btn.danger, button.danger, .danger-btn) {
    background: var(--danger);
    color: #ffffff;
}

:where(.input, .select, input.input, select.select) {
    width: 100%;
    min-height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-surface-alt);
    color: var(--text-main);
    padding: 0 10px;
    font-size: var(--font-size-body);
    outline: none;
}

:where(.input, .select, input, select, textarea):focus-visible {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.18);
    outline: 2px solid transparent;
}

:where(.form-grid) {
    display: grid;
    gap: var(--space-md);
}

:where(.field label) {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: var(--font-size-label);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

:where(.status-pill) {
    min-height: 24px;
    padding: 0 9px;
    border-radius: var(--radius-pill);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--font-size-caption);
    font-weight: var(--font-weight-bold);
    white-space: nowrap;
}

:where(.status-pill)::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--radius-pill);
    background: currentColor;
}

:where(.normal, .status-ok, .status-online) {
    background: var(--success-bg);
    color: var(--success);
}

:where(.warning, .status-warn, .status-lag) {
    background: var(--warning-bg);
    color: var(--warning);
}

:where(.alarm, .status-error, .status-critical) {
    background: var(--danger-bg);
    color: var(--danger);
}

:where(.offline, .status-unknown, .status-offline) {
    background: var(--offline-bg);
    color: var(--offline);
}

:where(.table-wrap) {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-surface);
    box-shadow: var(--shadow-card);
}

:where(.table-wrap table) {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-table);
}

:where(.table-wrap thead) {
    background: var(--bg-surface-alt);
    color: var(--text-muted);
    font-size: var(--font-size-label);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

:where(.table-wrap th, .table-wrap td) {
    padding: 12px 13px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

:where(.table-wrap tbody tr:last-child td) {
    border-bottom: 0;
}

:where(.table-wrap tbody tr:hover) {
    background: var(--bg-surface-alt);
}

:where(.chart-box) {
    height: 220px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-alt);
    padding: 18px;
}

@media (max-width: 1100px) {
    :where(.app) {
        grid-template-columns: 1fr;
    }

    :where(.app > .sidebar) {
        display: none;
    }
}

@media (max-width: 700px) {
    :where(.main) {
        padding: var(--space-lg);
    }
}
