/* =====================================================================
   Kvill — Visual Polish: Toolbar & Sidebar
   Premium glassmorphic toolbar + refined sidebar drawer

   HTML CHANGES NEEDED:
   ────────────────────
   1. In <header class="m-toolbar"> — no HTML changes needed, CSS-only polish.

   2. In .m-sidebar-footer, wrap the theme + logout buttons in a div:
      BEFORE:
        <button class="m-sidebar-footer-btn" id="mThemeToggle">...</button>
        <button class="m-sidebar-footer-btn" id="mLogoutBtn">...</button>
      AFTER:
        <div class="m-sidebar-footer-actions">
          <button class="m-sidebar-footer-btn" id="mThemeToggle">...</button>
          <button class="m-sidebar-footer-btn" id="mLogoutBtn">...</button>
        </div>

   3. Optionally add .m-sidebar-empty inside .m-sidebar-list for empty state:
      <div class="m-sidebar-empty">Нет сохранённых презентаций</div>

   LOAD ORDER: After mobile.css
   ===================================================================== */


/* =====================================================================
   TOOLBAR — Glassmorphic top bar
   ===================================================================== */

.m-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  padding-top: max(10px, calc(var(--m-safe-top) + 4px));
  background: var(--m-toolbar-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--m-toolbar-shadow);
}

[data-theme="dark"] .m-toolbar {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

/* ─── Toolbar buttons ─── */

.m-toolbar-btn {
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-1);
  cursor: pointer;
  border-radius: 10px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.2s var(--ease), color 0.2s var(--ease),
              transform 0.15s var(--ease);
  position: relative;
}

.m-toolbar-btn:active {
  background: var(--accent-subtle);
  transform: scale(0.92);
}

.m-toolbar-btn svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s var(--ease-spring);
}

/* Hamburger animation hint on hover/active */
.m-toolbar-btn#menuBtn:active svg {
  transform: scale(0.9);
}

/* Theme toggle rotation */
.m-toolbar-btn#themeBtn svg {
  transition: transform 0.5s var(--ease-spring);
}

.m-toolbar-btn#themeBtn:active svg {
  transform: rotate(30deg) scale(0.9);
}

/* ─── Toolbar center ─── */

.m-toolbar-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  gap: 2px;
}

/* ─── Title — premium typography ─── */

.m-toolbar-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  color: var(--text-0);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
  line-height: 1.2;
}

.m-toolbar-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
  margin-top: -1px;
}

/* ─── Slide counter — glass pill badge ─── */

.m-slide-counter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--accent-subtle);
  padding: 3px 12px;
  border-radius: 20px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease-spring);
}

[data-theme="dark"] .m-slide-counter {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}


/* =====================================================================
   SIDEBAR SCRIM — Smooth overlay backdrop
   ===================================================================== */

.m-sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 9499;
  background: transparent;
  pointer-events: none;
  transition: background 0.35s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.m-sidebar-scrim.active {
  background: rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

[data-theme="dark"] .m-sidebar-scrim.active {
  background: rgba(0, 0, 0, 0.55);
}


/* =====================================================================
   SIDEBAR DRAWER — Premium glass panel
   ===================================================================== */

.m-sidebar-drawer {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: min(300px, 85vw);
  z-index: 9500;
  background: var(--m-sidebar-bg);
  border-right: 1px solid var(--m-panel-border);
  box-shadow: 4px 0 32px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  transform: translateX(-105%);
  transition: transform 0.4s var(--ease-spring);
  will-change: transform;
}

[data-theme="dark"] .m-sidebar-drawer {
  background: #1a1a1e;
  border-right-color: rgba(255, 255, 255, 0.08);
  box-shadow: 4px 0 32px rgba(0, 0, 0, 0.5);
}

.m-sidebar-drawer.open {
  transform: translateX(0);
}

/* ─── Sidebar header ─── */

/* Sidebar header — clean, no border, no gradient (matches desktop) */
.m-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 8px;
  padding-top: max(12px, calc(var(--m-safe-top) + 4px));
  border-bottom: none;
  flex-shrink: 0;
  white-space: nowrap;
}

