/* ═══════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ═══════════════════════════════════════════════════════════
   CSS VARIABLES
═══════════════════════════════════════════════════════════ */
:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #eff6ff;
  --primary-border: #bfdbfe;

  --bg:      #f1f5f9;
  --surface: #ffffff;
  --border:  #e2e8f0;
  --border-light: #f1f5f9;

  --text:       #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.15), 0 4px 6px rgba(0,0,0,.06);
}

/* ═══════════════════════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════════════════════ */
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ═══════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

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

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

.btn-danger {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}
.btn-danger:hover { background: #fee2e2; }

.btn-sm   { padding: 5px 12px; font-size: 13px; }
.btn-full { width: 100%; }

/* ═══════════════════════════════════════════════════════════
   FORMS
═══════════════════════════════════════════════════════════ */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-group textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

.form-error {
  font-size: 13px;
  color: #dc2626;
  margin-bottom: 12px;
  min-height: 18px;
}

/* ═══════════════════════════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════════════════════════ */
.login-body {
  min-height: 100vh;
  background: linear-gradient(145deg, #0f172a 0%, #1e3a8a 55%, #1d4ed8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 40px 36px 36px;
  width: 100%;
  max-width: 400px;
}

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

.logo-icon {
  width: 52px;
  height: 52px;
  background: var(--primary);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(37,99,235,.35);
}

.login-logo h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

/* Tab toggle */
.tab-toggle {
  display: flex;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
}

.toggle-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all .2s;
}
.toggle-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Token input */
.token-input {
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace !important;
  font-size: 22px !important;
  letter-spacing: .25em !important;
  text-align: center !important;
  text-transform: uppercase !important;
  padding: 12px !important;
}

/* ═══════════════════════════════════════════════════════════
   DASHBOARD LAYOUT
═══════════════════════════════════════════════════════════ */
.dashboard-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 58px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  color: var(--primary);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.header-username {
  color: var(--text);
  font-weight: 500;
}

.user-role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

/* Tabs */
.tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 20px;
}

.tab-btn {
  padding: 13px 18px;
  border: none;
  border-bottom: 2.5px solid transparent;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Main content */
.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.filter-area {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

.filter-area select {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  outline: none;
  font-family: inherit;
}
.filter-area select:focus { border-color: var(--primary); }

/* Panels */
.panel         { display: none; }
.panel.active  { display: block; }

/* ═══════════════════════════════════════════════════════════
   TABLE
═══════════════════════════════════════════════════════════ */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  line-height: 1.4;
}

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

.id-cell   { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.name-cell { font-weight: 500; }
.desc-cell {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-muted);
}
.date-cell { color: var(--text-muted); font-size: 13px; white-space: nowrap; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn + .btn { margin-left: 4px; }

/* Client/actions columns hidden for client role */
.client-mode .col-client,
.client-mode .col-actions { display: none; }

/* ═══════════════════════════════════════════════════════════
   STATUS BADGES
═══════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}

/* Orders */
.badge-new          { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.badge-in_progress  { background: #ffedd5; color: #c2410c; border-color: #fed7aa; }
.badge-completed    { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.badge-cancelled    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* Requests */
.badge-reviewing    { background: #f3e8ff; color: #6b21a8; border-color: #e9d5ff; }
.badge-approved     { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.badge-rejected     { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ═══════════════════════════════════════════════════════════
   TOKEN DISPLAY (clients table)
═══════════════════════════════════════════════════════════ */
.token-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.token-code {
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .15em;
  color: var(--text);
  background: var(--bg);
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.btn-copy {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  color: var(--text-muted);
  transition: all .2s;
  font-family: inherit;
}
.btn-copy:hover { background: var(--bg); color: var(--text); }
.btn-copy.copied { background: #dcfce7; color: #15803d; border-color: #86efac; }

/* ═══════════════════════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 64px 20px;
  color: var(--text-muted);
  font-size: 15px;
}
.empty-state p { margin: 0; }

/* ═══════════════════════════════════════════════════════════
   MODAL
═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  overflow: hidden;
  animation: modal-in .18s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.95) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--bg);
  border-radius: 7px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body  { padding: 20px 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border);
}

/* Token reveal after client creation */
.token-reveal {
  background: var(--primary-light);
  border: 1.5px solid var(--primary-border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  margin-top: 14px;
}
.token-reveal .tr-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.token-reveal .tr-value {
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: .25em;
  color: var(--primary);
}
.token-reveal .tr-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ═══════════════════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  text-align: center;
  transition: opacity .3s, transform .3s;
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: var(--primary); }
.toast.fade-out { opacity: 0; transform: translateY(8px); }

/* ═══════════════════════════════════════════════════════════
   CLIENT VIEW
═══════════════════════════════════════════════════════════ */

/* Шапка клиента */
.cl-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
}

.cl-username {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.cl-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.cl-logout-btn:hover { background: #fee2e2; color: #b91c1c; }

/* Контент */
.cl-content {
  padding: 16px 16px 100px;
  min-height: calc(100vh - 56px);
  background: var(--bg);
}

/* Заголовок секции */
.cl-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 8px 0 8px 4px;
}
.cl-section-title:not(:first-child) { margin-top: 24px; }

/* Карточка */
.cl-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.cl-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--primary-light);
  color: var(--primary);
}

.cl-card-body { flex: 1; min-width: 0; }

.cl-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cl-card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Пустое состояние */
.cl-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
}

/* Экран написания сообщения */
.cl-compose {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: calc(100vh - 56px - 66px - 32px);
}

.cl-compose-textarea {
  flex: 1;
  width: 100%;
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  resize: none;
  outline: none;
  line-height: 1.6;
  box-shadow: var(--shadow);
}
.cl-compose-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.cl-compose-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* Нижняя навигация */
.cl-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
  box-shadow: 0 -2px 12px rgba(0,0,0,.07);
}

.cl-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 0;
  border: none;
  background: none;
  color: var(--text-light);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s;
  font-family: inherit;
}
.cl-nav-btn span { line-height: 1; }
.cl-nav-btn.active { color: var(--primary); }
.cl-nav-btn:hover  { color: var(--text-muted); }
.cl-nav-btn.active:hover { color: var(--primary); }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE
═══════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Header */
  .header {
    padding: 0 12px;
    gap: 8px;
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .header-brand {
    font-size: 14px;
    flex: 1 1 auto;
  }

  .header-user {
    gap: 6px;
    font-size: 13px;
  }

  .header-username {
    display: none;
  }

  /* Tabs */
  .tabs-bar {
    padding: 0 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs-bar::-webkit-scrollbar { display: none; }

  .tab-btn {
    padding: 11px 12px;
    font-size: 13px;
    flex-shrink: 0;
  }

  /* Main content */
  .main-content {
    padding: 12px;
  }

  /* Toolbar */
  .toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .filter-area {
    width: 100%;
    flex-wrap: wrap;
  }

  .filter-area select {
    flex: 1;
    min-width: 0;
  }

  /* Table минимальная ширина чтобы не ломалась */
  .data-table {
    min-width: 480px;
  }

  .data-table th,
  .data-table td {
    padding: 9px 10px;
    font-size: 13px;
  }

  .desc-cell {
    max-width: 120px;
  }

  /* Modal */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation: modal-in-mobile .2s ease-out;
  }

  @keyframes modal-in-mobile {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* Toast */
  .toast {
    bottom: 12px;
    right: 12px;
    left: 12px;
    min-width: 0;
  }

  /* Login */
  .login-card {
    padding: 28px 20px 24px;
  }
}
