/* ═══════════════════════════════════════════════════════
   МАГАМОЖЕТ — CRM  |  Deep Dark Studio Theme
   ═══════════════════════════════════════════════════════ */

/* ─── Reset & Variables ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette — Deep Dark Studio */
  --bg:           #0a0b0d;    /* Глубокий угольный фон */
  --bg-card:      #14161a;    /* Рабочие поверхности */
  --bg-hover:     #1e2126;    /* Интерактив */
  --bg-input:     #181a1f;    /* Поля ввода */
  --border:       #2a2d33;    /* Строгие границы */
  --border-focus: #4f6ef7;

  --text:         #e1e3e6;    /* Чистый светлый текст */
  --text-secondary: #91969e;  /* Серый текст */
  --text-muted:   #63676e;    /* Приглушенный */

  --primary:      #4f6ef7;
  --primary-hover:#637fff;
  --primary-light: rgba(79, 110, 247, 0.2);

  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;

  --radius:       8px;
  --radius-sm:    5px;
  --radius-lg:    12px;

  --shadow-sm:    0 1px 2px rgba(0,0,0,.5);
  --shadow:       0 4px 6px rgba(0,0,0,.4);
  --shadow-md:    0 8px 24px rgba(0,0,0,.6);
  --shadow-lg:    0 16px 48px rgba(0,0,0,.8);

  --header-h:     60px;
  --nav-h:        48px;
  --font:         'Inter', sans-serif;

  --transition:   .2s ease;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ═══════════════════════════════════════════════════════
   AUTH SCREEN
   ═══════════════════════════════════════════════════════ */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #e8eaef 0%, #f4f5f7 50%, #e0e3ea 100%);
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px 36px;
  animation: authFadeIn .5s ease-out;
}

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

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), #7c8ef7);
  color: #fff;
  margin-bottom: 16px;
  box-shadow: 0 6px 20px rgba(79,110,247,.3);
}

.auth-logo h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: .92rem;
  margin-top: 4px;
}

/* Auth Tabs */
.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 5px;
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.auth-tab.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.auth-tab:hover:not(.active) { color: var(--text); }

/* Auth Form */
.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-group label {
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-family: var(--font);
  font-size: .92rem;
  color: var(--text);
  transition: var(--transition);
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  background: var(--bg-hover);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.auth-error {
  padding: 10px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  text-align: center;
  margin-top: 8px;
  animation: shake .4s ease;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ═══════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(79,110,247,.25);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 3px 8px rgba(79,110,247,.3);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: #fef2f2; }

.btn-sm { padding: 5px 10px; font-size: .82rem; }

.btn-full { width: 100%; justify-content: center; padding: 11px; font-size: .95rem; }

/* ═══════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #7c8ef7);
  color: #fff;
}

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .88rem;
  color: var(--text-secondary);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--primary-light);
  color: var(--primary);
}

/* ═══════════════════════════════════════════════════════
   NAVIGATION
   ═══════════════════════════════════════════════════════ */
.nav-bar {
  display: flex;
  gap: 2px;
  padding: 8px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.nav-btn:hover { background: var(--bg-hover); color: var(--text); }
.nav-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

/* ═══════════════════════════════════════════════════════
   STATS BAR
   ═══════════════════════════════════════════════════════ */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 20px 24px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

.stat-label {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════ */
.main-content {
  max-width: 1440px;
  margin: 0 auto;
}

.tab-content { padding: 0 24px 24px; }

/* ─── Toolbar ────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-filters {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toolbar-filters select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-family: var(--font);
  font-size: .85rem;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

.toolbar-filters select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ─── Table ──────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: #1c2027;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  transition: var(--transition);
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Status badges in table */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
}
.status-new        { border: 1px solid #2563eb; color: #60a5fa; background: rgba(37, 99, 235, 0.1); }
.status-rejected   { border: 1px solid #dc2626; color: #f87171; background: rgba(220, 38, 38, 0.1); }
.status-inprogress { border: 1px solid #d97706; color: #fbbf24; background: rgba(217, 119, 6, 0.1); }
.status-completed  { border: 1px solid #16a34a; color: #4ade80; background: rgba(22, 163, 74, 0.1); }
.status-incomplete { border: 1px solid #db2777; color: #f472b6; background: rgba(219, 39, 119, 0.1); }

/* Actions in tables */
.row-actions {
  display: flex;
  gap: 4px;
}

.row-actions button {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}
.row-actions button:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.row-actions button.del:hover {
  background: #fef2f2;
  color: var(--danger);
}

/* Active status in masters table */
.active-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.active-dot.on  { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,.4); }
.active-dot.off { background: var(--text-muted); }

/* ═══════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modalBgIn .25s ease;
}

@keyframes modalBgIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 32px 24px;
  animation: modalSlideIn .3s ease-out;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 500;
  color: #fff;
  background: var(--text);
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease-out;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

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

/* ═══════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: .95rem; }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .stats-bar { grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px; }
  .toolbar { padding: 0; }
  .tab-content { padding: 0 16px 16px; }
  .header { padding: 0 16px; }
  .nav-bar { padding: 6px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 20px 20px 16px; }
  .header-title { font-size: 1rem; }
  .auth-card { padding: 28px 24px 24px; }
}

@media (max-width: 480px) {
  .stats-bar { grid-template-columns: 1fr; }
  .header-user span:first-child { display: none; }
}

/* Connection status ticks */
.connection-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}
.status-ticks {
  font-weight: bold;
  font-size: 15px;
  cursor: help;
  user-select: none;
  letter-spacing: -3px; /* Сближаем галочки, чтобы получилась "сдвоенная" */
  margin-left: 5px;
}
.status-ticks.delivered { color: #60a5fa; } /* Blue */
.status-ticks.read { color: #4ade80; }      /* Green */

