/* ============================================================
   layout.css  v1.0
   App shell structure only. Nothing inside a page's content
   area belongs here — that lives in components.css or [domain].css.
   ============================================================ */

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

#app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
}

#app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

#sidebar {
  grid-area: sidebar;
  background: var(--surface-sidebar);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#topbar {
  grid-area: topbar;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
}

#main-content {
  grid-area: main;
  overflow-y: auto;
  padding: var(--space-3) var(--space-4);
}

#notification-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  z-index: var(--z-popover);
}

/* ⚠ LESSON LEARNED — mandatory flex-child overflow rules.
   Every flex container with text-bearing children in the sidebar
   (and anywhere else in this file) must follow these three rules. */

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: var(--space-2) var(--space-4);
  color: rgba(255, 255, 255, 0.82);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.nav-item.active {
  border-left-color: var(--color-accent);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav-item-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-section-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.4);
  padding: var(--space-4) var(--space-4) var(--space-1);
}

/* Consultation-page three-column shell (workflow rail / content / safety rail) */
.consult-shell {
  display: grid;
  grid-template-columns: 108px 1fr var(--safety-rail-width);
  gap: 0;
  background: var(--surface-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.consult-rail,
.consult-safety {
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
}

@media (max-width: 900px) {
  .consult-shell {
    grid-template-columns: 64px 1fr;
  }
  .consult-safety {
    grid-column: 1 / -1;
  }
}

/* ── Sidebar collapsible groups ────────────── */
.sidebar-group { border-bottom: 1px solid rgba(255,255,255,0.06); }
.sidebar-group-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; cursor: pointer; user-select: none;
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: rgba(255,255,255,0.45); font-weight: 700;
  transition: color 0.15s;
}
.sidebar-group-header:hover { color: rgba(255,255,255,0.75); }
.sidebar-group-items { padding-bottom: 4px; }
/* A top-level link with no group header (e.g. Dashboard) */
.sidebar-standalone { padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.form-control:disabled,
.form-control[readonly] {
    background-color: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 1;
}

#menu-toggle {
    display: none;
}

@media (max-width: 1280px) {
    #app-shell:not(.no-chrome) {
        grid-template-columns: 0 1fr;
        transition: grid-template-columns .25s cubic-bezier(.4, 0, .2, 1);
    }

    #sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: var(--sidebar-width);
        z-index: 1001;
        transform: translateX(-100%); /* hidden */
        transition: transform .2s ease;
    }

    #app-shell.nav-open #sidebar {
        transform: none; /* shown */
    }

    #menu-toggle {
        display: block;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 1002;
        width: 36px;
        height: 36px;
        border: 0;
        border-radius: 8px;
        background: #0f2a3d;
        color: #fff;
        font-size: 18px;
        cursor: pointer;
        box-shadow: 0 2px 6px rgba(0,0,0,.3);
    }

    #topbar {
        padding-left: 60px; /* room for the button */
        transition: padding-left .25s cubic-bezier(.4, 0, .2, 1);
    }

    /* While the menu is open, reserve its width */
    #app-shell:not(.no-chrome).nav-open {
        grid-template-columns: var(--sidebar-width) 1fr;
    }
}
/* ── Topbar: desktop ── */
.topbar-brand {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.topbar-title {
    font-weight: 800;
    font-size: 17px;
    letter-spacing: 0.2px;
    color: var(--text-primary, #1e293b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.topbar-menu {
    position: relative;
}

.topbar-menu-btn {
    display: none;
}
/* button hidden on desktop */
.topbar-menu-panel {
    display: flex; /* inline on desktop */
    align-items: center;
}

.topbar-user {
    color: var(--text-secondary, #64748b);
    white-space: nowrap;
    margin: 0 8px;
}

.topbar-product {
    color: var(--color-primary);
    font-weight: 600;
}

.topbar-signout {
    margin-left: 12px;
    white-space: nowrap;
}

/* ── Tablet / small laptop: just smaller fonts ── */
@media (max-width: 1280px) {
    #topbar {
        gap: 8px;
    }

    .topbar-title {
        font-size: 15px;
    }

    .topbar-user {
        font-size: 12px;
    }
}

/* ── Tablet portrait and phone: dropdown ── */
@media (max-width: 768px) {
    .topbar-title {
        font-size: 13px;
    }

    .topbar-menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: 1px solid var(--border-default, #e2e8f0);
        border-radius: 50%;
        background: var(--surface-card, #fff);
        color: var(--text-primary, #1e293b);
        font-size: 20px;
        cursor: pointer;
    }

    .topbar-menu-panel {
        display: none; /* closed by default */
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        min-width: 210px;
        padding: 12px;
        background: var(--surface-card, #fff);
        border: 1px solid var(--border-default, #e2e8f0);
        border-radius: 10px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
        z-index: 1003;
    }

    .topbar-menu.open .topbar-menu-panel {
        display: flex;
    }

    .topbar-user {
        margin: 0;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border-default, #e2e8f0);
        white-space: normal;
    }

    .topbar-signout {
        margin-left: 0;
        justify-content: flex-start;
    }
}
.btn:hover {
    background: var(--surface-page);
}
/* ── Branch switcher (top bar) and branch picker (sign-in) ── */
.topbar-branch {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 8px;
    color: var(--text-secondary, #64748b);
}

.topbar-branch .form-select {
    width: auto;
    max-width: 240px;
    height: 30px;
    padding-top: 2px;
    padding-bottom: 2px;
    font-size: 12px;
}

@media (max-width: 768px) {
    .topbar-branch { margin: 0; }
    .topbar-branch .form-select { max-width: none; width: 100%; }
}

.branch-pick { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.branch-pick li { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border-default, #e2e8f0); border-radius: 8px; }
.branch-pick li:has(input:checked) { border-color: var(--color-primary); background: var(--surface-page); }
.branch-pick label { cursor: pointer; font-size: 14px; flex: 1; }

.topbar-clock {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-left: 20px;
    padding: 5px 14px 5px 8px;
    background: var(--color-primary-light, #e0f2fe);
    border: 1px solid rgba(14, 116, 144, .18);
    border-radius: 999px;
    white-space: nowrap;
    line-height: 1.15;
}

    .topbar-clock > i {
        display: grid;
        place-items: center;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: var(--color-primary, #0e7490);
        color: #fff;
        font-size: 16px;
    }

    .topbar-clock .clock-body {
        display: flex;
        flex-direction: column;
    }

    .topbar-clock .clock-time {
        font-size: 14px;
        font-weight: 700;
        color: var(--text-primary, #0f172a);
        font-variant-numeric: tabular-nums; /* digits keep a fixed width, so the clock doesn't jitter */
    }

    .topbar-clock .clock-date {
        font-size: 10.5px;
        font-weight: 500;
        color: var(--text-muted, #64748b);
    }

@media (max-width: 900px) {
    .topbar-clock .clock-date {
        display: none;
    }
}

@media (max-width: 600px) {
    .topbar-clock {
        display: none;
    }
}