/* ══════════════════════════════════════════════════════════════════
   IDISI — BASE & TYPOGRAPHY (VIDEOMAKER SOFT FROSTED MONOCHROME)
   ══════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 15px;
  background-color: var(--bg-base);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body {
  font-family: var(--font);
  background: var(--body-bg);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.45;
  letter-spacing: -0.012em;
  scrollbar-width: none;
  -ms-overflow-style: none;
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}

/* Zero Visible Native Scrollbars (Pure Sleek Experience) */
*::-webkit-scrollbar,
::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
}

/* Application Layout Shell */
.app-layout {
  width: 100%;
  min-height: 100dvh;
  position: relative;
  transition: all 0.35s var(--ease);
}

/* View Container — Dynamic Fluid & Responsive Architecture */
.view-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 16px 14px calc(110px + env(safe-area-inset-bottom, 0px));
  min-height: calc(100dvh - 72px);
  position: relative;
  transition: max-width 0.35s var(--ease), padding 0.35s var(--ease);
}

/* Tablets (iPad, 768px+) */
@media (min-width: 768px) {
  .view-container {
    max-width: var(--container-tablet, 960px);
    padding: 20px 24px 120px;
  }
}

/* Laptops & Standard Monitors (1024px+) */
@media (min-width: 1024px) {
  .view-container {
    max-width: var(--container-desktop, 1360px);
    padding: 24px 36px calc(130px + env(safe-area-inset-bottom, 0px));
  }
}

