/* ═══════════════════════════════════════════════════════
   CORMOD DESIGN SYSTEM
   Canonical source: portal/app/cormod.css — keep both in sync.
   For modules that can't take a runtime dependency on an external domain
   (segmented/air-gapped networks, e.g. the NVR module): vendor this file
   locally instead of linking to it live.

   VERSIONING: this file (cormod-theme.css) always tracks the latest version —
   fine for modules that sync on a schedule/manually. If you want a version that
   never silently changes underneath you, pin to cormod-theme.v1.css instead
   (frozen snapshot; a future breaking change will ship as v2, v1 stays as-is).
   Current: v1.
═══════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  /* CorMod palette — matches VS Code Dark+ editor colors */
  --color-cormod-bg:          #1e1e1e;   /* editor.background */
  --color-cormod-surface:     #252526;   /* sideBar.background */
  --color-cormod-surface2:    #2d2d2d;   /* list.hoverBackground-ish */
  --color-cormod-surface3:    #37373d;   /* list.activeSelectionBackground-ish */
  --color-cormod-surface-mid: #222222;   /* exact average of surface (#252526) and bg (#1e1e1e) */
  --color-cormod-accent:      #0078d4;   /* focusBorder / VS Code blue */
  --color-cormod-accent-dim:  rgba(0, 120, 212, 0.14);
  --color-cormod-accent-glow: rgba(0, 120, 212, 0.28);
  --color-cormod-border:      #3c3c3c;
  --color-cormod-border-soft: rgba(255, 255, 255, 0.06);
  --color-cormod-text-main:   #cccccc;   /* foreground */
  --color-cormod-text-sub:    #9d9d9d;   /* descriptionForeground */
  --color-cormod-text-muted:  #6b6b6b;
  --color-cormod-danger:      #f14c4c;
  --color-cormod-success:     #4ec9b0;
  --color-cormod-warning:     #cca700;
  --color-cormod-accent-2:      #818cf8;   /* secondary accent (indigo) — status dots/badges that need a hue distinct from accent/danger/success/warning */
  --color-cormod-accent-2-dim:  rgba(129, 140, 248, 0.14);

  --sidebar-w:           256px;
  --sidebar-w-collapsed:  64px;
  --header-h:             56px;
  --radius-card:          12px;
  --radius-slot:          10px;
  --radius-btn:           8px;
  --transition:           0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-card:          0 1px 2px rgba(0,0,0,0.50), 0 2px 8px rgba(0,0,0,0.30);
  --shadow-hover:         0 4px 16px rgba(0,0,0,0.55), 0 12px 32px rgba(0,0,0,0.35);
}

* , *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--color-cormod-bg);
  color: var(--color-cormod-text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-cormod-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-cormod-text-muted); }

/* ═══════════════════════════════════════════════════════
   LIGHT THEME
═══════════════════════════════════════════════════════ */
[data-theme="light"] {
  /* VS Code Light+ editor colors */
  --color-cormod-bg:          #ffffff;
  --color-cormod-surface:     #f3f3f3;
  --color-cormod-surface2:    #e8e8e8;
  --color-cormod-surface3:    #e2e6ec;
  --color-cormod-surface-mid: #f9f9f9;   /* exact average of surface (#f3f3f3) and bg (#ffffff) */
  --color-cormod-accent:      #005fb8;
  --color-cormod-accent-dim:  rgba(0, 95, 184, 0.09);
  --color-cormod-accent-glow: rgba(0, 95, 184, 0.18);
  --color-cormod-accent-2:      #6366f1;   /* indigo, deepened for contrast on white */
  --color-cormod-accent-2-dim:  rgba(99, 102, 241, 0.10);
  --color-cormod-border:      rgba(0, 0, 0, 0.10);
  --color-cormod-border-soft: rgba(0, 0, 0, 0.05);
  --color-cormod-text-main:   #1e1e1e;
  --color-cormod-text-sub:    #3b3b3b;
  --color-cormod-text-muted:  #6b6b6b;
  --shadow-card:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.12), 0 8px 32px rgba(0,0,0,0.07);
}

html[data-sidebar2-collapsed="true"] .cormod-col2-header,
html[data-sidebar2-collapsed="true"] .cormod-col2-body {
  width: 3.5rem !important;
  min-width: 3.5rem !important;
  padding-left: 0.25rem !important;
  padding-right: 0.25rem !important;
}

html[data-sidebar2-collapsed="true"] .cormod-col2-text {
  display: none !important;
}

html[data-sidebar2-collapsed="true"] .cormod-col2-header {
  justify-content: center;
}