.m-sidebar-header::after {
  display: none;
}

/* ─── Logo ─── */

.m-sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.m-sidebar-header .logo-mark {
  width: 28px;
  height: 24px;
}

.m-sidebar-header .logo-text {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-0);
  letter-spacing: -0.3px;
}


/* ─── New presentation button — accent CTA ─── */

.m-sidebar-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 24px);
  margin: 8px 12px 12px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-0);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s var(--ease),
              background 0.15s var(--ease);
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

/* No shine overlay — flat button */
.m-sidebar-new-btn::before {
  display: none;
}

.m-sidebar-new-btn:hover {
  background: var(--bg-input-hover);
}

.m-sidebar-new-btn:active {
  transform: scale(0.97);
}

.m-sidebar-new-btn svg {
  width: 16px;
  height: 16px;
  stroke: var(--text-1);
}


/* ─── Presentation list ─── */

.m-sidebar-list {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.m-sidebar-list::-webkit-scrollbar {
  width: 3px;
}

.m-sidebar-list::-webkit-scrollbar-track {
  background: transparent;
}

.m-sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ─── Presentation item — compact, matches desktop ─── */

.m-sidebar-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  min-height: 32px;
  padding: 0;
  margin: 0 4px;
  cursor: pointer;
  border-radius: 6px;
  border-left: none;
  overflow: hidden;
  position: relative;
  isolation: isolate;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.m-sidebar-item:hover .m-sidebar-item-content {
  background: rgba(0, 0, 0, 0.04);
}

.m-sidebar-item:active .m-sidebar-item-content {
  background: rgba(0, 0, 0, 0.06);
}

/* Active item — subtle bg like desktop */
.m-sidebar-item.active .m-sidebar-item-content {
  background: var(--accent-subtle);
}

.m-sidebar-item.active .m-sidebar-item-title {
  font-weight: 500;
  color: var(--text-0);
}

[data-theme="dark"] .m-sidebar-item:hover .m-sidebar-item-content {
  background: rgba(255, 255, 255, 0.05);
}
[data-theme="dark"] .m-sidebar-item:active .m-sidebar-item-content {
  background: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .m-sidebar-item.active .m-sidebar-item-content {
  background: var(--accent-subtle);
}

/* Item title — match desktop: 13px, normal weight */
.m-sidebar-item-title {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
}

.m-sidebar-item.active .m-sidebar-item-title {
  font-weight: 500;
  color: var(--text-0);
}

/* Item date — hidden like desktop */
.m-sidebar-item-date {
  display: none;
}

/* Item icon — matches folder icon weight/contrast */
.m-sidebar-item-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.m-sidebar-item-icon svg {
  width: 16px;
  height: 16px;
  color: var(--text-2);
}

/* Item content — swipe wrapper (row: icon + title)
   MUST stay opaque to hide swipe-action buttons behind it.
   z-index:1 + position:relative ensures it stacks above .m-sidebar-swipe-actions (z-index:0). */
.m-sidebar-item-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 6px;
  background: transparent;
  position: relative;
  z-index: 1;
  will-change: transform;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Empty state for sidebar list */
.m-sidebar-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 32px 16px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  line-height: 1.5;
}


/* ─── Sidebar footer — compact bar, profile+balance left, theme right ─── */

/* Sidebar footer — clean, no border (matches desktop) */
.m-sidebar-footer {
  display: flex;
  align-items: center;
  padding: 8px;
  padding-bottom: max(8px, calc(var(--m-safe-bottom) + 4px));
  border-top: none;
  flex-shrink: 0;
  gap: 4px;
  margin-top: auto;
}

/* Balance — interactive, same height as footer buttons (32px) */
.m-sidebar-balance {
  font-size: 13px;
  font-weight: 425;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  background: none;
  height: 32px;
  padding: 0 8px;
  border: none;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease;
}

.m-sidebar-balance:hover {
  color: var(--text-0);
  background: var(--bg-input);
}

.m-sidebar-balance:active {
  color: var(--text-0);
  background: var(--bg-input-hover);
}

/* Theme toggle — inline with other footer buttons, no push right */

/* Footer buttons — compact */
.m-sidebar-footer-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}