/* Ultra-wide & Large Screens (1440px+) */
@media (min-width: 1440px) {
  .view-container {
    max-width: var(--container-widescreen, 1600px);
    padding: 28px 48px calc(130px + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Режим телефона на ПК и Ноутбуках (по долгому нажатию ESC или кнопке) ── */
[data-layout-mode="phone"] .app-layout,
[data-layout-mode="compact"] .app-layout {
  max-width: 440px !important;
  margin: 16px auto !important;
  min-height: calc(100dvh - 32px) !important;
  background: var(--bg-surface) !important;
  border-radius: 28px !important;
  border: 1px solid var(--border-light) !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22), 0 0 0 1px var(--border) !important;
  overflow: hidden !important;
  transition: all 0.35s var(--ease);
}

[data-layout-mode="phone"] .header-inner,
[data-layout-mode="compact"] .header-inner {
  max-width: 100% !important;
  padding: 12px 14px !important;
}

[data-layout-mode="phone"] .view-container,
[data-layout-mode="compact"] .view-container {
  max-width: 100% !important;
  padding: 14px 14px calc(130px + env(safe-area-inset-bottom, 0px)) !important;
  margin: 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
}

[data-layout-mode="phone"] .books-grid,
[data-layout-mode="compact"] .books-grid {
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 12px !important;
}

[data-layout-mode="phone"] .orders-list,
[data-layout-mode="compact"] .orders-list,
[data-layout-mode="phone"] .acts-list,
[data-layout-mode="compact"] .acts-list,
[data-layout-mode="phone"] .special-list,
[data-layout-mode="compact"] .special-list {
  grid-template-columns: 1fr !important;
  gap: 12px !important;
}

[data-layout-mode="phone"] .bottom-nav,
[data-layout-mode="compact"] .bottom-nav {
  max-width: 410px !important;
}

[data-layout-mode="phone"] .desktop-hotkey,
[data-layout-mode="compact"] .desktop-hotkey {
  display: none !important;
}

[data-layout-mode="phone"] .sheet-backdrop,
[data-layout-mode="compact"] .sheet-backdrop {
  align-items: flex-end !important;
  padding: 0 !important;
}

[data-layout-mode="phone"] .sheet-panel,
[data-layout-mode="compact"] .sheet-panel {
  max-width: 100% !important;
  border-radius: var(--r-xl) var(--r-xl) 0 0 !important;
}

[data-layout-mode="phone"] .sheet-handle-bar,
[data-layout-mode="compact"] .sheet-handle-bar {
  display: block !important;
}

/* ── ESC Long Press (2s) HUD Indicator ─────────────────────────── */
.esc-hold-hud {
  position: fixed;
  top: calc(86px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translate(-50%, -20px) scale(0.92);
  opacity: 0;
  visibility: hidden;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px 10px 14px;
  background: rgba(14, 14, 16, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  border-radius: var(--r-full);
  pointer-events: none;
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease), visibility 0.22s var(--ease);
  font-family: var(--font);
}

.esc-hold-hud.active {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0) scale(1);
}

.esc-ring-wrap {
  width: 38px;
  height: 38px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.esc-ring-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.esc-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.14);
  stroke-width: 3.5;
}

.esc-ring-progress {
  fill: none;
  stroke: #ffffff;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset 0.05s linear;
}

.esc-hud-key {
  font-size: 10px;
  font-weight: 850;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #fff;
  letter-spacing: -0.02em;
}

.esc-hud-content {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.esc-hud-title {
  font-size: 13px;
  font-weight: 750;
  color: #ffffff;
  line-height: 1.2;
}

.esc-hud-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

/* ESC HUD Light Theme Adaptive Styling */
[data-theme="light"] .esc-hold-hud {
  background: var(--sheet-bg);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg), var(--border-specular);
}

[data-theme="light"] .esc-hud-title {
  color: var(--text-main);
}

[data-theme="light"] .esc-hud-sub {
  color: var(--text-muted);
}

[data-theme="light"] .esc-hud-key {
  color: var(--text-main);
}

[data-theme="light"] .esc-ring-bg {
  stroke: var(--border-light);
}

[data-theme="light"] .esc-ring-progress {
  stroke: var(--accent);
}

/* Header (Frosted Glass Full-Width Sticky Bar) */
.app-header {
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--header-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s var(--ease), border-color 0.3s var(--ease);
}

.header-inner {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: max-width 0.35s var(--ease), padding 0.35s var(--ease);
}

@media (min-width: 768px) {
  .header-inner {
    max-width: var(--container-tablet, 960px);
    padding: 14px 24px;
  }
}

@media (min-width: 1024px) {
  .header-inner {
    max-width: var(--container-desktop, 1360px);
    padding: 16px 36px;
  }
}

@media (min-width: 1440px) {
  .header-inner {
    max-width: var(--container-widescreen, 1600px);
    padding: 18px 48px;
  }
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--glass-card);
  backdrop-filter: var(--blur-sm);
  -webkit-backdrop-filter: var(--blur-sm);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  transition: all 0.25s var(--ease);
}

.brand-logo-icon:hover {
  border-color: var(--border-light);
  background: var(--glass-card-hover);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.brand-logo-icon:active {
  transform: scale(0.92);
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.025em;
  color: var(--text-main);
  line-height: 1.15;
}

.brand-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
  transition: color 0.2s var(--ease);
}

.brand-status-chip:hover {
  color: var(--text-main);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--text-main);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
  animation: pulseDot 2.4s infinite ease-in-out;
  transition: all 0.25s var(--ease);
}

.brand-status-chip:hover .status-dot {
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--glass-pill);
  backdrop-filter: var(--blur-sm);
  -webkit-backdrop-filter: var(--blur-sm);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.header-btn svg,
.quick-action-btn svg,
.header-btn svg path,
.header-btn svg line,
.quick-action-btn svg path,
.quick-action-btn svg line {
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
}

.header-btn:hover {
  background: var(--glass-bg-hover);
  border-color: var(--border-light);
  color: var(--text-main);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}

.header-btn:active {
  transform: var(--press-scale);
}

.header-btn.primary {
  background: var(--glass-card);
  border-color: var(--border-light);
  color: var(--text-main);
}

.header-btn.primary:hover {
  background: var(--glass-card-hover);
  border-color: var(--border-focus);
  color: var(--text-main);
  box-shadow: var(--shadow-glow);
}

@keyframes headerSpin {
  100% { transform: rotate(360deg); }
}