/* ═══════════════════════════════════════════════════════
   MOBILE STANDARD — breakpoint 768px across the whole Cormod
   ecosystem. Framework-agnostic (no Bootstrap dependency), so any
   module — React/Tailwind, Bootstrap, or plain HTML — can reuse these
   classes verbatim. Below 768px, primary chrome (sidebar/rail) must
   hide behind a hamburger-triggered drawer (.cormod-drawer), or,
   for modules with frequent section-switching, an optional
   .cormod-bottom-nav. See design-system-checklist.html for the full
   rationale.
═══════════════════════════════════════════════════════ */
.cormod-hide-mobile { }
.cormod-show-mobile { display: none; }
@media (max-width: 767.98px) {
  .cormod-hide-mobile { display: none !important; }
  .cormod-show-mobile { display: flex !important; }
}

.cormod-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 60;
}

.cormod-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--color-cormod-surface);
  border-right: 1px solid var(--color-cormod-border);
  box-shadow: var(--shadow-hover);
  overflow-y: auto;
  z-index: 61;
  display: flex;
  flex-direction: column;
}

/* Optional pattern for modules with frequent top-level section switching
   (e.g. a workshop/booking board) — not used by the portal shell itself.
   IMPORTANT: pick ONE primary mobile nav surface, not both. If you add
   .cormod-bottom-nav for your top-level sections, don't ALSO put the same
   section list in the .cormod-drawer — that's a confusing duplicate. Split
   responsibilities instead: bottom-nav = frequent top-level sections,
   drawer = everything else (settings, admin, logout, less-used sections). */
.cormod-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 64px;
  display: flex;
  background: var(--color-cormod-surface);
  border-top: 1px solid var(--color-cormod-border);
  z-index: 55;
}

.cormod-bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px 6px;
  font-size: 10px;
  color: var(--color-cormod-text-muted);
  background: none;
  border: none;
  border-top: 3px solid transparent;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cormod-bn-item.active {
  color: var(--color-cormod-accent);
  border-top-color: var(--color-cormod-accent);
}

/* ═══════════════════════════════════════════════════════
   WIDE CONTENT — same breakpoint (768px) as the rest of the mobile
   standard above, but this is about the MAIN CONTENT AREA, not the
   navigation shell: tab/button rows, stat-card rows, tables, and
   multi-column boards that are wider than the phone screen. The page
   itself must never scroll horizontally — wrap the wide thing in one
   of these instead.
═══════════════════════════════════════════════════════ */

/* Any row that doesn't fit (tabs, stat cards, toolbar buttons, a table)
   — wrap it in this instead of letting it clip or push the page wide.
   Scrolls sideways on its own, the rest of the page stays put. */
.cormod-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.cormod-scroll-x > * {
  flex-shrink: 0;
}

/* Multi-column board/kanban (e.g. a day-by-day schedule). Wrap columns in
   .cormod-board-row (the scroll container), each column gets
   .cormod-board-col. Below 768px each column takes ~the full screen
   (swipe between days) instead of N narrow, half-cut columns. */
.cormod-board-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.cormod-board-col {
  flex: 0 0 268px;
  min-width: 268px;
}
@media (max-width: 767.98px) {
  .cormod-board-col {
    flex: 0 0 calc(100vw - 32px);
    min-width: calc(100vw - 32px);
  }
}
@media (min-width: 768px) and (max-width: 991.98px) {
  .cormod-board-col {
    flex: 0 0 220px;
    min-width: 220px;
  }
}

/* ═══════════════════════════════════════════════════════
   NOTICE BAR — collapsible attention strip. For "N unclosed records",
   "N unpaid orders" etc. that would otherwise dump a wall of always-
   expanded chips at the top of the page (expensive on mobile vertical
   space). Collapsed by default: one line, severity badges with counts.
   Tap to expand the full list. Toggle however fits your stack (here:
   plain onclick + a class, see components-reference.html) — only the
   resulting classes/markup need to match.
═══════════════════════════════════════════════════════ */
.cormod-notice-bar {
  border: 1px solid var(--color-cormod-border);
  border-radius: var(--radius-card);
  background: var(--color-cormod-surface);
  overflow: hidden;
}
.cormod-notice-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-cormod-text-sub);
  user-select: none;
}
.cormod-notice-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.cormod-notice-badge-danger {
  background: rgba(241, 76, 76, 0.14);
  color: var(--color-cormod-danger);
}
.cormod-notice-badge-warning {
  background: rgba(204, 167, 0, 0.14);
  color: var(--color-cormod-warning);
}
.cormod-notice-chevron {
  margin-left: auto;
  transition: transform var(--transition);
  flex-shrink: 0;
}
.cormod-notice-bar.open .cormod-notice-chevron {
  transform: rotate(180deg);
}
.cormod-notice-body {
  display: none;
  padding: 0 14px 12px;
  border-top: 1px solid var(--color-cormod-border);
  padding-top: 10px;
}
.cormod-notice-bar.open .cormod-notice-body {
  display: block;
}

