/* Nivas 5 — обвивка на приложението: марка, режим, навигация.

   Един и същ HTML се подрежда по четири начина според режима и ширината:

   · Админ, монитор (≥ 1440px)      — странична лента с всички раздели наведнъж;
   · Админ, лаптоп (1100–1439px)    — тясна лента с икони, „Още“ се отваря встрани
                                      (същото и на „Табло“, което има свое меню);
   · таблет / Техник на компютър    — хоризонтална лента горе;
   · телефон (≤ 720px)              — лента с икони долу, под палеца.

   Всички правила за лентата живеят само тук. */

:root {
  --nav-w: 0px;
  --tabbar-h: 0px;
}

/* ------------------------------------------------------------------ общи части */

.topbar {
  background: var(--surface);
  color: var(--text);
  /* Цветната линия горе е сигналът за работния режим. */
  border-top: 3px solid var(--mode-accent);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  color: var(--text);
  text-decoration: none;
  border-radius: 9px;
}
.brand-mark { width: 28px; height: 28px; border-radius: 8px; display: block; flex: none; }
.topbar-brand strong { font-size: 14px; font-weight: 650; letter-spacing: .08em; white-space: nowrap; }

.topbar-meta { display: flex; align-items: center; gap: 8px; flex: none; }

.nav-icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.top-actions { display: flex; min-width: 0; }

.top-actions > a,
.settings-toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 0;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.top-actions > a:hover,
.settings-toggle:hover,
.settings-toggle[aria-expanded="true"] { background: var(--surface-3); color: var(--text); }
.top-actions > a.active,
.top-actions > a[aria-current="page"],
.settings-toggle.active {
  background: var(--mode-soft);
  color: var(--text);
  font-weight: 650;
}
.top-actions > a.active .nav-icon,
.top-actions > a[aria-current="page"] .nav-icon,
.settings-toggle.active .nav-icon { color: var(--mode-strong); }
.top-actions > a.has-unread { color: var(--text); }
.top-actions > a:focus-visible,
.settings-toggle:focus-visible { outline: 2px solid var(--mode-accent); outline-offset: -2px; }

/* Бялото кръгче с броя: непрочетени съобщения и неща, които чакат действие.
   Пръстенът пулсира тихо, за да се хване с крайчеца на окото, без да мига. */
.nav-badge {
  position: relative;
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: #fff;
  color: #1d1f33;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3);
}
.nav-badge[hidden] { display: none; }
.nav-badge::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 2px solid #fff;
  border-radius: var(--radius-pill);
  animation: nav-badge-pulse 2.2s ease-out infinite;
  pointer-events: none;
}
.nav-badge.is-new { animation: nav-badge-pop .5s ease-out; }
@keyframes nav-badge-pulse {
  0% { opacity: .8; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.6); }
}
@keyframes nav-badge-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* ------------------------------------------------------------- менюто „Още“ */

.settings-menu { position: relative; display: flex; }
.settings-toggle__label { display: inline; }

.settings-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 80;
  width: 290px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  padding: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.settings-dropdown[hidden] { display: none; }