.m-sidebar-footer-btn:active {
  background: var(--bg-input);
  color: var(--text-0);
}

.m-sidebar-footer-btn svg {
  width: 16px;
  height: 16px;
}


/* =====================================================================
   BREAKPOINT OVERRIDES
   ===================================================================== */

@media (max-width: 380px) {
  .m-toolbar {
    padding: 8px 10px;
    padding-top: max(8px, calc(var(--m-safe-top) + 2px));
  }

  .m-toolbar-title {
    font-size: 15px;
  }

  .m-sidebar-drawer {
    width: min(300px, 90vw);
  }
}


/* =====================================================================
   ACCESSIBILITY — Reduced motion
   ===================================================================== */

@media (prefers-reduced-motion: reduce) {
  .m-toolbar-btn svg,
  .m-sidebar-footer-btn svg,
  .m-sidebar-drawer,
  .m-sidebar-scrim,
  .m-sidebar-new-btn,
  .m-sidebar-item {
    transition-duration: 0.01ms !important;
  }
}


/* =====================================================================
   iOS SAFARI FIXES
   ===================================================================== */

@supports (-webkit-touch-callout: none) {
  .m-sidebar-drawer {
    -webkit-overflow-scrolling: auto;
    isolation: isolate;
  }
}


/* =====================================================================
   DESKTOP BREAKPOINTS — Toolbar & Sidebar
   ===================================================================== */

@media (min-width: 768px) {

  /* ── Toolbar: HIDDEN on desktop (sidebar has its own branding) ── */
  .m-toolbar {
    display: none !important;
  }

  /* ── Sidebar: always visible, not a drawer ── */
  .m-sidebar-drawer {
    position: relative;
    transform: none !important;
    width: var(--m-sidebar-width, 280px);
    min-width: var(--m-sidebar-width, 280px);
    z-index: auto;
    border-right: 1px solid var(--sidebar-border, var(--border));
    box-shadow: none;
    will-change: auto;
    transition: width 0.3s var(--ease), min-width 0.3s var(--ease),
                opacity 0.3s var(--ease);
  }

  [data-theme="dark"] .m-sidebar-drawer {
    box-shadow: none;
  }

  /* Sidebar collapsed — show icon strip at 48px */
  .m-sidebar-drawer.m-sidebar-collapsed {
    width: 48px;
    min-width: 48px;
    overflow: hidden;
  }

  .m-sidebar-drawer.m-sidebar-collapsed .m-sidebar-content {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    width: 0;
  }

  .m-sidebar-drawer.m-sidebar-collapsed .m-sidebar-strip {
    display: flex;
  }

  /* Hide scrim on desktop */
  .m-sidebar-scrim {
    display: none !important;
  }

  /* Sidebar header padding: no safe-area needed, compact */
  .m-sidebar-header {
    padding: 12px 10px 8px;
  }

  /* Hover states for desktop */
  .m-sidebar-item:hover .m-sidebar-item-content {
    background: var(--bg-input);
  }

  .m-sidebar-new-btn:hover {
    background: var(--bg-input-hover);
    border-color: var(--border-hover);
  }

  .m-sidebar-footer-btn:hover {
    background: var(--bg-input);
    color: var(--text-0);
  }

  .m-sidebar-header-btn:hover {
    background: var(--bg-input);
    color: var(--text-0);
  }
}

@media (min-width: 1024px) {
  /* .m-toolbar hidden via 768px rule */
}