.header-btn.spinning svg {
  animation: headerSpin 0.6s linear infinite;
}

/* ── Theme Switcher Micro-Animations ───────────────────────────── */
.theme-toggle-btn {
  position: relative;
  overflow: hidden;
}

.theme-toggle-btn svg {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -9px;
  margin-left: -9px;
  transition: transform 0.4s var(--spring), opacity 0.25s var(--ease), color 0.25s var(--ease);
  will-change: transform, opacity;
}

/* In Dark Mode (default): Show Moon icon */
:root:not([data-theme="light"]) .theme-toggle-btn .theme-icon-sun,
[data-theme="dark"] .theme-toggle-btn .theme-icon-sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.3);
  pointer-events: none;
}

:root:not([data-theme="light"]) .theme-toggle-btn .theme-icon-moon,
[data-theme="dark"] .theme-toggle-btn .theme-icon-moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  color: #f1f5f9;
}

:root:not([data-theme="light"]) .theme-toggle-btn:hover .theme-icon-moon,
[data-theme="dark"] .theme-toggle-btn:hover .theme-icon-moon {
  color: #38bdf8;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.65));
}

/* In Light Mode: Show Sun icon */
[data-theme="light"] .theme-toggle-btn .theme-icon-moon {
  opacity: 0;
  transform: rotate(90deg) scale(0.3);
  pointer-events: none;
}

[data-theme="light"] .theme-toggle-btn .theme-icon-sun {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  color: var(--yandex);
  filter: drop-shadow(0 0 4px rgba(204, 123, 53, 0.25));
}

[data-theme="light"] .theme-toggle-btn:hover .theme-icon-sun {
  color: var(--yandex-light);
  transform: rotate(45deg) scale(1.12);
  filter: drop-shadow(0 0 6px rgba(204, 123, 53, 0.4));
}

/* Smooth Section Transitions */
.view-section {
  animation: fadeInSoft 0.3s var(--ease);
}

@keyframes fadeInSoft {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive Utilities */
.desktop-only {
  display: none !important;
}

.mobile-only {
  display: inline-flex !important;
}

/* Explicit device attribute overrides from detection */
html[data-device="desktop"] .desktop-only {
  display: inline-flex !important;
}
html[data-device="desktop"] .mobile-only {
  display: none !important;
}
html[data-device="mobile"] .desktop-only {
  display: none !important;
}
html[data-device="mobile"] .mobile-only {
  display: inline-flex !important;
}

/* Media query fallback */
@media (min-width: 768px) {
  html:not([data-device="mobile"]) .desktop-only {
    display: inline-flex !important;
  }
  html:not([data-device="mobile"]) .mobile-only {
    display: none !important;
  }
}

/* ── Screen Layout Mode Switcher Button ───────────────────────── */
.layout-toggle-btn {
  position: relative;
  transition: all 0.25s var(--ease);
}

.layout-toggle-btn:hover {
  color: var(--text-main);
  border-color: var(--border-focus);
}

.layout-toggle-btn.active {
  background: var(--glass-card-hover);
  border-color: var(--border-light);
  color: var(--accent);
}

/* Tooltip for desktop button hover */
@media (hover: hover) and (pointer: fine) {
  .header-btn[title]:hover::after {
    content: attr(title);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 10, 10, 0.94);
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: var(--r-xs);
    white-space: nowrap;
    pointer-events: none;
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
    z-index: 100;
    animation: fadeInSoft 0.15s ease;
  }
}

/* ── Exit Overlay (После завершения сессии) ───────────────────────── */
.app-exit-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(8, 10, 16, 0.96);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.app-exit-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.exit-overlay-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  padding: 36px 28px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  animation: modalPopIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.exit-overlay-icon {
  width: 68px;
  height: 68px;
  border-radius: var(--r-full);
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px auto;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.exit-overlay-card h2 {
  font-size: 22px;
  font-weight: 750;
  color: var(--text-main);
  margin-bottom: 10px;
}

.exit-overlay-card p {
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.5;
  margin-bottom: 24px;
}