.settings-dropdown a,
.settings-logout {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  margin: 0;
  padding: 9px 11px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.25;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.settings-dropdown .nav-icon { width: 18px; height: 18px; color: var(--text-muted); }
.settings-dropdown a:hover,
.settings-dropdown a:focus-visible,
.settings-logout:hover,
.settings-logout:focus-visible { background: var(--surface-3); color: var(--text); outline: none; }
.settings-dropdown a:focus-visible,
.settings-logout:focus-visible { box-shadow: inset 0 0 0 2px var(--mode-accent); }
.settings-dropdown a.active { background: var(--mode-soft); color: var(--text); font-weight: 650; }
.settings-dropdown a.active .nav-icon { color: var(--mode-strong); }

.settings-group {
  display: block;
  margin: 8px 0 2px;
  padding: 10px 11px 2px;
  border-top: 1px solid var(--line);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* „Каталог“ и „Система“ са сгънати; разгъват се при натискане и остават
   отворени, когато текущата страница е в тях. */
.settings-section > summary { list-style: none; }
.settings-section > summary::-webkit-details-marker { display: none; }
summary.settings-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-radius: 0 0 9px 9px;
  cursor: pointer;
  user-select: none;
}
summary.settings-group:hover { color: var(--text-soft); }
summary.settings-group:focus-visible { outline: none; color: var(--text); box-shadow: inset 0 0 0 2px var(--mode-accent); }
.settings-section__chevron { width: 14px; height: 14px; flex: 0 0 auto; transition: transform .15s ease; }
.settings-section[open] > summary .settings-section__chevron { transform: rotate(180deg); }
.settings-section[open] > summary { padding-bottom: 4px; }
.settings-section { display: flex; flex-direction: column; gap: 2px; }

.settings-account { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--line); }
.settings-user {
  display: block;
  padding: 2px 11px 4px;
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------- превключвател на режима
   Двата режима се виждат едновременно, активният е запълнен — така текущият
   режим се чете, без бутонът да изглежда като действие. */

.mode-switch {
  display: flex;
  gap: 3px;
  margin: 0;
  padding: 3px;
  background: var(--surface-inset);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
}
.mode-switch button {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.is-active { background: var(--mode-accent); color: #fff; cursor: default; }

/* ------------------------------------------------------ оборот за деня (Техник)
   Датата отгоре с дребни сиви букви; отдолу изпълнени/общо задачи и сумата. */

.revenue-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  padding: 4px 10px;
  border: 1px solid rgba(63, 158, 104, .38);
  border-radius: 10px;
  background: rgba(63, 158, 104, .12);
  line-height: 1.15;
  animation: revenue-chip-glow 3.2s ease-in-out 3;
}
.revenue-chip__day { font-size: 11px; font-weight: 500; letter-spacing: .03em; color: var(--text-muted); white-space: nowrap; }
.revenue-chip__stats { display: inline-flex; align-items: center; gap: 8px; }
.revenue-chip__progress {
  padding-right: 8px;
  border-right: 1px solid var(--line-strong);
  color: var(--text-bright);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.revenue-chip__sum {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  font-weight: 600;
  color: #6fc492;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.revenue-chip.is-up { animation: revenue-chip-pop .7s ease-out; }
@keyframes revenue-chip-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 158, 104, 0); }
  50% { box-shadow: 0 0 0 3px rgba(63, 158, 104, .16); }
}
@keyframes revenue-chip-pop {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(63, 158, 104, .45); }
  40% { transform: scale(1.06); box-shadow: 0 0 0 6px rgba(63, 158, 104, .18); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(63, 158, 104, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .nav-badge.is-new, .revenue-chip, .revenue-chip.is-up { animation: none; }
  .nav-badge::after { animation: none; opacity: .5; transform: scale(1); }
}

/* ===================================================== хоризонтална лента горе
   Таблет в Админ и всичко над телефон в Техник. */

@media (min-width: 721px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 58px;
    padding: 0 max(20px, calc((100% - var(--page-max)) / 2));
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
  }
  .top-actions { order: 2; flex: 1 1 auto; align-items: center; gap: 2px; }
  .topbar-meta { order: 3; }
  .settings-menu { margin-left: auto; }
  .top-actions > a .nav-badge { margin-left: -2px; }
}

/* Между телефон и лаптоп редът е тесен: иконите на връзките отпадат първи. */
@media (min-width: 721px) and (max-width: 940px) {
  .top-actions > a > .nav-icon,
  .topbar-brand strong,
  .settings-toggle__label { display: none; }
  .topbar { gap: 10px; padding: 0 14px; }
  .top-actions > a, .settings-toggle { padding: 8px 10px; }
}

/* =========================================== Админ на компютър: тясна лента вляво */

@media (min-width: 1100px) {
  body.mode-admin[data-shell] { --nav-w: 84px; padding-left: var(--nav-w); }

  body.mode-admin[data-shell] .topbar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: var(--nav-w);
    min-height: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 8px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    box-shadow: none;
    overflow-y: auto;
    scrollbar-width: none;
  }
  body.mode-admin[data-shell] .topbar::-webkit-scrollbar { display: none; }

  body.mode-admin[data-shell] .topbar-brand { justify-content: center; padding: 2px 0; }
  body.mode-admin[data-shell] .topbar-brand strong { display: none; }
  body.mode-admin[data-shell] .brand-mark { width: 34px; height: 34px; border-radius: 10px; }

  body.mode-admin[data-shell] .topbar-meta { order: 1; display: block; }
  body.mode-admin[data-shell] .mode-switch { flex-direction: column; }
  body.mode-admin[data-shell] .mode-switch button { padding: 6px 2px; font-size: 11.5px; }

  body.mode-admin[data-shell] .top-actions {
    order: 2;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  body.mode-admin[data-shell] .top-actions > a,
  body.mode-admin[data-shell] .settings-toggle {
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 100%;
    padding: 9px 2px 8px;
    font-size: 11px;
    font-weight: 550;
    letter-spacing: .01em;
    text-align: center;
  }
  body.mode-admin[data-shell] .top-actions > a .nav-icon,
  body.mode-admin[data-shell] .settings-toggle .nav-icon { width: 22px; height: 22px; }
  body.mode-admin[data-shell] .top-actions .nav-badge {
    position: absolute;
    top: 3px;
    left: calc(50% + 6px);
    margin: 0;
  }
  body.mode-admin[data-shell] .settings-menu { position: static; margin: auto 0 0; }
  body.mode-admin[data-shell] .settings-dropdown {
    position: fixed;
    top: auto;
    right: auto;
    bottom: 12px;
    left: calc(var(--nav-w) + 8px);
    max-height: calc(100vh - 24px);
  }

  /* „Табло“ носи собствено меню за изгледите; то се закача под горния ръб,
     а не под лента, която вече я няма. */
  body.mode-admin[data-shell] .dash-side { top: 18px; max-height: calc(100vh - 36px); }
}

/* ============================== Админ на монитор: пълна странична лента с всичко */

@media (min-width: 1440px) {
  body.mode-admin[data-shell]:not(:has(.dash)) { --nav-w: 264px; }

  body.mode-admin[data-shell]:not(:has(.dash)) .topbar { gap: 14px; padding: 14px 12px 12px; }
  body.mode-admin[data-shell]:not(:has(.dash)) .topbar-brand { justify-content: flex-start; padding: 4px 8px; }
  body.mode-admin[data-shell]:not(:has(.dash)) .topbar-brand strong { display: block; }
  body.mode-admin[data-shell]:not(:has(.dash)) .brand-mark { width: 30px; height: 30px; border-radius: 8px; }
  body.mode-admin[data-shell]:not(:has(.dash)) .mode-switch { flex-direction: row; }
  body.mode-admin[data-shell]:not(:has(.dash)) .mode-switch button { padding: 7px 8px; font-size: 12.5px; }

  body.mode-admin[data-shell]:not(:has(.dash)) .top-actions { gap: 2px; }
  body.mode-admin[data-shell]:not(:has(.dash)) .top-actions > a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 11px;
    padding: 9px 11px;
    font-size: 14px;
    letter-spacing: 0;
    text-align: left;
  }
  body.mode-admin[data-shell]:not(:has(.dash)) .top-actions > a .nav-icon { width: 19px; height: 19px; }
  body.mode-admin[data-shell]:not(:has(.dash)) .top-actions > a .nav-badge { position: relative; top: auto; left: auto; margin-left: auto; }

  /* Тук „Още“ не е бутон: разделите му са разгънати под основните. */
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-toggle { display: none; }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-menu { flex: 1 1 auto; flex-direction: column; margin: 0; }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-dropdown,
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-dropdown[hidden] {
    position: static;
    display: flex !important;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    width: auto;
    max-height: none;
    overflow: visible;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-dropdown a,
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-logout { color: var(--text-muted); font-weight: 550; padding: 8px 11px; }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-dropdown a:hover,
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-logout:hover { color: var(--text); }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-dropdown a.active { color: var(--text); font-weight: 650; }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-dropdown .nav-icon { width: 19px; height: 19px; color: inherit; }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-dropdown a.active .nav-icon { color: var(--mode-strong); }
  body.mode-admin[data-shell]:not(:has(.dash)) .settings-account { margin-top: auto; }
}

/* =================================================== телефон: лента с икони долу */

@media (max-width: 720px) {
  body[data-shell] { --tabbar-h: 60px; }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 50px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--line);
  }
  .brand-mark { width: 30px; height: 30px; }
  /* В „Техник“ първият ред носи и оборота, и режима — името отстъпва на знака. */
  body.mode-technician .topbar-brand strong {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .topbar-meta { min-width: 0; }
  .mode-switch button { min-height: 34px; padding: 5px 10px; }

  .top-actions {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    align-items: stretch;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 4px env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--line-strong);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .4);
  }
  .top-actions > a,
  .settings-menu { flex: 1 1 0; min-width: 0; }
  .settings-menu { position: static; }

  .top-actions > a,
  .settings-toggle {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 100%;
    min-height: 0;
    padding: 6px 2px 5px;
    border-radius: 0;
    background: transparent;
    font-size: 11px;
    font-weight: 550;
    letter-spacing: .01em;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .top-actions > a .nav-icon,
  .settings-toggle .nav-icon { width: 23px; height: 23px; }
  .top-actions > a:hover,
  .settings-toggle:hover { background: transparent; }
  .top-actions > a.active,
  .top-actions > a[aria-current="page"],
  .settings-toggle.active,
  .settings-toggle[aria-expanded="true"] { background: transparent; color: var(--mode-strong); }
  .top-actions > a.active::before,
  .top-actions > a[aria-current="page"]::before,
  .settings-toggle.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    width: 34px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--mode-accent);
    transform: translateX(-50%);
  }
  .top-actions .nav-badge { position: absolute; top: 4px; left: calc(50% + 5px); margin: 0; }

  /* „Още“ се отваря като лист над лентата. */
  .settings-dropdown {
    position: fixed;
    top: auto;
    right: 8px;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
    left: 8px;
    width: auto;
    max-height: min(72vh, 600px);
    border-radius: 16px;
    box-shadow: var(--shadow-lg), 0 0 0 100vmax rgba(6, 8, 11, .6);
  }
  .settings-dropdown a,
  .settings-logout { min-height: 46px; font-size: 15px; }

  /* Съдържанието и залепените ленти с действия отстъпват място на лентата долу. */
  body[data-shell] .page { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 28px); }
  body[data-shell] .sticky-actions { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px); }
}

@media (max-width: 380px) {
  .topbar { padding: 6px 9px; gap: 6px; }
  .mode-switch button { padding: 5px 8px; font-size: 12px; }
  .revenue-chip { padding: 3px 8px; }
  .top-actions > a, .settings-toggle { font-size: 11px; letter-spacing: 0; }
}

@media print {
  .topbar, .skip-link { display: none !important; }
  body[data-shell] { padding-left: 0 !important; }
}

/* „Изкупуване“ и „Фактури“ са в основното меню на Админ, когато то е
   странична лента (≥1100px). На таблет и телефон лентата няма място за тях –
   там остават в „Още“, заедно с числото върху него. */
@media (min-width: 1100px) {
  .settings-dropdown [data-nav-dup] { display: none; }
  body.mode-admin .settings-toggle .nav-badge { display: none; }
}
@media (max-width: 1099px) {
  .top-actions > a[data-nav-wide] { display: none; }
}
/* „!“ – записи от сайта не са пристигнали; стои до числото на неотворените. */
.nav-badge--alert { background: var(--danger, #d4483b); margin-left: 3px; }