/* ═══════════════════════════════════════════════════════
   CONFIRM MODAL — shared pattern for any "are you sure?" action
   (logout, delete, stop/restart, revoke, etc.) across every module.
═══════════════════════════════════════════════════════ */
.cormod-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.cormod-modal {
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--color-cormod-surface3);
  border: 1px solid var(--color-cormod-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-hover);
  padding: 24px;
  text-align: center;
}

.cormod-modal-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.cormod-modal-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--color-cormod-text-main);
  margin-bottom: 4px;
}

.cormod-modal-body {
  font-size: 13px;
  color: var(--color-cormod-text-sub);
  margin-bottom: 20px;
}

.cormod-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.cormod-modal-actions button,
.cormod-modal-actions a {
  flex: 1;
  padding: 8px 16px;
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  display: inline-block;
}

.cormod-modal-btn-cancel {
  background: var(--color-cormod-surface2);
  border-color: var(--color-cormod-border);
  color: var(--color-cormod-text-sub);
}
.cormod-modal-btn-cancel:hover {
  color: var(--color-cormod-text-main);
}

.cormod-modal-btn-confirm {
  background: var(--color-cormod-accent);
  color: #fff;
}
.cormod-modal-btn-confirm:hover {
  filter: brightness(1.1);
}

.cormod-modal-btn-confirm-danger {
  background: var(--color-cormod-danger);
}

/* ═══════════════════════════════════════════════════════
   SETTINGS MODAL — единый структурный стандарт для раздела «Настройки»
   во всех модулях. Список слева, содержимое выбранного пункта справа.
   Три группы пунктов сверху вниз, каждая — свой .cormod-settings-nav-heading:
     1. "Универсальное"      — фиксированный набор, см. design-system-checklist.html
     2. "Модуль"              — свои пункты конкретного проекта, видны всем
     3. "Администрирование"   — свои пункты, рендерятся в разметке только если
                                 текущий пользователь admin/owner этого модуля
   (то же самое условие, каким модуль и так уже решает, показывать ли админку).
═══════════════════════════════════════════════════════ */
.cormod-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.cormod-settings-modal {
  position: relative;
  width: 100%;
  max-width: 920px;
  height: min(640px, 90vh);
  background: var(--color-cormod-surface);
  border: 1px solid var(--color-cormod-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-hover);
  display: flex;
  overflow: hidden;
}

.cormod-settings-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: none;
  background: none;
  color: var(--color-cormod-text-muted);
  cursor: pointer;
  z-index: 2;
}
.cormod-settings-close:hover {
  background: var(--color-cormod-surface3);
  color: var(--color-cormod-text-main);
}

.cormod-settings-nav {
  width: 240px;
  flex: 0 0 240px;
  border-right: 1px solid var(--color-cormod-border);
  background: var(--color-cormod-surface2);
  overflow-y: auto;
  padding: 16px 8px;
}

.cormod-settings-title {
  font-size: 16px;
  font-weight: 700;
  padding: 2px 10px 14px;
  color: var(--color-cormod-text-main);
}

.cormod-settings-nav-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-cormod-text-muted);
  padding: 14px 10px 6px;
}
.cormod-settings-nav-heading:first-of-type {
  padding-top: 0;
}

.cormod-settings-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-btn);
  font-size: 13px;
  color: var(--color-cormod-text-sub);
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
}
.cormod-settings-nav-item:hover {
  background: var(--color-cormod-surface3);
  color: var(--color-cormod-text-main);
}
.cormod-settings-nav-item.active {
  background: var(--color-cormod-accent-dim);
  color: var(--color-cormod-accent);
  font-weight: 600;
}

.cormod-settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

.cormod-settings-back {
  display: none;
}

@media (max-width: 767.98px) {
  .cormod-settings-overlay {
    padding: 0;
  }
  .cormod-settings-modal {
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    border-radius: 0;
  }
  .cormod-settings-nav {
    width: 100%;
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--color-cormod-border);
  }
  .cormod-settings-modal.cormod-settings-showing-content .cormod-settings-nav {
    display: none;
  }
  .cormod-settings-modal:not(.cormod-settings-showing-content) .cormod-settings-content {
    display: none;
  }
  .cormod-settings-back {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--color-cormod-accent);
    font-size: 13px;
    padding: 0 0 16px;
    cursor: pointer;
  }
}
