/* =====================================================================
   app.css — SimLogic Portal modern design system
   Loaded LAST in _Layout.cshtml so it refines Materialize/Site.css.
   Goal: modern app shell (fixed sidebar + sticky topbar) and a cohesive
   look, WITHOUT touching the functional widgets (Materialize JS, Kendo
   grids, amCharts, jsGrid all keep working).
   ===================================================================== */

:root {
    /* Brand palette — matches existing SimLogic Materialize light-blue */
    --brand: #039be5;          /* light-blue darken-1 (the app's primary) */
    --brand-600: #0288d1;      /* light-blue darken-2 (hover) */
    --brand-700: #0277bd;      /* light-blue darken-3 */
    --brand-300: #29b6f6;      /* light-blue lighten-1 (original hover accent) */
    --accent: #00acc1;         /* cyan accent used in the old theme */

    /* Neutrals / surfaces */
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8ef;
    --text: #1f2a37;
    --text-muted: #64748b;

    /* Sidebar — light-blue like the original nav */
    --sidebar-w: 248px;
    --rail-w: 72px;            /* width of the collapsed icon rail */
    --sidebar-bg: #0288d1;      /* gradient bottom */
    --sidebar-bg-2: #039be5;    /* gradient top */
    --sidebar-text: rgba(255, 255, 255, 0.92);
    --sidebar-text-active: #ffffff;
    --sidebar-active: rgba(255, 255, 255, 0.20);
    --sidebar-hover: rgba(255, 255, 255, 0.12);

    /* Chrome */
    --topbar-h: 64px;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.06);
    --ring: 0 0 0 3px rgba(3, 155, 229, 0.20);
}

/* ---------------------------------------------------------------- base */
html, body {
    background: var(--bg) !important;
    color: var(--text);
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    height: 100%;
}

body {
    overflow-x: hidden;
}

* {
    -webkit-font-smoothing: antialiased;
}

/* ============================================================ app shell
   CSS grid: a slim icon rail reserves the left column; topbar + main fill
   the rest. The rail expands ON TOP of content on hover (no reflow).      */
.app-shell {
    display: grid;
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "topbar topbar"
        "sidebar main";
    min-height: 100vh;
}

/* -------------------------------------------------------------- topbar */
.app-topbar {
    grid-area: topbar;
    position: sticky;
    top: 0;
    z-index: 50; /* above the expanded rail so the title stays visible */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.app-topbar .topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.app-topbar .topbar-brand {
    display: inline-flex;
    align-items: center;
}

.app-topbar .topbar-logo {
    height: 34px;
    width: auto;
    display: block;
}

.app-topbar .topbar-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    padding-left: 6px;
    border-left: 1px solid var(--border);
    margin-left: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-topbar .topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.app-topbar .topbar-user .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Hamburger — always visible; toggles the drawer open/closed */
.sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--text);
    padding: 6px;
    border-radius: 8px;
    line-height: 0;
}

.sidebar-toggle:hover {
    background: var(--surface-2);
}

.sidebar-toggle .material-icons {
    font-size: 26px !important;
}

/* ------------------------------------------------------------- sidebar */
.app-sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: var(--rail-w);
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    overflow-x: hidden;
    background: linear-gradient(180deg, var(--sidebar-bg-2) 0%, var(--sidebar-bg) 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, box-shadow 0.2s ease;
    z-index: 40;
}

/* Expanded: on hover, or pinned open via the hamburger toggle */
.app-sidebar:hover,
body.sidebar-pinned .app-sidebar {
    width: var(--sidebar-w);
    box-shadow: var(--shadow-md);
}

/* Hover = temporary overlay (no reflow). Pinned = reserve space so the page
   content sits beside the full sidebar instead of being covered. */
body.sidebar-pinned .app-shell {
    grid-template-columns: var(--sidebar-w) 1fr;
}

.app-sidebar .sidebar-nav {
    flex: 1 1 auto;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-sidebar .sidebar-spacer {
    flex: 1 1 auto;
}

/* nav item (link or submenu header) */
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none !important;
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active) !important;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-active) !important;
    box-shadow: inset 3px 0 0 0 #ffffff;
}

