:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #1e3a8a;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --accent: #d97706;
  --accent-soft: #fffbeb;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Layout */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.auth-wrap {
  max-width: 440px;
  margin: 28px auto;
  padding: 0 16px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.section-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Tabs & Pills */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-alt);
  padding: 4px;
  border-radius: 10px;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Forms */
.form-grid {
  display: grid;
  gap: 12px;
}

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

@media (min-width: 600px) {
  .form-row-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.textarea {
  min-height: 84px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.12);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
}

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

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

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-block {
  width: 100%;
}

/* Score Scale Picker (1-5) */
.scale-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.scale-btn {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}

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

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-excellent {
  background: var(--success-soft);
  color: var(--success);
}

.badge-good {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-fair {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-low {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-neutral {
  background: var(--surface-alt);
  color: var(--text-muted);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

@media (min-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

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

.stat-value {
  font-size: 22px;
  font-weight: 800;
  margin-top: 2px;
}

.stat-card.alert {
  border-color: #fecaca;
  background: #fef2f2;
}

.stat-card.alert .stat-value {
  color: var(--danger);
}

/* Lists */
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (min-width: 640px) {
  .list-item-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 36px 20px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
}

.empty-desc {
  margin: 0 auto 16px;
  max-width: 380px;
  font-size: 14px;
  color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }
}

.modal {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px;
  box-shadow: 0 20px 25px -5px rgba(15, 23, 42, 0.2);
}

@media (min-width: 600px) {
  .modal {
    border-radius: var(--radius);
  }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
  max-width: calc(100vw - 32px);
}

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

/* Raport A4 */
.raport-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.raport-toolbar-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.raport-sheet {
  max-width: 820px;
  margin: 16px auto 36px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.raport-kop {
  border-bottom: 3px double #0f172a;
  padding-bottom: 12px;
  margin-bottom: 16px;
  text-align: center;
}

.raport-kop h1 {
  margin: 0;
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.raport-kop p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 14px;
}

.info-table td {
  padding: 5px 6px;
  vertical-align: top;
}

.info-table td.label {
  width: 160px;
  color: var(--text-muted);
  font-weight: 600;
}

.raport-block {
  margin-top: 18px;
  page-break-inside: avoid;
}

.raport-block h2 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

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

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 7px 9px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  background: var(--surface-alt);
  font-weight: 700;
}

.ttd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 28px;
  text-align: center;
  font-size: 13px;
  page-break-inside: avoid;
}

.ttd-space {
  height: 64px;
}

.draft-banner {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 600;
}

@page {
  size: A4 portrait;
  margin: 14mm;
}

@media print {
  body {
    background: #fff;
    font-size: 12px;
  }

  .no-print {
    display: none !important;
  }

  .raport-sheet {
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }

  .badge {
    border: 1px solid #cbd5e1;
  }
}
