/* INTERPROS shell theme tokens.
   Light is the default appearance. Dark is an opt-in dark-grey palette applied by
   app-shell.js through the `data-theme` attribute on <html>. Only semantic tokens
   change between themes; the INTERPROS brand palette below stays constant so the
   BIM workspace and authentication pages (which do not load the shell theme)
   keep their existing identity. */
:root {
    color-scheme: light;

    /* Brand palette — constant across themes. */
    --navy-950: #06182f;
    --navy-900: #071f40;
    --navy-800: #0d315c;
    --orange-600: #e85f1f;
    --orange-500: #f26826;
    --slate-900: #17243a;
    --slate-700: #475569;
    --slate-500: #768397;
    --slate-300: #cfd7e3;
    --slate-200: #e4e9f0;
    --slate-100: #f3f6f9;
    --white: #fff;
    --success: #16794c;
    --warning: #98610b;
    --danger: #b42318;

    /* Semantic surface + text tokens (light theme). */
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-muted: #f7f9fc;
    --surface-inset: #f1f4f8;
    --text: #17243a;
    --text-muted: #5c6a80;
    --text-subtle: #8593a6;
    --border: #e3e8ef;
    --border-strong: #cdd6e2;
    --accent: #f26826;
    --accent-hover: #e0561a;
    --accent-contrast: #ffffff;
    --accent-text: #c0490f;
    --accent-soft: #fff2ea;
    --brand-strong: #071f40;
    --brand-strong-contrast: #ffffff;
    --success-text: #16794c;
    --success-soft: #e6f6ef;
    --warning-text: #98610b;
    --warning-soft: #fff3dc;
    --danger-text: #b42318;
    --danger-soft: #fff4f3;
    --shadow-sm: 0 1px 2px rgba(9, 24, 45, .05);
    --shadow-md: 0 6px 20px rgba(9, 24, 45, .07);
    --focus-ring: rgba(242, 104, 38, .45);

    /* Shell chrome. */
    --header-bg: #06182f;
    --header-text: #ffffff;
    --header-text-muted: #aab9cc;
    --header-line: rgba(255, 255, 255, .18);
    --sidebar-bg: #071f40;
    --sidebar-text: #bdcadd;
    --sidebar-text-muted: #8095b0;
    --sidebar-icon: #8297b1;
    --sidebar-hover: rgba(255, 255, 255, .09);
    --sidebar-active-text: #ffffff;
    --sidebar-line: rgba(255, 255, 255, .09);

    --app-sidebar-expanded-width: 210px;
    --app-sidebar-collapsed-width: 68px;
    --app-sidebar-width: var(--app-sidebar-expanded-width);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

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

    --bg: #16181b;
    --surface: #1e2126;
    --surface-muted: #24282e;
    --surface-inset: #1a1d21;
    --text: #e9ecf1;
    --text-muted: #a7aeb9;
    --text-subtle: #848c98;
    --border: #33383f;
    --border-strong: #454b55;
    --accent: #f26826;
    --accent-hover: #ff7c3d;
    --accent-contrast: #ffffff;
    --accent-text: #ff9a63;
    --accent-soft: rgba(242, 104, 38, .14);
    --brand-strong: #2e343c;
    --brand-strong-contrast: #e9ecf1;
    --success-text: #5fd3a3;
    --success-soft: rgba(95, 211, 163, .14);
    --warning-text: #f0b74e;
    --warning-soft: rgba(240, 183, 78, .14);
    --danger-text: #ff9186;
    --danger-soft: rgba(255, 145, 134, .14);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 22px rgba(0, 0, 0, .45);
    --focus-ring: rgba(255, 140, 90, .55);

    --header-bg: #101215;
    --header-text: #f2f4f7;
    --header-text-muted: #9aa2ad;
    --header-line: rgba(255, 255, 255, .14);
    --sidebar-bg: #101215;
    --sidebar-text: #c4cad3;
    --sidebar-text-muted: #8a919c;
    --sidebar-icon: #8a919c;
    --sidebar-hover: rgba(255, 255, 255, .07);
    --sidebar-active-text: #ffffff;
    --sidebar-line: rgba(255, 255, 255, .08);
}

/* Every stylesheet rendered inside the shared shell (shell, dashboard, data-source,
   admin) resolves its surfaces, text and borders from the semantic tokens above.
   The brand-named tokens (--navy-*, --slate-*, --white) are reserved for pages that
   deliberately keep a fixed appearance — login, password flows and the BIM viewer —
   and therefore stay constant in both themes. */

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--text); background: var(--bg); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.brand-lockup { display: inline-flex; align-items: center; gap: 11px; color: var(--header-text); }
.brand-lockup .brand-mark { display: block; flex: 0 0 auto; width: 40px; height: 40px; object-fit: contain; }
.brand-lockup strong, .brand-lockup small { display: block; }
.brand-lockup strong { font-size: 16px; letter-spacing: .04em; }
.brand-lockup small { margin-top: 2px; color: var(--header-text-muted); font-size: 10px; }
.brand-lockup-large .brand-mark { width: 48px; height: 48px; }
.brand-lockup-large strong { font-size: 19px; }
.brand-lockup-large small { font-size: 11px; }

