/* ============ Тёмная тема ============ */
:root, body[data-theme="dark"] {
  --bg-0: #0a0e1a;
  --bg-1: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #293548;
  --border: rgba(148, 163, 184, 0.12);
  --border-hover: rgba(148, 163, 184, 0.25);

  --text-0: #f1f5f9;
  --text-1: #cbd5e1;
  --text-2: #94a3b8;
  --text-3: #64748b;

  --accent-1: #38bdf8;
  --accent-2: #818cf8;
  --accent-grad: linear-gradient(135deg, #38bdf8 0%, #818cf8 100%);

  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --purple: #a855f7;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
  --shadow-modal: 0 24px 80px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(148, 163, 184, 0.1);

  --bg-radial:
    radial-gradient(at 20% 0%, rgba(56, 189, 248, 0.08) 0px, transparent 50%),
    radial-gradient(at 80% 100%, rgba(129, 140, 248, 0.08) 0px, transparent 50%);

  --surface: rgba(30, 41, 59, 0.95);
  --surface-solid: #1e293b;
}

body[data-theme="light"] {
  --bg-0: #f1f5f9;
  --bg-1: #ffffff;
  --bg-2: #ffffff;
  --bg-3: #e2e8f0;
  --border: rgba(15, 23, 42, 0.08);
  --border-hover: rgba(15, 23, 42, 0.2);

  --text-0: #0f172a;
  --text-1: #1e293b;
  --text-2: #475569;
  --text-3: #94a3b8;

  --accent-1: #0284c7;
  --accent-2: #6366f1;
  --accent-grad: linear-gradient(135deg, #0284c7 0%, #6366f1 100%);

  --shadow-sm: 0 1px 4px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 8px 32px rgba(15, 23, 42, 0.15);
  --shadow-modal: 0 24px 80px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.05);

  --bg-radial:
    radial-gradient(at 20% 0%, rgba(2, 132, 199, 0.05) 0px, transparent 50%),
    radial-gradient(at 80% 100%, rgba(99, 102, 241, 0.05) 0px, transparent 50%);

  --surface: #ffffff;
  --surface-solid: #ffffff;
}

:root {
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --modal-dur: 320ms;
  --modal-ease: cubic-bezier(0.34, 1.32, 0.64, 1);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-0);
  background-image: var(--bg-radial);
  background-attachment: fixed;
  color: var(--text-0);
  margin: 0;
  padding: 24px;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.embed { padding: 14px; background-image: none; }

h1, h2, h3 { color: var(--text-0); margin-top: 0; letter-spacing: -0.02em; font-weight: 700; }
h1 {
  font-size: 28px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: inline-block;
  margin-bottom: 20px;
}
h2 { font-size: 20px; margin-bottom: 16px; }
h3 { font-size: 16px; margin-bottom: 12px; color: var(--accent-1); }

a { color: var(--accent-1); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-2); }

/* ============ Topbar ============ */
.topbar {
  position: relative;
  z-index: 1000;
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  box-shadow: var(--shadow-md);
}
body[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.95); }

.topbar > a:not(.btn):not(.logout-btn):not(.theme-toggle) {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  font-size: 13px;
  transition: var(--transition);
  white-space: nowrap;
  position: relative;
}
.topbar > a:not(.btn):not(.logout-btn):not(.theme-toggle):hover {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-1);
}
.topbar .right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.icon-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-shrink: 0;
}
body[data-theme="light"] .icon-switch { background: #f1f5f9; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 26px;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  color: var(--text-3);
  line-height: 1;
}
.icon-btn:hover {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent-1);
  text-decoration: none;
}
.icon-btn.active {
  background: var(--accent-grad);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(56, 189, 248, 0.25);
}