.nav-item .nav-icon {
    width: 22px;
    flex: 0 0 22px;
    height: auto !important;
    line-height: 1 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    font-size: 19px !important;
    color: inherit;
}

.nav-item .nav-label {
    flex: 1 1 auto;
}

/* submenu (Admin, Savings & Metrics) */
.nav-group .nav-caret {
    font-size: 18px !important;
    transition: transform 0.2s ease;
    opacity: 0.8;
}

.nav-group.open > .nav-item .nav-caret {
    transform: rotate(180deg);
}

.nav-submenu {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.25s ease;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-group.open > .nav-submenu {
    max-height: 360px;
}

.nav-submenu .nav-item {
    padding-left: 42px;
    font-size: 0.86rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.82);
}

/* =================================================== mini-rail behaviour
   Collapsed (default): only icons show, centered. Expanded (hover/pinned):
   labels and carets reveal.                                               */

/* Labels & carets collapse out of the rail */
.nav-label {
    flex: 1 1 auto;
    opacity: 0;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.12s ease, max-width 0.18s ease;
}

.nav-caret {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
}

.app-sidebar:hover .nav-label,
body.sidebar-pinned .nav-label {
    opacity: 1;
    max-width: 180px;
}

.app-sidebar:hover .nav-caret,
body.sidebar-pinned .nav-caret {
    opacity: 1;
    max-width: 24px;
}

/* Center icons while collapsed; left-align once expanded */
.app-sidebar .nav-item {
    gap: 0;
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
}

.app-sidebar:hover .nav-item,
body.sidebar-pinned .nav-item {
    gap: 12px;
    padding-left: 12px;
    padding-right: 12px;
    justify-content: flex-start;
}

.app-sidebar:hover .nav-submenu .nav-item,
body.sidebar-pinned .nav-submenu .nav-item {
    padding-left: 42px;
}

/* Keep submenus closed while the rail is collapsed */
body:not(.sidebar-pinned) .app-sidebar:not(:hover) .nav-submenu {
    max-height: 0 !important;
}

/* =========================================================== main area */
.app-main {
    grid-area: main;
    min-width: 0;
    padding: 24px 28px 48px;
}

.app-main .page-container {
    max-width: 1500px;
    margin: 0 auto;
}

/* Backdrop for mobile drawer */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 35;
}

body.sidebar-open .sidebar-backdrop {
    display: block;
}

/* ============================================== small-screen adjustments */
@media (max-width: 992px) {
    .app-main {
        padding: 18px 16px 40px;
    }
}

/* =====================================================================
   Global refinements layered over Materialize / Bootstrap.
   These polish existing view markup without changing structure.
   ===================================================================== */

/* headings */
h1, h2, h3, h4, h5, h6,
.header {
    color: var(--text);
    font-weight: 600;
}

.app-main h4.header,
.app-main h5.header {
    margin-top: 0.4rem;
}

/* Cards / Materialize z-depth panels */
.card,
.app-main .z-depth-1,
.app-main .z-depth-2,
.app-main .z-depth-3 {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-sm) !important;
}

.card .card-content {
    padding: 20px;
}

