:root {
  --bg-main: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-hover: #19233c;
  --bg-input: #1a233a;
  --border-subtle: #212c45;
  --border-focus: #3b82f6;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-faint: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.28);
  
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --warning-border: rgba(245, 158, 11, 0.28);

  --urgent: #f97316;
  --urgent-bg: rgba(249, 115, 22, 0.14);
  --urgent-border: rgba(249, 115, 22, 0.35);

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --danger-border: rgba(239, 68, 68, 0.28);

  --whatsapp: #10b981;
  --whatsapp-hover: #059669;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --transition: all 0.18s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   Экран авторизации
   ========================================================================== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 30%, #17233f 0%, #0b0f19 80%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-logo {
  margin-bottom: 26px;
}

.logo-icon {
  width: 56px;
  height: 56px;
  background: rgba(37, 99, 235, 0.15);
  color: #60a5fa;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.auth-logo h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.auth-logo p {
  font-size: 13px;
  color: var(--text-muted);
}

.auth-error {
  background: var(--danger-bg);
  color: #fca5a5;
  border: 1px solid var(--danger-border);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ==========================================================================
   Шапка приложения
   ========================================================================== */
.app-container {
  max-width: 1340px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

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

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #60a5fa;
}

.brand-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.header-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
}

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

/* ==========================================================================
   Кнопки
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: #334155;
}

.btn-whatsapp {
  background: #059669;
  color: #ffffff;
}

.btn-whatsapp:hover {
  background: #047857;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12.5px;
}

.btn-icon {
  padding: 7px 9px;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.btn-block {
  width: 100%;
}

/* ==========================================================================
   Сводная статистика (Stats Grid)
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: #334155;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.15;
  margin-bottom: 4px;
}

.stat-sub {
  font-size: 11px;
  color: var(--text-faint);
}

.text-success { color: #34d399 !important; }
.text-warning { color: #fbbf24 !important; }
.text-urgent  { color: #fb923c !important; }
.text-danger  { color: #f87171 !important; }
.text-accent  { color: #60a5fa !important; }

/* ==========================================================================
   Панель поиска и фильтров (Toolbar)
   ========================================================================== */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: var(--text-faint);
}

.search-box input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 10px 36px 10px 38px;
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}

.search-box input:focus {
  border-color: var(--border-focus);
}

.clear-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.filter-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.tabs-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: #ffffff;
  background: rgba(37, 99, 235, 0.2);
  border-color: rgba(59, 130, 246, 0.4);
}

.tab-btn span {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 6px;
  border-radius: 10px;
}

.sort-select-wrapper select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 12.5px;
  outline: none;
  cursor: pointer;
}

/* ==========================================================================
   Таблица клиентов (Desktop)
   ========================================================================== */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.clients-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.clients-table th {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-faint);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.clients-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

.clients-table tr:hover td {
  background: var(--bg-card-hover);
}

.client-name-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.c-name {
  font-weight: 600;
  color: var(--text-main);
  font-size: 14px;
}

.c-phone {
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: none;
}

.c-phone:hover {
  color: #60a5fa;
  text-decoration: underline;
}

.c-service-badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 500;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.25);
  padding: 3px 8px;
  border-radius: 6px;
}

.c-dates-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.c-end-date {
  font-weight: 600;
  color: var(--text-main);
}

.c-start-date {
  font-size: 11px;
  color: var(--text-faint);
}

/* Бейджи статусов */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.status-badge.active {
  background: var(--success-bg);
  color: #34d399;
  border: 1px solid var(--success-border);
}

.status-badge.warning {
  background: var(--warning-bg);
  color: #fbbf24;
  border: 1px solid var(--warning-border);
}

.status-badge.urgent {
  background: var(--urgent-bg);
  color: #fb923c;
  border: 1px solid var(--urgent-border);
}

.status-badge.expired {
  background: var(--danger-bg);
  color: #f87171;
  border: 1px solid var(--danger-border);
}

.renewals-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.renewals-badge:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

/* Действия в строке */
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.btn-action-renew {
  background: rgba(37, 99, 235, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(37, 99, 235, 0.3);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-action-renew:hover {
  background: var(--primary);
  color: #ffffff;
}

.btn-action-wa {
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.28);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  transition: var(--transition);
}

.btn-action-wa:hover {
  background: #10b981;
  color: #ffffff;
}

.btn-action-menu {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 16px;
}

.btn-action-menu:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

/* ==========================================================================
   Мобильный вид (Карточки)
   ========================================================================== */
.cards-container {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.client-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.client-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.card-title-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-service-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.card-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.card-info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-info-label {
  font-size: 11px;
  color: var(--text-faint);
}

.card-info-val {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

.card-notes {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
}

.card-actions .btn {
  flex: 1;
}

/* ==========================================================================
   Модальные окна
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 999;
}

.modal-window {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-sm {
  max-width: 420px;
}

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

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input[type="text"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 9px 12px;
  font-size: 13.5px;
  outline: none;
  transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
}

textarea {
  resize: vertical;
}

/* Модалка продления */
.renew-client-info {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}

.renew-client-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}

.renew-dates-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.renew-date-row {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}

.pills-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.pill-btn {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.pill-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.pill-btn.active {
  background: rgba(37, 99, 235, 0.25);
  border-color: #3b82f6;
  color: #93c5fd;
}

/* История продлений */
.history-summary {
  display: flex;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.history-stat {
  flex: 1;
}

.h-label {
  font-size: 11px;
  color: var(--text-muted);
}

.h-value {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.history-item {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}

.history-item-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Тост уведомление */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #334155;
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  animation: slideUp 0.2s ease;
}

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

.loading-state,
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.empty-state svg {
  margin-bottom: 12px;
  color: var(--text-faint);
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text-main);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
  margin-bottom: 16px;
}

/* ==========================================================================
   Адаптивность (iPhone и мобильные)
   ========================================================================== */
@media (max-width: 820px) {
  .app-container {
    padding: 12px 14px 40px;
    gap: 14px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .table-wrapper {
    display: none;
  }

  .cards-container {
    display: flex;
  }

  .filter-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .tabs-bar {
    width: 100%;
  }

  .sort-select-wrapper select {
    width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