.user-menu {
  position: relative;
  display: inline-block;
  z-index: 2000;
  flex-shrink: 0;
  max-width: 260px;
  min-width: 0;
}
.user-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border);
  color: var(--text-0);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: none;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
  max-width: 100%;
  min-width: 0;
}
.user-btn .user-name {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 190px;
}
body[data-theme="light"] .user-btn { background: #f1f5f9; }
.user-btn:hover {
  border-color: var(--accent-1);
  background: rgba(56, 189, 248, 0.08);
  transform: none;
  box-shadow: none;
}
.user-btn .chev {
  font-size: 10px;
  color: var(--text-3);
  flex-shrink: 0;
}
.user-menu.open .user-btn .chev { transform: rotate(180deg); }

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 210px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 3000;
  transform-origin: top right;
}
body[data-theme="light"] .user-dropdown { background: #ffffff; }
.user-menu.open .user-dropdown { display: block; animation: ddFade 0.15s ease-out; }
@keyframes ddFade {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dd-link {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-1);
  text-decoration: none;
  white-space: nowrap;
}
.dd-link:hover { background: rgba(56, 189, 248, 0.08); color: var(--accent-1); text-decoration: none; }
.dd-link.dd-danger { color: #f87171; }
.dd-link.dd-danger:hover { background: rgba(239, 68, 68, 0.12); color: #ef4444; }

table {
  position: relative;
  z-index: 1;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 16px;
  background: var(--surface);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
body[data-theme="light"] table { background: #ffffff; }

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
th {
  background: rgba(15, 23, 42, 0.5);
  color: var(--text-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 11px;
}
body[data-theme="light"] th { background: #f8fafc; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(56, 189, 248, 0.04); }

button, .btn {
  background: var(--accent-grad);
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  margin-right: 4px;
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.2);
}
button:hover, .btn:hover {
  color: #ffffff;
}
.btn-danger  { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); color: white; }
.btn-danger:hover  { color: white; }
.btn-success { background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); color: white; }
.btn-success:hover { color: white; }
.btn-gray    { background: rgba(71, 85, 105, 0.6); color: var(--text-0); box-shadow: none; }
body[data-theme="light"] .btn-gray { background: #e2e8f0; color: #334155; }
.btn-gray:hover { color: var(--text-0); }
.btn-edit    { background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); color: white; }
.btn-remind  { background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%); color: white; }

input, select, textarea {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.5);
  color: var(--text-0);
  font-family: inherit;
  font-size: 13px;
  margin: 4px 0;
}
body[data-theme="light"] input,
body[data-theme="light"] select,
body[data-theme="light"] textarea { background: #ffffff; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.flash {
  padding: 12px 18px;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.9), rgba(22, 163, 74, 0.9));
  color: white;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  font-weight: 500;
  position: relative;
  z-index: 500;
}
.flash-error { background: linear-gradient(135deg, rgba(239, 68, 68, 0.9), rgba(220, 38, 38, 0.9)); }