.button { min-height: 38px; padding: 0 16px; border: 1px solid transparent; border-radius: 5px; cursor: pointer; font-weight: 700; font-size: 12px; transition: background .16s ease, border-color .16s ease, opacity .16s ease; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { background: var(--accent); color: var(--accent-contrast); }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-secondary { border-color: var(--brand-strong); background: var(--brand-strong); color: var(--brand-strong-contrast); }
.button-secondary:hover:not(:disabled) { opacity: .88; }
.button-outline { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.button-outline:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-muted); }
.button-ghost { border-color: var(--header-line); background: transparent; color: var(--header-text); }
.button-ghost:hover { background: rgba(255,255,255,.08); }
.button-full { width: 100%; }

.eyebrow { margin: 0 0 7px; color: var(--accent-text); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.inline-state, .form-message { margin: 14px 0 0; padding: 11px 12px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-muted); color: var(--text-muted); font-size: 12px; line-height: 1.45; }
.inline-state.error, .form-message.error { border-color: var(--danger-text); background: var(--danger-soft); color: var(--danger-text); }
.inline-state:empty, .form-message:empty { display: none; }

.app-header { position: fixed; inset: 0 0 auto; z-index: 100; display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 20px; background: var(--header-bg); color: var(--header-text); }
.app-header-actions { display: flex; align-items: center; gap: 14px; }
.environment-badge { padding: 4px 7px; border: 1px solid var(--header-line); border-radius: 4px; color: var(--header-text-muted); font-size: 9px; font-weight: 800; letter-spacing: .12em; }
.user-summary { text-align: right; }
.user-summary strong, .user-summary small { display: block; }
.user-summary strong { font-size: 12px; }
.user-summary small { margin-top: 2px; color: var(--header-text-muted); font-size: 10px; }
.app-layout { min-height: 100vh; padding-top: 64px; }

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--header-line);
    border-radius: 999px;
    background: transparent;
    color: var(--header-text);
    cursor: pointer;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    transition: background .16s ease, border-color .16s ease;
}
.theme-toggle:hover { background: rgba(255,255,255,.09); }
.theme-toggle-icon { display: inline-grid; place-items: center; flex: 0 0 auto; }
.theme-toggle-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle-label { line-height: 1; }

.app-page.sidebar-collapsed,
:root.shell-sidebar-collapsed { --app-sidebar-width: var(--app-sidebar-collapsed-width); }
.app-sidebar {
    position: fixed;
    inset: 64px auto 0 0;
    z-index: 50;
    width: var(--app-sidebar-width);
    padding: 52px 10px 18px;
    overflow-y: auto;
    background: var(--sidebar-bg);
    transition: width .18s ease;
}
.app-page .data-source-main,
.app-page .admin-main {
    margin-left: var(--app-sidebar-width);
    transition: margin-left .18s ease;
}
.shell-sidebar { isolation: isolate; }
.sidebar-collapse-toggle {
    position: absolute;
    top: 12px;
    right: 10px;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--sidebar-line);
    border-radius: 6px;
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
    cursor: pointer;
    transition: background .16s ease, color .16s ease, transform .18s ease;
}
.sidebar-collapse-toggle:hover { background: rgba(255,255,255,.14); color: var(--sidebar-active-text); }
.sidebar-collapse-icon, .nav-icon, .sidebar-group-chevron { display: inline-grid; place-items: center; flex: 0 0 auto; }
.sidebar-collapse-icon svg, .nav-icon svg, .sidebar-group-chevron svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.app-sidebar.collapsed .sidebar-collapse-icon { transform: rotate(180deg); }