/* Buttons (Materialize .btn) */
.btn,
.btn-large,
.btn-small {
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    box-shadow: none;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover,
.btn-large:hover,
.btn-small:hover {
    box-shadow: var(--shadow-sm);
}

/* Icons inside buttons: inherit the (white) button text color, with sane size and
   alignment. This re-tames Site.css `.material-icons{font-size:x-large!important}`,
   which otherwise oversizes every in-button icon (the broken-looking save/run icons). */
.btn i.material-icons,
.btn-large i.material-icons,
.btn-small i.material-icons,
.btn-floating i.material-icons {
    color: inherit !important;
    font-size: 1.2rem !important;
    line-height: inherit !important;
    height: auto !important;
    vertical-align: middle;
}

.btn i.material-icons.right {
    margin-left: 8px;
}

.btn i.material-icons.left {
    margin-right: 8px;
}

/* Map Materialize brand color classes used in views to the new palette */
.btn.light-blue,
.btn.light-blue.lighten-1,
.btn.light-blue.darken-1 {
    background-color: var(--brand) !important;
}

.btn.light-blue:hover {
    background-color: var(--brand-600) !important;
}

/* Flat buttons (e.g. modal Cancel/Reset) read as text links, not dark blocks */
.btn-flat {
    color: var(--brand);
    text-transform: none;
}

/* Tables (native + Materialize) — replace the old bright-blue th */
.app-main table {
    border-collapse: collapse;
    background: var(--surface);
}

.app-main table th {
    background-color: var(--surface-2) !important;
    color: var(--text) !important;
    font-weight: 600;
    border-bottom: 2px solid var(--border) !important;
}

.app-main table td {
    border-bottom: 1px solid var(--border);
}

.app-main table.striped tbody tr:nth-child(odd) {
    background: var(--surface-2);
}

/* Form fields (Materialize input-field) */
.input-field > label {
    color: var(--text-muted);
}

.input-field input[type=text]:focus,
.input-field input[type=email]:focus,
.input-field input[type=password]:focus,
.input-field input[type=number]:focus,
.input-field textarea:focus {
    border-bottom: 1px solid var(--brand) !important;
    box-shadow: 0 1px 0 0 var(--brand) !important;
}

.input-field input:focus + label {
    color: var(--brand) !important;
}

/* Checkboxes (Materialize) — cleaner box + brand hover.
   The checked checkmark is already brand blue (#039be5) in this build. */
.app-main [type="checkbox"] + span:not(.lever) {
    color: var(--text);
}

.app-main [type="checkbox"]:not(:checked) + span:not(.lever):before {
    border-radius: 3px;
    border-color: #9aa7b5;
}

.app-main label:hover [type="checkbox"]:not(:checked) + span:not(.lever):before {
    border-color: var(--brand);
}

/* Radio buttons — brand accent */
.app-main [type="radio"]:checked + span:after,
.app-main [type="radio"].with-gap:checked + span:after {
    background-color: var(--brand);
}

.app-main [type="radio"]:checked + span:before,
.app-main [type="radio"]:checked + span:after,
.app-main [type="radio"].with-gap:checked + span:before,
.app-main [type="radio"].with-gap:checked + span:after {
    border-color: var(--brand);
}

/* Materialize select (FormSelect / multi-select) */
.app-main .select-wrapper input.select-dropdown {
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.app-main .select-wrapper input.select-dropdown:focus {
    border-bottom: 1px solid var(--brand);
    box-shadow: 0 1px 0 0 var(--brand);
}

.app-main .select-wrapper .caret {
    fill: var(--text-muted);
}

/* Dropdown list (shared by selects) — brand hover/selection */
.dropdown-content li > a,
.dropdown-content li > span {
    color: var(--text);
}

.dropdown-content li.selected,
.dropdown-content li.active,
.dropdown-content li:hover {
    background-color: rgba(3, 155, 229, 0.10);
}

.dropdown-content li > span {
    color: var(--text);
}

/* Multi-select check icons inside the dropdown use the brand color */
.dropdown-content li.selected > span {
    color: var(--brand);
}

/* Tabs */
.tabs .tab a {
    color: var(--text-muted);
    text-transform: none;
    font-weight: 600;
}

.tabs .tab a.active,
.tabs .tab a:hover {
    color: var(--brand);
}

.tabs .indicator {
    background-color: var(--brand);
}

/* Flash messages from _Header.cshtml */
.app-main .card-panel {
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

/* Blockquote used on dashboards */
blockquote.customBlockQuote {
    border-left: 4px solid var(--brand);
    background: rgba(11, 111, 184, 0.07);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Kendo: keep the paid theme, just align accents with the brand */
.app-main .k-grid {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

/* Nicer scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: #c5cedb transparent;
}

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

*::-webkit-scrollbar-thumb {
    background: #c5cedb;
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.app-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
    background-clip: content-box;
}