.card {
  background: var(--surface);
  backdrop-filter: blur(10px);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 1;
}
body[data-theme="light"] .card { background: #ffffff; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

.stat {
  display: inline-block;
  background: var(--surface);
  padding: 16px 24px;
  border-radius: var(--radius-lg);
  margin-right: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  min-width: 120px;
  position: relative;
  z-index: 1;
}
body[data-theme="light"] .stat { background: #ffffff; }
.stat b { font-size: 26px; background: var(--accent-grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; display: block; margin-top: 4px; }

.tabs {
  position: relative;
  z-index: 1;
  margin: 20px 0 0;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.tab {
  display: inline-flex; align-items: center;
  padding: 12px 20px;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  position: relative;
}
.tab:hover { color: var(--text-0); background: rgba(56, 189, 248, 0.05); text-decoration: none; }
.tab.active { color: var(--accent-1); background: rgba(56, 189, 248, 0.08); }
.tab.active::after { content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 2px; background: var(--accent-grad); }
.tab .badge { display: inline-block; background: rgba(71, 85, 105, 0.8); color: white; border-radius: 10px; padding: 2px 8px; font-size: 11px; margin-left: 8px; font-weight: 700; }
.tab.active .badge { background: var(--accent-grad); color: #0f172a; }

.perm-badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 5px; font-size: 11px; margin-right: 4px; font-weight: 600; }
.perm-yes { background: rgba(22, 101, 52, 0.6); color: #86efac; }
body[data-theme="light"] .perm-yes { background: #dcfce7; color: #166534; }
.perm-no  { background: rgba(127, 29, 29, 0.6); color: #fca5a5; }
body[data-theme="light"] .perm-no { background: #fee2e2; color: #991b1b; }

.cancel-client { color: var(--warning); font-weight: 600; }
.cancel-staff  { color: var(--danger); font-weight: 600; }

.audit-actor { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.actor-client { background: rgba(120, 53, 15, 0.5); color: #fbbf24; }
.actor-staff  { background: rgba(127, 29, 29, 0.5); color: #fca5a5; }
.actor-super  { background: rgba(30, 58, 138, 0.5); color: #93c5fd; }
.actor-system { background: rgba(51, 65, 85, 0.6); color: #cbd5e1; }
body[data-theme="light"] .actor-client { background: #fef3c7; color: #92400e; }
body[data-theme="light"] .actor-staff  { background: #fee2e2; color: #991b1b; }
body[data-theme="light"] .actor-super  { background: #dbeafe; color: #1e40af; }
body[data-theme="light"] .actor-system { background: #e2e8f0; color: #334155; }

.salon-logo {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
}

.hint { color: var(--text-3); font-size: 12px; margin-top: 4px; }

.reg-open-banner,
.reg-closed-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 14px;
  flex-wrap: wrap;
  position: relative;
  z-index: 1;
}
.reg-open-banner { background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.35); color: #86efac; }
body[data-theme="light"] .reg-open-banner { color: #166534; }
.reg-closed-banner { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.35); color: #fca5a5; }
body[data-theme="light"] .reg-closed-banner { color: #991b1b; }

.today-card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 1;
}
body[data-theme="light"] .today-card { background: #ffffff; }

.today-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}
.today-sub { color: var(--text-2); font-size: 13px; }
.today-sub b { color: var(--text-0); }

.today-legend { display: flex; align-items: center; font-size: 12px; color: var(--text-2); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.legend-free { background: rgba(34, 197, 94, 0.35); border: 1px solid rgba(34, 197, 94, 0.6); }
.legend-busy { background: rgba(239, 68, 68, 0.85); }
.legend-past { background: rgba(100, 116, 139, 0.25); }
.legend-break {
  background: repeating-linear-gradient(45deg,
    rgba(120, 53, 15, 0.35), rgba(120, 53, 15, 0.35) 3px,
    rgba(120, 53, 15, 0.55) 3px, rgba(120, 53, 15, 0.55) 6px);
}

.schedule-scroll { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }
.schedule-table { margin: 0; border: none; border-radius: 0; min-width: 100%; font-size: 12px; }
.schedule-table th,
.schedule-table td { padding: 6px 4px; text-align: center; font-size: 11px; border-bottom: 1px solid var(--border); min-width: 42px; }
.schedule-table thead th { background: rgba(15, 23, 42, 0.7); color: var(--text-2); font-weight: 600; position: sticky; top: 0; z-index: 2; }
body[data-theme="light"] .schedule-table thead th { background: #f1f5f9; }

.schedule-table .time-h.now-h { background: rgba(56, 189, 248, 0.25); color: var(--accent-1); }
.schedule-table .sticky-col {
  position: sticky; left: 0;
  background: rgba(15, 23, 42, 0.95);
  text-align: left;
  padding-left: 12px;
  min-width: 140px;
  z-index: 3;
  border-right: 1px solid var(--border);
}
body[data-theme="light"] .schedule-table .sticky-col { background: #f8fafc; }
.schedule-table thead .sticky-col { z-index: 4; }
.schedule-table .w-name { font-weight: 600; font-size: 13px; color: var(--text-0); }

.st-free { background: rgba(34, 197, 94, 0.08); }
.st-free::after {
  content: '';
  display: block;
  width: 12px; height: 12px;
  margin: 0 auto;
  border-radius: 3px;
  background: rgba(34, 197, 94, 0.35);
  border: 1px solid rgba(34, 197, 94, 0.6);
}
.st-busy { background: rgba(239, 68, 68, 0.15); color: rgba(239, 68, 68, 0.9); font-size: 14px; font-weight: 700; cursor: help; }
body[data-theme="light"] .st-busy { color: #dc2626; }
.st-past { background: rgba(100, 116, 139, 0.06); }

.st-break {
  background: repeating-linear-gradient(45deg,
    rgba(120, 53, 15, 0.35), rgba(120, 53, 15, 0.35) 4px,
    rgba(120, 53, 15, 0.55) 4px, rgba(120, 53, 15, 0.55) 8px);
  color: #fbbf24;
  font-size: 14px;
  font-weight: 700;
  cursor: help;
}
body[data-theme="light"] .st-break { color: #92400e; }

.schedule-table .st-free { cursor: pointer; }
.schedule-table .st-free:hover {
  background: rgba(56, 189, 248, 0.35);
  box-shadow: inset 0 0 0 2px var(--accent-1);
}
.schedule-table .st-free::after {
  content: '+';
  display: block;
  font-size: 14px;
  color: rgba(34, 197, 94, 0.9);
  font-weight: 700;
  margin-top: -2px;
}
.schedule-table .st-free:hover::after { color: #0f172a; }
body[data-theme="light"] .schedule-table .st-free:hover::after { color: #0369a1; }

.schedule-table .total-h,
.schedule-table .total-cell {
  background: rgba(15, 23, 42, 0.5);
  font-weight: 700;
  color: var(--accent-1);
  min-width: 60px;
  border-left: 1px solid var(--border);
}
body[data-theme="light"] .schedule-table .total-h,
body[data-theme="light"] .schedule-table .total-cell { background: #f8fafc; }

/* ============ Чат ============ */
.chat-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 70vh; }

.chat-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
body[data-theme="light"] .chat-list { background: #ffffff; }
.chat-list-header { padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.chat-conv { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text-1); }
.chat-conv:hover { background: rgba(56, 189, 248, 0.05); text-decoration: none; }
.chat-conv.active { background: rgba(56, 189, 248, 0.12); border-left: 3px solid var(--accent-1); }
.chat-conv .cname { font-weight: 600; font-size: 13px; color: var(--text-0); display: flex; justify-content: space-between; gap: 8px; }
.chat-conv .last { font-size: 12px; color: var(--text-2); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conv .meta { font-size: 10px; color: var(--text-3); margin-top: 4px; display: flex; justify-content: space-between; }
.chat-unread-badge { background: var(--danger); color: white; border-radius: 10px; padding: 1px 7px; font-size: 10px; font-weight: 700; }
.chat-empty { padding: 24px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

.chat-window { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; overflow: hidden; }
body[data-theme="light"] .chat-window { background: #ffffff; }
.chat-win-header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chat-win-header .who { font-size: 14px; }
.chat-win-header .sub { font-size: 11px; color: var(--text-3); font-weight: 400; }
.chat-msgs { padding: 16px; overflow-y: auto; max-height: 60vh; min-height: 340px; display: flex; flex-direction: column; gap: 8px; background: rgba(15, 23, 42, 0.2); }
body[data-theme="light"] .chat-msgs { background: #f8fafc; }
.msg { max-width: 75%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45; word-wrap: break-word; white-space: pre-wrap; }
.msg.in { background: rgba(56, 189, 248, 0.15); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .ts { display: block; font-size: 10px; opacity: 0.7; margin-top: 3px; }
.chat-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface); }
body[data-theme="light"] .chat-form { background: #ffffff; }
.chat-form textarea { flex: 1; resize: none; min-height: 40px; max-height: 120px; margin: 0; }
.chat-form button { margin: 0; }

.chat-fab {
  position: fixed; right: 24px; bottom: 24px;
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--accent-grad); color: #fff !important;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; line-height: 1;
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.45);
  z-index: 5000; text-decoration: none !important;
  cursor: pointer; border: none;
}
.chat-fab::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--accent-grad);
  opacity: 0.35;
  z-index: -1;
  animation: fabPulse 3s ease-in-out infinite;
}
@keyframes fabPulse {
  0%, 100% { transform: scale(1); opacity: 0.35; }
  50%      { transform: scale(1.15); opacity: 0; }
}
.chat-fab:hover { color: #fff !important; }
.chat-fab-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 11px; background: var(--danger); color: #fff;
  font-size: 12px; font-weight: 700; line-height: 22px; text-align: center;
  border: 2px solid var(--bg-0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  animation: chatFabPulse 2s infinite;
  box-sizing: border-box;
}
@keyframes chatFabPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}

/* =========================================================
   МОДАЛЬНЫЕ ОКНА
   ========================================================= */
.modal-overlay {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 8000;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
  overflow-y: auto;
  visibility: hidden;
  pointer-events: none;
  background: transparent;
  transition: visibility 0s linear var(--modal-dur);
}

.modal-overlay::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity var(--modal-dur) ease;
  pointer-events: none;
  z-index: 0;
}

.modal-overlay.open {
  visibility: visible;
  pointer-events: auto;
  transition: visibility 0s;
}
.modal-overlay.open::before { opacity: 1; }

.modal-overlay.closing {
  visibility: hidden;
  transition: visibility 0s linear calc(var(--modal-dur) * 0.7);
}
.modal-overlay.closing::before {
  opacity: 0;
  transition: opacity calc(var(--modal-dur) * 0.7) ease;
}

.modal-window {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1080px;
  height: calc(100vh - 64px);
  max-height: 900px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(-40px) scale(0.94);
  opacity: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition:
    transform var(--modal-dur) var(--modal-ease),
    opacity calc(var(--modal-dur) * 0.7) ease;
}
body[data-theme="light"] .modal-window { background: #ffffff; }

.modal-overlay.open .modal-window {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-overlay.open .modal-window.settled {
  transform: none;
  transition: none;
}

.modal-overlay.closing .modal-window {
  transform: translateY(-30px) scale(0.95);
  opacity: 0;
  transition:
    transform calc(var(--modal-dur) * 0.7) cubic-bezier(0.4, 0, 0.6, 1),
    opacity calc(var(--modal-dur) * 0.7) ease;
}

.modal-window.modal-narrow {
  max-width: 640px;
  height: min(90vh, 860px);
  max-height: calc(100vh - 64px);
}

.modal-iframe {
  width: 100%;
  flex: 1;
  min-height: 300px;
  border: 0;
  background: var(--bg-0);
  display: block;
  opacity: 1;
  transition: opacity 0.2s ease;
  image-rendering: -webkit-optimize-contrast;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
body[data-theme="light"] .modal-iframe { background: #f1f5f9; }
.modal-overlay:not(.open) .modal-iframe { opacity: 0; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 20;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-0);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  box-shadow: var(--shadow-sm);
}
body[data-theme="light"] .modal-close { background: #ffffff; }
.modal-close:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  transform: rotate(90deg) scale(1.05);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}
.modal-close:active { transform: rotate(90deg) scale(0.92); }

.modal-title {
  padding: 14px 60px 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  background: var(--surface-solid);
  color: var(--text-0);
  flex-shrink: 0;
}
body[data-theme="light"] .modal-title { background: #ffffff; }

/* =========================================================
   ПЕРЕКЛЮЧАТЕЛЬ ТЕМЫ — тумблер
   ========================================================= */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 62px;
  height: 28px;
  padding: 0 5px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  user-select: none;
  flex-shrink: 0;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}
body[data-theme="light"] .theme-toggle { background: #e2e8f0; }
.theme-toggle:hover {
  border-color: var(--accent-1);
  text-decoration: none;
  transform: none;
  box-shadow: none;
}
.theme-toggle:active { transform: scale(0.97); }

.theme-toggle .tt-icon {
  position: relative;
  z-index: 2;
  font-size: 12px;
  line-height: 1;
  width: 22px;
  text-align: center;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.theme-toggle .tt-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-grad);
  box-shadow: 0 2px 8px rgba(56, 189, 248, 0.5);
  transition: transform 0.4s cubic-bezier(0.34, 1.4, 0.64, 1);
  z-index: 1;
}

.theme-toggle .tt-sun { opacity: 0.45; }
.theme-toggle .tt-moon { opacity: 1; }
.theme-toggle .tt-knob { transform: translateX(32px); }

.theme-toggle.is-light .tt-sun { opacity: 1; }
.theme-toggle.is-light .tt-moon { opacity: 0.45; }
.theme-toggle.is-light .tt-knob { transform: translateX(0); }

.theme-toggle:hover .tt-sun,
.theme-toggle:hover .tt-moon { transform: scale(1.15); }

/* =========================================================
   ПЛАВНОСТЬ ИНТЕРФЕЙСА
   ========================================================= */
html { scroll-behavior: smooth; }

* {
  transition-property: background-color, border-color, color, box-shadow, transform, opacity;
  transition-duration: 0.2s;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeInPage {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
body { animation: fadeInPage 0.35s cubic-bezier(0.34, 1.2, 0.64, 1) both; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card, table, .stat, .today-card, .tabs {
  animation: fadeInUp 0.4s cubic-bezier(0.34, 1.2, 0.64, 1) both;
}
.card:nth-child(1) { animation-delay: 0.02s; }
.card:nth-child(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.10s; }
.today-card       { animation-delay: 0.04s; }
table             { animation-delay: 0.08s; }
.tabs             { animation-delay: 0.06s; }

button, .btn {
  transition:
    transform 0.15s cubic-bezier(0.34, 1.4, 0.64, 1),
    box-shadow 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}
button:hover, .btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(56, 189, 248, 0.35); }
button:active, .btn:active {
  transform: translateY(0) scale(0.97);
  transition-duration: 0.08s;
}

input, select, textarea {
  transition: border-color 0.15s ease, box-shadow 0.2s ease, background-color 0.2s ease, transform 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--border-hover); }
input:focus, select:focus, textarea:focus { transform: translateY(-1px); }

.card { transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease; }
.card:hover { border-color: var(--border-hover); box-shadow: var(--shadow-md); }

.stat { transition: transform 0.25s cubic-bezier(0.34, 1.3, 0.64, 1), box-shadow 0.25s ease, border-color 0.25s ease; }
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--border-hover); }

tr { transition: background-color 0.15s ease; }

.user-menu.open .user-dropdown { animation: dropdownIn 0.22s cubic-bezier(0.34, 1.3, 0.64, 1) both; }
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.user-btn .chev { transition: transform 0.25s cubic-bezier(0.34, 1.3, 0.64, 1); }

.flash { animation: flashIn 0.4s cubic-bezier(0.34, 1.3, 0.64, 1) both; }
@keyframes flashIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.icon-btn { transition: transform 0.2s cubic-bezier(0.34, 1.4, 0.64, 1), background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease; }
.icon-btn:hover { transform: scale(1.1); }
.icon-btn:active { transform: scale(0.95); }

.tab { transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease; }
.tab:hover { transform: translateY(-1px); }
.tab.active::after { animation: tabUnderline 0.3s cubic-bezier(0.34, 1.3, 0.64, 1) both; }
@keyframes tabUnderline {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.schedule-table .st-free { transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease; }
.schedule-table .st-free:active { transform: scale(0.9); }

.chat-fab { transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1), box-shadow 0.25s ease; }
.chat-fab:hover { transform: scale(1.08); box-shadow: 0 12px 32px rgba(56, 189, 248, 0.6); color: #fff !important; }
.chat-fab:active { transform: scale(0.94); }
.chat-fab { animation: fabIn 0.5s var(--modal-ease) both; }
@keyframes fabIn {
  from { opacity: 0; transform: scale(0.3) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-overlay::before { transition: opacity 0.32s ease; }

.msg { animation: msgIn 0.25s var(--modal-ease); }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

body, .topbar, .card, table, .modal-window, .user-dropdown {
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease;
}

.salon-card { transition: transform 0.25s cubic-bezier(0.34, 1.4, 0.64, 1), box-shadow 0.25s ease, border-color 0.25s ease; }
.salon-card:hover { transform: translateY(-3px) scale(1.02); box-shadow: var(--shadow-md); }

.modal-close { transition: transform 0.25s cubic-bezier(0.34, 1.3, 0.64, 1), background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease; }


/* =========================================================
   МОБИЛЬНАЯ АДАПТАЦИЯ
   ========================================================= */

/* Планшеты и меньше */
@media (max-width: 900px) {
  .topbar {
    padding: 8px 10px;
    gap: 0;
  }
  .topbar > a:not(.btn):not(.logout-btn):not(.theme-toggle) {
    padding: 6px 9px;
    font-size: 12px;
  }
  .topbar .right {
    width: 100%;
    margin-left: 0;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
  }
  .user-btn .user-name { max-width: 140px; }

  .stat {
    min-width: 0;
    flex: 1 1 calc(50% - 12px);
    padding: 12px 16px;
  }
  .stat b { font-size: 22px; }

  .schedule-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .schedule-table .sticky-col {
    min-width: 110px;
    padding-left: 8px;
    font-size: 12px;
  }

  .modal-window {
    max-width: 100% !important;
    height: calc(100vh - 24px);
    border-radius: 12px;
  }
  .modal-window.modal-narrow { max-width: 100% !important; }

  .chat-layout { grid-template-columns: 1fr; }
}

/* Телефоны */
@media (max-width: 700px) {
  body {
    padding: 10px;
    font-size: 13px;
  }
  body.embed { padding: 8px; }

  h1 { font-size: 20px; margin-bottom: 12px; }
  h2 { font-size: 16px; margin-bottom: 10px; }
  h3 { font-size: 14px; }

  .topbar {
    border-radius: 12px;
    padding: 8px 8px;
  }
  .topbar > a:not(.btn):not(.logout-btn):not(.theme-toggle) {
    padding: 6px 8px;
    font-size: 11px;
  }
  .icon-switch { padding: 1px; }
  .icon-btn { width: 24px; height: 24px; font-size: 12px; }
  .theme-toggle { width: 50px; height: 24px; }
  .theme-toggle .tt-knob { width: 20px; height: 20px; transform: translateX(26px); }
  .theme-toggle.is-light .tt-knob { transform: translateX(0); }
  .theme-toggle .tt-icon { width: 18px; font-size: 10px; }

  .user-btn {
    padding: 6px 9px;
    font-size: 12px;
  }
  .user-btn .user-name { max-width: 110px; }
  .user-dropdown { min-width: 180px; }
  .dd-link { padding: 8px 10px; font-size: 12px; }

  button, .btn {
    padding: 9px 14px;
    font-size: 13px;
    min-height: 38px;
  }

  input, select, textarea {
    font-size: 16px;
    padding: 10px 12px;
    width: 100%;
  }

  .row {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }
  .row > div,
  .row > label {
    width: 100%;
  }
  .row input,
  .row select,
  .row textarea {
    width: 100% !important;
    max-width: 100%;
  }

  .stat {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
    padding: 10px 14px;
    margin-right: 0;
  }
  .stat b { font-size: 20px; }

  .card { padding: 14px; border-radius: 12px; }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 10px 14px;
    font-size: 12px;
    flex-shrink: 0;
  }

  /* ===== Таблицы → карточки ===== */
  table.responsive-table,
  table.responsive-table thead,
  table.responsive-table tbody,
  table.responsive-table tr,
  table.responsive-table th,
  table.responsive-table td {
    display: block;
    width: 100%;
  }
  table.responsive-table thead { display: none; }
  table.responsive-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px 12px;
    box-shadow: var(--shadow-sm);
  }
  table.responsive-table td {
    padding: 4px 0;
    border: none;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    min-height: 26px;
  }
  table.responsive-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-3);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
    flex-shrink: 0;
  }
  table.responsive-table td[data-label=""]::before,
  table.responsive-table td:not([data-label])::before { content: none; }

  table.responsive-table td:last-child {
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
  }

  .today-card { padding: 12px 14px; }
  .today-header { flex-direction: column; align-items: stretch; }
  .today-header > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-end;
  }
  .today-sub { font-size: 12px; }

  .today-legend {
    flex-wrap: wrap;
    gap: 8px 14px;
    font-size: 11px;
  }

  .chat-layout { grid-template-columns: 1fr; }
  .chat-list { max-height: 220px; }
  .chat-window { min-height: 400px; }
  .chat-msgs { max-height: 50vh; min-height: 240px; padding: 12px; }
  .msg { max-width: 88%; font-size: 13px; }

  .chat-fab {
    right: 14px;
    bottom: 14px;
    width: 54px;
    height: 54px;
    font-size: 22px;
  }

  .modal-overlay { padding: 6px; }
  .modal-window {
    height: calc(100vh - 12px);
    max-height: none;
    border-radius: 10px;
  }
  .modal-title { padding: 12px 50px 12px 16px; font-size: 13px; }
  .modal-close { top: 8px; right: 10px; width: 32px; height: 32px; }

  .reg-open-banner, .reg-closed-banner {
    padding: 12px 14px;
    font-size: 13px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .schedule-table th,
  .schedule-table td { padding: 4px 2px; font-size: 10px; min-width: 36px; }
  .schedule-table .sticky-col { min-width: 90px; font-size: 11px; }
  .schedule-scroll::-webkit-scrollbar { height: 4px; }
  .schedule-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
}

/* Очень узкие телефоны */
@media (max-width: 380px) {
  body { padding: 8px; }
  h1 { font-size: 18px; }
  .topbar > a { padding: 5px 7px; font-size: 10px; }
  .user-btn .user-name { max-width: 80px; font-size: 11px; }
  .stat { flex: 1 1 100%; }
  .tabs .tab { padding: 8px 12px; font-size: 11px; }
}

/* Уважение к reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}