:root {
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #cbd5e1;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  padding: 14px;
  min-height: 100vh;
}

/* ЭКРАН ВХОДА (ПОЛНОСТЬЮ БЕЛЫЙ, ЦЕНТРИРОВАННЫЙ) */
body.auth-mode {
  background: #ffffff !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  height: 100vh !important;
  overflow: hidden !important;
}

#login-modal-wrapper {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
}

.auth-card {
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.1), 0 4px 12px rgba(15, 23, 42, 0.05);
  border: 1px solid #e2e8f0;
  max-width: 420px;
  width: 90%;
  padding: 36px 32px;
  text-align: center;
}

.auth-logo {
  width: 58px;
  height: 58px;
  background: #eff6ff;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.auth-copyright {
  margin-top: 26px;
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.container {
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  margin-bottom: 14px;
}

.header {
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.header-title h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  background: white;
  border-radius: 10px 10px 0 0;
}

.tab {
  padding: 12px 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
}

.tab:hover { color: var(--text-main); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.controls {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  background: white;
  border-bottom: 1px solid var(--border);
}

.search-input, select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
}

.btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: #f1f5f9; color: #1e293b; border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
}

th {
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  user-select: none;
}

th.sortable { cursor: pointer; }
th.sortable:hover { background: #e2e8f0; }

td {
  padding: 9px 12px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
}

tbody tr.clickable-row {
  cursor: pointer;
  transition: background 0.12s;
}
tbody tr.clickable-row:hover { background: #f8fafc; }

.type-badge-incoming {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.type-badge-outgoing {
  color: #15803d;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.status-draft { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-processed { background: #d1fae5; color: #065f46; }
.status-sent { background: #dbeafe; color: #1e40af; }
.status-delivered { background: #e9d5ff; color: #6b21a8; }
.status-archived { background: #fee2e2; color: #991b1b; }

.deadline-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.deadline-red { background: #fee2e2; color: #dc2626; }
.deadline-yellow { background: #fffbeb; color: #d97706; }
.deadline-green { background: #dcfce7; color: #16a34a; }

.tag-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  margin: 1px 2px;
  color: white;
  background: #64748b;
}

/* МОДАЛЬНЫЕ ОКНА */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.show { display: flex !important; }

.modal-content {
  background: white;
  border-radius: 12px;
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.modal-header {
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

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

.form-group { margin-bottom: 11px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 3px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* СТРОГИЙ АККОРДЕОН */
.accordion-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}
.accordion-header {
  padding: 11px 15px;
  background: #f8fafc;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
}
.accordion-header:hover { background: #f1f5f9; }
.accordion-content {
  padding: 14px;
  display: none;
  background: white;
  border-top: 1px solid var(--border);
}
.accordion-item.open .accordion-content { display: block !important; }
.accordion-item.open .acc-arrow { transform: rotate(180deg); }
.acc-arrow { transition: transform 0.15s; font-size: 11px; color: var(--text-muted); }

.notification-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.notification {
  background: white;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 10px 14px;
  border-left: 4px solid var(--primary);
  font-size: 13px;
}
.notification.error { border-left-color: var(--danger); }
.notification.success { border-left-color: var(--success); }
.notification.warning { border-left-color: var(--warning); }

/* ПЕЧАТЬ */
@page {
  size: landscape;
  margin: 8mm;
}

@media print {
  body {
    background: #ffffff !important;
    padding: 0 !important;
    color: #000000 !important;
  }
  .no-print, .modal, .notification-container, .header, .tabs, .controls, #app-container > .card:not(#tab-registry-content) {
    display: none !important;
  }
  .print-only {
    display: block !important;
  }
  body.print-active-card > *:not(#print-area) {
    display: none !important;
  }
  body.print-active-card #print-area {
    display: block !important;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
  }

  table {
    width: 100% !important;
    border-collapse: collapse !important;
  }
  th, td {
    border: 1px solid #333333 !important;
    padding: 6px 8px !important;
    font-size: 9pt !important;
    color: #000000 !important;
  }
  thead tr {
    background: #0f172a !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact;
  }
  thead th {
    color: #ffffff !important;
  }
}
.print-only { display: none; }

/* Гарантированное отображение модального окна сотрудника */
#employee-single-modal.show {
  display: flex !important;
  z-index: 9999 !important;
}

/* ВЫРАВНИВАНИЕ ШАПКИ И НУМЕРАЦИЯ ДЛЯ ПЕЧАТИ */
@page {
  size: landscape;
  margin: 10mm 10mm 15mm 10mm;
  @bottom-right {
    content: counter(page) " / " counter(pages);
    font-family: 'Inter', sans-serif;
    font-size: 9pt;
    color: #64748b;
  }
}

@media print {
  th {
    text-align: center !important;
    vertical-align: middle !important;
  }
  .print-page-footer {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    margin-top: 14px;
    font-size: 9pt;
    color: #475569;
    border-top: 1px solid #cbd5e1;
    padding-top: 6px;
  }
}

/* Компактная таблица предварительного просмотра без распирания */
#report-preview-container table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

#report-preview-container th {
  text-align: center !important;
  font-size: 11px;
  padding: 6px 4px;
  white-space: nowrap;
}

#report-preview-container td {
  font-size: 11px;
  padding: 6px 4px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ЗАПРЕТ ПЕРЕНОСА И КОРРЕКТНАЯ ШИРИНА КОЛОНОК ТИП И СТАТУС */
.type-badge-incoming, .type-badge-outgoing {
  white-space: nowrap !important;
  font-size: 11px !important;
  padding: 3px 8px !important;
}

.status-badge {
  white-space: nowrap !important;
  font-size: 11px !important;
  padding: 3px 10px !important;
}

#main-mail-table th:nth-child(4),
#main-mail-table td:nth-child(4) {
  min-width: 95px !important; /* Колонка "Тип" */
  white-space: nowrap !important;
}

#main-mail-table th:nth-child(10),
#main-mail-table td:nth-child(10) {
  min-width: 115px !important; /* Колонка "Статус" */
  white-space: nowrap !important;
}

#main-mail-table th:nth-child(11),
#main-mail-table td:nth-child(11) {
  min-width: 55px !important; /* Колонка "Файли" */
  text-align: center !important;
}

/* БЕЙДЖ ДЛЯ КОЛИЧЕСТВА ВКЛАДЕНИЙ (ЦИФРА В КРУЖОЧКЕ) */
.attach-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 2px rgba(29, 78, 216, 0.08);
}