/* Group headers are text-only by design — no icons. */
.sidebar-group { margin: 0 0 10px; padding: 0 0 10px; border-bottom: 1px solid var(--sidebar-line); }
.sidebar-group:last-child { margin-bottom: 0; border-bottom: 0; }
.sidebar-group-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 32px;
    gap: 8px;
    padding: 0 9px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .13em;
    text-align: left;
    text-transform: uppercase;
}
.sidebar-group-toggle:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.sidebar-group-title { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-group-chevron { transition: transform .16s ease; }
.sidebar-group:not(.is-collapsed) .sidebar-group-chevron { transform: rotate(90deg); }
.sidebar-group.is-collapsed .sidebar-group-items { display: none; }
.sidebar-group-items { padding-top: 3px; }

.nav-item {
    display: flex;
    align-items: center;
    min-height: 40px;
    gap: 10px;
    margin-bottom: 4px;
    padding: 0 10px;
    border-radius: 5px;
    color: var(--sidebar-text);
    font-size: 12px;
    font-weight: 600;
    transition: background .16s ease, color .16s ease;
}
.nav-item-label { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item small { margin-left: auto; color: var(--sidebar-text-muted); font-size: 9px; text-transform: uppercase; }
.nav-item:hover:not(.disabled), .nav-item.active { background: var(--sidebar-hover); color: var(--sidebar-active-text); }
.nav-item.active { box-shadow: inset 3px 0 0 var(--orange-500); }
.nav-item.disabled { cursor: default; opacity: .65; }
.nav-icon { width: 19px; color: var(--sidebar-icon); }
.nav-item.active .nav-icon, .nav-item:hover .nav-icon { color: var(--sidebar-active-text); }

.app-sidebar.collapsed { padding-left: 8px; padding-right: 8px; }
.app-sidebar.collapsed .sidebar-collapse-toggle { right: 8px; }
.app-sidebar.collapsed .sidebar-group-title,
.app-sidebar.collapsed .nav-item-label,
.app-sidebar.collapsed .nav-item small { display: none; }
.app-sidebar.collapsed .sidebar-group-toggle,
.app-sidebar.collapsed .nav-item { width: 44px; margin-right: auto; margin-left: auto; padding-right: 0; padding-left: 0; justify-content: center; }
.app-sidebar.collapsed .sidebar-group-toggle { margin-bottom: 2px; }
.app-sidebar.collapsed .nav-item.active { box-shadow: inset 3px 0 0 var(--orange-500); }
.app-sidebar.collapsed .nav-icon { width: 20px; }

/* Legacy sidebar selectors remain supported for any shell page not yet hydrated. */
.nav-group { margin: 12px 0 8px; padding-top: 10px; border-top: 1px solid var(--sidebar-line); }
.nav-group-label { display: block; padding: 0 12px 7px; color: var(--sidebar-text-muted); font-size: 9px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.nav-item.nav-subitem { min-height: 34px; margin-left: 8px; padding-left: 14px; font-size: 11px; }
.nav-item.nav-subitem.active { border-left-width: 2px; }

.page-heading { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-heading h1 { margin: 0; color: var(--text); font-size: 27px; }
.page-heading p:last-child { margin: 7px 0 0; color: var(--text-muted); font-size: 13px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0; color: var(--text); font-size: 17px; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 999px; font-size: 9px; font-weight: 800; letter-spacing: .08em; white-space: nowrap; }
.status-pill.available { background: var(--success-soft); color: var(--success-text); }
.status-pill.neutral { background: var(--surface-inset); color: var(--text-muted); }
.status-pill.warning { background: var(--warning-soft); color: var(--warning-text); }

/* BIM workspace: keep the left tool panel below the 48px BIM dimension nav.
   bim.css defines the panel at top:72px; this page-safe override prevents
   the higher-z-index dimension nav from clipping the first 48px of content. */
#bim-source-panel { top: 120px !important; }

@media (max-width: 820px) {
    :root { --app-sidebar-expanded-width: 176px; --app-sidebar-collapsed-width: 64px; }
    .user-summary { display: none; }
    .theme-toggle-label { display: none; }
    .theme-toggle { padding: 0 8px; }
    .nav-item { font-size: 11px; }
}

@media (max-width: 640px) {
    :root { --app-sidebar-width: 0px; }
    .app-page.sidebar-collapsed,
    :root.shell-sidebar-collapsed { --app-sidebar-width: 0px; }
    .app-header { padding: 0 12px; }
    .app-header .brand-lockup small, .environment-badge { display: none; }
    .app-sidebar, .app-sidebar.collapsed {
        position: static;
        display: flex;
        align-items: stretch;
        width: auto;
        padding: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        transition: none;
    }
    .app-page .data-source-main,
    .app-page .admin-main { margin-left: 0; }
    .sidebar-collapse-toggle { display: none; }
    .sidebar-group { display: flex; flex: 0 0 auto; margin: 0; padding: 0; border: 0; }
    .sidebar-group-toggle { display: none; }
    .sidebar-group-items, .sidebar-group.is-collapsed .sidebar-group-items { display: flex; padding: 0; }
    .app-sidebar .nav-item, .app-sidebar.collapsed .nav-item { flex: 0 0 auto; width: auto; min-height: 38px; margin: 0 4px 0 0; padding: 0 11px; justify-content: flex-start; }
    .app-sidebar .nav-item-label, .app-sidebar.collapsed .nav-item-label { display: inline; }
    .app-sidebar .nav-item small, .app-sidebar.collapsed .nav-item small { display: none; }
    .app-sidebar .nav-icon, .app-sidebar.collapsed .nav-icon { width: 17px; }
    .app-layout { padding-top: 64px; }
}
