/* Меню у стилі Atlas: кольорові картки-пункти, секції, що згортаються,
   і згортання самого сайдбара в смугу іконок. Порт на чистий CSS (Atlas — Tailwind). */

/* ── Кольорові теми пунктів (як THEMES в Atlas) ───────────────────────────── */

/* Теми задаються атрибутом, а не класом — щоб їх могли брати і пункт меню,
   і картка столу, не успадковуючи при цьому чужу розкладку. */
[data-theme]          { --t1: #7c3aed; --t2: #4f46e5; --soft: #f3edfd; --ink: #6d28d9; }
[data-theme="purple"] { --t1: #7c3aed; --t2: #4f46e5; --soft: #f3e8ff; --ink: #7e22ce; }
[data-theme="blue"]   { --t1: #2563eb; --t2: #0891b2; --soft: #dbeafe; --ink: #1d4ed8; }
[data-theme="green"]  { --t1: #10b981; --t2: #0d9488; --soft: #d1fae5; --ink: #047857; }
[data-theme="amber"]  { --t1: #f59e0b; --t2: #f97316; --soft: #fef3c7; --ink: #b45309; }
[data-theme="indigo"] { --t1: #6366f1; --t2: #7c3aed; --soft: #e0e7ff; --ink: #4338ca; }
[data-theme="red"]    { --t1: #ef4444; --t2: #e11d48; --soft: #fee2e2; --ink: #b91c1c; }
[data-theme="pink"]   { --t1: #ec4899; --t2: #c026d3; --soft: #fce7f3; --ink: #be185d; }

/* Темні відтінки тем — два блоки з однаковими значеннями, тримати синхронно
   (системна тема / явний вибір перемикачем). */
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) [data-theme="purple"] { --soft: #3b0764; --ink: #d8b4fe; }
  :root:not([data-scheme="light"]) [data-theme="blue"]   { --soft: #172554; --ink: #93c5fd; }
  :root:not([data-scheme="light"]) [data-theme="green"]  { --soft: #052e2b; --ink: #6ee7b7; }
  :root:not([data-scheme="light"]) [data-theme="amber"]  { --soft: #451a03; --ink: #fcd34d; }
  :root:not([data-scheme="light"]) [data-theme="indigo"] { --soft: #1e1b4b; --ink: #a5b4fc; }
  :root:not([data-scheme="light"]) [data-theme="red"]    { --soft: #450a0a; --ink: #fca5a5; }
  :root:not([data-scheme="light"]) [data-theme="pink"]   { --soft: #500724; --ink: #f9a8d4; }
}
:root[data-scheme="dark"] [data-theme="purple"] { --soft: #3b0764; --ink: #d8b4fe; }
:root[data-scheme="dark"] [data-theme="blue"]   { --soft: #172554; --ink: #93c5fd; }
:root[data-scheme="dark"] [data-theme="green"]  { --soft: #052e2b; --ink: #6ee7b7; }
:root[data-scheme="dark"] [data-theme="amber"]  { --soft: #451a03; --ink: #fcd34d; }
:root[data-scheme="dark"] [data-theme="indigo"] { --soft: #1e1b4b; --ink: #a5b4fc; }
:root[data-scheme="dark"] [data-theme="red"]    { --soft: #450a0a; --ink: #fca5a5; }
:root[data-scheme="dark"] [data-theme="pink"]   { --soft: #500724; --ink: #f9a8d4; }

/* Згорнуте меню: футер-кнопки стовпчиком, підписи сховані */
.layout.collapsed .sb-footer-row { flex-direction: column; gap: 4px; }
.layout.collapsed .sb-footer-actions { flex-direction: column; }
.layout.collapsed .sb-version { display: none; }

/* ── Картка-пункт меню ────────────────────────────────────────────────────── */

.nav-card {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  margin: 4px 2px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer; user-select: none;
  transition: transform .18s, box-shadow .18s, background .18s;
}
.nav-card:hover { transform: scale(1.02); background: var(--surface); }

.nav-card .nav-ico {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; font-size: 17px;
  background: var(--soft); color: var(--ink);
  transition: background .18s, color .18s;
}
.nav-card .nav-text { min-width: 0; flex: 1; }
.nav-card .nav-label {
  display: block; font-weight: 700; font-size: 13.5px; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-card .nav-sub {
  display: block; font-size: 10.5px; font-weight: 500; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-card .nav-count {
  flex: 0 0 auto; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
  background: var(--soft); color: var(--ink);
}
.nav-card .nav-count.hot { background: var(--danger); color: #fff; }

/* активний — градієнт теми, як в Atlas */
.nav-card.active {
  background: linear-gradient(135deg, var(--t1), var(--t2));
  border-color: transparent; color: #fff;
  box-shadow: 0 8px 20px -6px color-mix(in srgb, var(--t1) 55%, transparent);
  transform: scale(1.02);
}
.nav-card.active .nav-ico { background: rgba(255, 255, 255, .2); color: #fff; }
.nav-card.active .nav-sub { color: rgba(255, 255, 255, .72); }
.nav-card.active .nav-count { background: rgba(255, 255, 255, .22); color: #fff; }

/* ── Секції, що згортаються ───────────────────────────────────────────────── */

.nav-section-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 4px;
  background: none; border: none; cursor: pointer;
  font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted);
}
.nav-section-btn:hover { color: var(--text); }
.nav-section-btn .chev { transition: transform .2s; font-size: 9px; }
.nav-section-btn .chev.open { transform: rotate(90deg); }
.nav-section-body { overflow: hidden; transition: max-height .25s ease; }

/* ── Рейка (68px іконок + flyout) — за гайдом Atlas ───────────────────────── */

.rail.sidebar-rail { width: 68px; padding: 12px 6px; }
.rail.sidebar-rail .sb-hide { display: none !important; }
.sb-show { display: none; }
.rail.sidebar-rail .sb-show { display: flex; justify-content: center; }
.rail.sidebar-rail .brand { justify-content: center; padding: 6px 0 14px; }
.rail.sidebar-rail .sb-footer-row { flex-direction: column; align-items: center; gap: 6px; }
.rail.sidebar-rail .sb-footer-actions { flex-direction: column; gap: 2px; }
.rail.sidebar-rail .who { justify-content: center; padding: 0; }

.nav-rail { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0; }

.rail-btn {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 13px;
  cursor: pointer; border: none; background: transparent; text-decoration: none;
  transition: background .15s, transform .12s;
}
.rail-btn:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); transform: translateY(-1px); }
.rail-btn.rail-active { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.rail-btn.rail-flyopen { background: color-mix(in srgb, var(--brand) 16%, transparent); }
.rail-btn.rail-active::before {          /* акцент-планка зліва */
  content: ''; position: absolute; left: -6px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 3px; background: var(--brand);
}
.rail-ico {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; font-size: 18px;
}
.rail-dot {                              /* крапка = є підпункти */
  position: absolute; right: 6px; bottom: 6px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--muted); opacity: .7;
}

.rail-flyout {
  position: fixed; z-index: 60; min-width: 220px; max-width: 280px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .16);
  max-height: 70vh; overflow-y: auto;
  animation: railFly .14s ease;
}
.rail-flyout.hidden { display: none; }
@keyframes railFly { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: none; } }

.rail-fly-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 5px 10px 6px;
}
.rail-fly-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 10px; text-decoration: none; color: inherit; cursor: pointer;
  transition: background .12s;
}
.rail-fly-item:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.rail-fly-item.rail-fly-active { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.rail-fly-ico {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; font-size: 16px;
  background: var(--soft); color: var(--ink);
}
.rail-fly-txt { display: flex; flex-direction: column; min-width: 0; }
.rail-fly-lbl { font-size: 13px; font-weight: 600; line-height: 1.2; }
.rail-fly-sub { font-size: 10px; color: var(--muted); line-height: 1.2; }

/* ── Перетягування пунктів меню ───────────────────────────────────────────── */

.nav-card[draggable="true"] { cursor: grab; }
.nav-card.dragging { opacity: .4; cursor: grabbing; }
.nav-card.drop-before { box-shadow: 0 -3px 0 -1px var(--brand); }
.nav-card.drop-after  { box-shadow: 0 3px 0 -1px var(--brand); }

/* ── Пошук у шапці + швидкі посилання на системи ──────────────────────────── */

.sb-tools { padding: 0 2px 6px; }
.sb-search { font-size: 13px; padding: 7px 11px; }
.rail.sidebar-rail .sb-tools { display: none; }

.sys-links { display: flex; gap: 4px; margin-top: 8px; }
.sys-link {
  flex: 1; display: grid; place-items: center;
  padding: 6px 0; font-size: 16px; text-decoration: none;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  transition: transform .12s, border-color .12s;
}
.sys-link:hover { transform: translateY(-1px); border-color: var(--brand); }

.search-overlay {
  position: fixed; inset: 0; z-index: 65; background: rgba(0, 0, 0, .28);
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.search-overlay.show { opacity: 1; pointer-events: auto; }

.search-panel {
  position: fixed; z-index: 70; left: calc(var(--rail) + 16px); top: 74px;
  width: min(520px, calc(100vw - var(--rail) - 40px));
  max-height: 70vh; overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .18);
  display: none;
}
.search-panel.show { display: block; animation: railFly .14s ease; }

.search-group {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 8px 10px 4px;
}
.search-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 10px; cursor: pointer;
}
.search-item:hover, .search-item.active { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.search-ico {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px; font-size: 15px;
  display: grid; place-items: center; background: var(--surface-2);
}
.search-txt { display: flex; flex-direction: column; min-width: 0; }
.search-main { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.search-sub { font-size: 11.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .search-panel { left: 12px; top: 62px; width: calc(100vw - 24px); }
}

/* ── Робочі столи (картки відділів) ───────────────────────────────────────── */

.desks {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  min-width: 0;                     /* інакше картки розпирають грід за екран */
}
.desk { min-width: 0; }
.desk h3, .desk .desk-sub { overflow-wrap: anywhere; }

.desk {
  display: block;                       /* не flex: вміст картки йде стовпчиком */
  position: relative; overflow: hidden;
  margin: 0; padding: 18px;
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow);
  cursor: pointer; transition: transform .18s, box-shadow .18s, border-color .18s;
}
.desk:hover { transform: translateY(-2px); border-color: var(--t1); }
.desk.disabled { cursor: default; opacity: .58; }
.desk.disabled:hover { transform: none; border-color: var(--border); }

/* декоративні трикутники, як у шапці Atlas */
.desk .decor { position: absolute; right: -10px; top: -6px; height: 100%; opacity: .5; pointer-events: none; }

.desk-ico {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center; font-size: 23px;
  background: linear-gradient(135deg, var(--t1), var(--t2)); color: #fff;
  box-shadow: 0 8px 18px -8px var(--t1);
}
.desk h3 { margin: 12px 0 2px; font-size: 16px; letter-spacing: -.01em; }
.desk .desk-sub { color: var(--muted); font-size: 12.5px; }

.desk-stats { display: flex; gap: 18px; margin-top: 16px; }
.desk-stat .n { font-size: 22px; font-weight: 700; line-height: 1; }
.desk-stat .l { font-size: 11px; color: var(--muted); }
.desk-stat.hot .n { color: var(--danger); }

.desk-flows { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
  display: grid; gap: 6px; }
.desk-flow { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.desk-flow .n { margin-left: auto; font-weight: 700; color: var(--text); }

/* ── Вкладки процесів усередині столу ─────────────────────────────────────── */

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 13px;
}
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tab .n { opacity: .7; margin-left: 6px; font-weight: 700; }

@media (max-width: 900px) {
  .desks { grid-template-columns: 1fr; }
}
