/* ============================================================
   assets/erp-shell.css  -  ERP shell "S1" (brand redesign, palette B)

   Every selector in this file starts with html[data-ui="2026"]
   (enforced by tests/properties/shell-css-scope.test.js).
   ROLLBACK: remove data-ui="2026" from <html> in index.html and the
   previous look returns; nothing here applies without it.

   Palette B = logo orange on warm charcoal. It overrides the variable names
   already defined in assets/style.css (section 1 / 1b); no second system.
   No menu entry or route is hidden or removed here.
   ============================================================ */

/* ---------- 1. Palette B: variables (dark default) ---------- */
html[data-ui="2026"],
html[data-ui="2026"][data-theme="dark"] {
  --bg:       #161314;
  --surface:  #1e1a1b;
  --surface2: #242021;
  --surface3: #2d2829;
  --surface4: #383233;
  --border:   rgba(255,255,255,0.09);
  --border2:  rgba(255,255,255,0.18);
  --accent:   #f55929;
  --accent2:  #ff8a3d;
  --accent3:  #f2b134;
  --success:  #2fbf71;
  --warning:  #f2b134;
  --danger:   #ef4b4b;
  --text:     #f6f2ef;
  --text2:    #bdb3ae;
  --text3:    #8f8581;
  --glow:     0 0 20px rgba(245,89,41,0.22);
  --radius:   12px;
  --radius2:  16px;
  --shell-nav-active-bg: rgba(245,89,41,0.14);
  --shell-nav-active-bd: rgba(245,89,41,0.32);
  --shell-bar-bg:  rgba(30,26,27,0.92);
  --shell-side-bg: #1a1617;
}

/* ---------- 1b. Palette B: light ---------- */
html[data-ui="2026"][data-theme="light"] {
  --bg:       #f6f3f0;
  --surface:  #ffffff;
  --surface2: #faf8f6;
  --surface3: #ece7e3;
  --surface4: #ddd5cf;
  --border:   rgba(35,31,32,0.10);
  --border2:  rgba(35,31,32,0.18);
  --accent:   #e5481a;
  --accent2:  #f55929;
  --accent3:  #b7791f;
  --success:  #16874a;
  --warning:  #b7791f;
  --danger:   #c62f2f;
  --text:     #231f20;
  --text2:    #5b524f;
  --text3:    #8a7f7b;
  --glow:     0 0 20px rgba(229,72,26,0.14);
  --shell-nav-active-bg: rgba(229,72,26,0.10);
  --shell-nav-active-bd: rgba(229,72,26,0.28);
  --shell-bar-bg:  rgba(255,255,255,0.94);
  --shell-side-bg: #ffffff;
}

/* ---------- 2. Topbar ---------- */
html[data-ui="2026"] #topbar {
  background: var(--shell-bar-bg);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border), 0 6px 24px rgba(0,0,0,0.12);
}
html[data-ui="2026"] .topbar-brand .brand-text {
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
}
html[data-ui="2026"] .topbar-action-btn {
  border-radius: 10px;
  border-color: var(--border);
  background: var(--glass);
}
html[data-ui="2026"] .topbar-action-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- 3. Sidebar ---------- */
html[data-ui="2026"] #sidebar {
  background: var(--shell-side-bg);
  border-right: 1px solid var(--border);
  box-shadow: none;
}
html[data-ui="2026"] .sidebar-group {
  padding: 18px 16px 6px;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text3);
}
html[data-ui="2026"] .nav-item {
  margin: 1px 8px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  color: var(--text2);
}
html[data-ui="2026"] .nav-item:hover {
  background: var(--glass2);
  color: var(--text);
}
html[data-ui="2026"] .nav-item.active {
  background: var(--shell-nav-active-bg);
  border-color: var(--shell-nav-active-bd);
  color: var(--accent);
}
html[data-ui="2026"] .nav-item.active .nav-label { font-weight: 800; }
html[data-ui="2026"] .sidebar-toggle {
  background: var(--surface2);
  border-color: var(--border2);
  box-shadow: none;
}

/* ---------- 4. Content: cards, KPIs, tables, forms, buttons ---------- */
html[data-ui="2026"] .panel,
html[data-ui="2026"] .kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius2);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
html[data-ui="2026"] .kpi-card:hover {
  border-color: var(--border2);
}
html[data-ui="2026"] .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
html[data-ui="2026"] .data-table th {
  background: var(--surface2);
  color: var(--text3);
  border-bottom: 1px solid var(--border2);
}
html[data-ui="2026"] .data-table tr:hover td {
  background: var(--glass);
}
html[data-ui="2026"] .form-input,
html[data-ui="2026"] input[type="text"],
html[data-ui="2026"] input[type="number"],
html[data-ui="2026"] input[type="date"],
html[data-ui="2026"] input[type="email"],
html[data-ui="2026"] input[type="tel"],
html[data-ui="2026"] input[type="search"],
html[data-ui="2026"] select,
html[data-ui="2026"] textarea {
  border-radius: 10px;
}
html[data-ui="2026"] .form-input:focus,
html[data-ui="2026"] input:focus,
html[data-ui="2026"] select:focus,
html[data-ui="2026"] textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(245,89,41,0.18);
}
html[data-ui="2026"] .btn {
  border-radius: 10px;
}
html[data-ui="2026"] .btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
}
html[data-ui="2026"] .btn-ghost {
  background: var(--glass2);
  border: 1px solid var(--border);
  color: var(--text);
}
html[data-ui="2026"] .modal-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius2);
}
html[data-ui="2026"] .modal-overlay {
  background: rgba(10,8,8,0.72);
}

/* ---------- 5. Tablet (<= 1024px): icon-only rail ---------- */
@media (max-width: 1024px) and (min-width: 769px) {
  html[data-ui="2026"] #sidebar {
    width: var(--sidebar-c) !important;
    min-width: var(--sidebar-c) !important;
  }
  html[data-ui="2026"] #sidebar .sidebar-group,
  html[data-ui="2026"] #sidebar .nav-label,
  html[data-ui="2026"] #sidebar .nav-badge {
    display: none;
  }
  html[data-ui="2026"] #sidebar .nav-item {
    justify-content: center;
    margin: 2px 8px;
    padding: 10px 0;
  }
  html[data-ui="2026"] #sidebar .nav-icon {
    width: auto;
    font-size: 17px;
  }
  html[data-ui="2026"] #sidebar .nav-item:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(var(--sidebar-c) - 4px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface3);
    color: var(--text);
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    z-index: 500;
    pointer-events: none;
  }
  html[data-ui="2026"] .sidebar-toggle { display: none; }
}

/* ---------- 6. Phone (<= 640px): bottom tab bar ----------
   Built from the existing #sidebar .nav-item[data-page] entries: when the
   drawer is closed the sidebar is a fixed, sideways-scrolling bar at the
   bottom (icon over a small label). The hamburger still opens the full
   drawer (.mobile-open), so every entry stays reachable. No new routes. */
@media (max-width: 640px) {
  html[data-ui="2026"] #sidebar:not(.mobile-open) {
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    width: 100% !important;
    min-width: 0 !important;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-right: 0;
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 24px rgba(0,0,0,0.18);
    z-index: 150;
  }
  html[data-ui="2026"] #sidebar:not(.mobile-open)::-webkit-scrollbar { display: none; }
  html[data-ui="2026"] #sidebar:not(.mobile-open) .sidebar-group,
  html[data-ui="2026"] #sidebar:not(.mobile-open) .nav-badge,
  html[data-ui="2026"] #sidebar:not(.mobile-open) .sidebar-toggle {
    display: none;
  }
  html[data-ui="2026"] #sidebar:not(.mobile-open) .nav-item {
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 64px;
    margin: 4px 2px;
    padding: 4px 6px;
    border-radius: 12px;
  }
  html[data-ui="2026"] #sidebar:not(.mobile-open) .nav-icon {
    width: auto;
    font-size: 18px;
  }
  html[data-ui="2026"] #sidebar:not(.mobile-open) .nav-label {
    flex: none;
    font-size: 9px;
    font-weight: 700;
    max-width: 62px;
    text-align: center;
  }
  /* keep content clear of the bar */
  html[data-ui="2026"] #content {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
  }
  /* an open drawer sits above everything, as before */
  html[data-ui="2026"] #sidebar.mobile-open {
    background: var(--shell-side-bg);
    z-index: 8000;
  }
}

/* ---------- 6. Windows (W1): stacked dialogs ----------
   core/modal.js only sets --depth (0 = first window) on each layer.
   Desktop/tablet: centred dialog, small cascade per layer, content scrolls
   inside. Phone: full-screen sheet; the close button reads "< Back". */
html[data-ui="2026"] .modal-overlay {
  --win-step: 14px;
  --win-cascade: calc(min(var(--depth, 0), 5) * var(--win-step));
  padding: 24px;
  overscroll-behavior: contain;
}
html[data-ui="2026"] .modal-overlay > .modal-box {
  position: relative;
  top: var(--win-cascade);
  inset-inline-start: var(--win-cascade);
  width: min(92vw, 640px) !important;
  max-width: min(92vw, 640px) !important;
  max-height: calc(100vh - 48px - var(--win-cascade)) !important;
  max-height: calc(100dvh - 48px - var(--win-cascade)) !important;
  margin: 0 !important;
  overflow: auto !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
html[data-ui="2026"] .modal-overlay > .modal-box.wide {
  width: min(92vw, 880px) !important;
  max-width: min(92vw, 880px) !important;
}
html[data-ui="2026"] .modal-overlay > .modal-box .modal-header {
  position: sticky;
  top: -22px;
  z-index: 2;
  margin: -22px -22px 16px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
html[data-ui="2026"] .modal-overlay > .modal-box table {
  min-width: 520px;
}
@media (max-width: 640px) {
  html[data-ui="2026"] .modal-overlay {
    padding: 0;
    align-items: stretch;
  }
  html[data-ui="2026"] .modal-overlay > .modal-box,
  html[data-ui="2026"] .modal-overlay > .modal-box.wide {
    top: 0;
    inset-inline-start: 0;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh;
    height: 100dvh;
    max-height: none !important;
    border-radius: 0;
    border-width: 0;
    padding: 0 14px calc(18px + env(safe-area-inset-bottom, 0px)) !important;
  }
  html[data-ui="2026"] .modal-overlay > .modal-box .modal-header {
    top: 0;
    margin: 0 -14px 14px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  }
  html[data-ui="2026"] .modal-overlay > .modal-box .modal-header .modal-close {
    order: -1;
    width: auto;
    min-width: 44px;
    height: 40px;
    padding: 0 14px;
    font-size: 0;
  }
  html[data-ui="2026"] .modal-overlay > .modal-box .modal-header .modal-close::before {
    content: "\2039  Back";
    font-size: 14px;
    font-weight: 700;
  }
  html[data-ui="2026"] .modal-overlay > .modal-box .modal-header h3 {
    flex: 1;
    min-width: 0;
    margin-inline-start: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
