/* ── Reset & Variables ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f0f2f5;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1a202c;
  --text-muted:#718096;
  --primary:   #2563eb;
  --primary-dk:#1d4ed8;
  --danger:    #dc2626;
  --radius:    6px;
  --shadow:    0 1px 3px rgba(0,0,0,.1);
  --header-h:  56px;
}

html, body { height: 100%; font-family: system-ui, -apple-system, sans-serif; font-size: 14px; }
body { background: var(--bg); color: var(--text); }

/* ── Header ────────────────────────────────────────────────────────────── */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: #1e293b;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.header-inner {
  display: flex; align-items: center; gap: 16px;
  height: 100%; padding: 0 16px;
}
.brand {
  font-size: 16px; font-weight: 700; color: #fff;
  white-space: nowrap; margin-right: 8px;
}
.nav { display: flex; gap: 2px; flex: 1; }
.nav-btn {
  background: none; border: none; cursor: pointer;
  color: #94a3b8; font-size: 13px; font-weight: 500;
  padding: 6px 12px; border-radius: var(--radius);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-btn.active { background: rgba(255,255,255,.12); color: #fff; }
.header-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.user-name { color: #94a3b8; font-size: 13px; white-space: nowrap; }
.logout-btn {
  color: #94a3b8; font-size: 12px; text-decoration: none;
  padding: 4px 8px; border-radius: 4px; border: 1px solid #334155;
  transition: color .15s, border-color .15s;
}
.logout-btn:hover { color: #fff; border-color: #64748b; }

/* ── Main ──────────────────────────────────────────────────────────────── */
.main { margin-top: var(--header-h); padding: 24px 16px; min-height: calc(100vh - var(--header-h)); }

/* ── View ──────────────────────────────────────────────────────────────── */
.view { max-width: 1280px; margin: 0 auto; }
.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px;
}
.view-header h1 { font-size: 20px; font-weight: 700; }

/* ── Filters ───────────────────────────────────────────────────────────── */
.filters {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.search-input, .filter-select {
  height: 36px; padding: 0 10px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
  font-size: 13px; color: var(--text); outline: none;
}
.search-input { min-width: 200px; flex: 1 1 200px; }
.filter-select { min-width: 140px; }
.search-input:focus, .filter-select:focus { border-color: var(--primary); }

/* ── Table ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: #f8fafc; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td.empty { text-align: center; color: var(--text-muted); padding: 32px; white-space: normal; }
.data-table td.wrap { white-space: normal; max-width: 260px; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 100px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.badge-urgent  { background: #fee2e2; color: #b91c1c; }
.badge-high    { background: #ffedd5; color: #c2410c; }
.badge-medium  { background: #fef9c3; color: #a16207; }
.badge-low     { background: #dcfce7; color: #15803d; }
.badge-status  { background: #e0f2fe; color: #0369a1; }
.badge-role    { background: #ede9fe; color: #6d28d9; }
.badge-score-excellent        { background: #dcfce7; color: #15803d; }
.badge-score-good             { background: #d1fae5; color: #065f46; }
.badge-score-average          { background: #fef9c3; color: #a16207; }
.badge-score-needs-improvement{ background: #fee2e2; color: #b91c1c; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dk); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost     { background: none; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal {
  border: none; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  padding: 0; width: min(560px, 95vw); max-height: 90vh; overflow: hidden;
}
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-inner { padding: 24px; overflow-y: auto; max-height: 90vh; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--text-muted); line-height: 1;
}
.modal-close:hover { color: var(--text); }
#modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; padding-right: 24px; }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border);
}

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.input, .select, .textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; color: var(--text);
  background: var(--surface); outline: none;
  transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); }
.textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Settings ──────────────────────────────────────────────────────────── */
.settings-panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; max-width: 600px; }
.categories-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.category-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; background: var(--bg); border-radius: var(--radius);
  font-size: 13px;
}
.category-item button { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1; padding: 2px 4px; }
.category-item button:hover { color: var(--danger); }
.category-add-row { display: flex; gap: 8px; }
.category-add-row .input { flex: 1; }

/* ── QA Status select inline ───────────────────────────────────────────── */
.status-select { font-size: 12px; padding: 3px 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }

/* ── Run QA button ─────────────────────────────────────────────────────── */
#run-qa-btn .spinner { display: none; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
#run-qa-btn.loading .spinner { display: inline-block; }
#run-qa-btn.loading .btn-label { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; top: 70px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 200px; max-width: 340px;
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  animation: slide-in .2s ease;
}
.toast-success { background: #166534; color: #fff; }
.toast-error   { background: #991b1b; color: #fff; }
.toast-info    { background: #1e40af; color: #fff; }
@keyframes slide-in { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Responsive — below 640px use card layout ──────────────────────────── */
@media (max-width: 640px) {
  .header-inner { gap: 8px; }
  .brand { font-size: 14px; }
  .nav-btn { font-size: 12px; padding: 5px 8px; }
  .user-name { display: none; }
  .main { padding: 16px 10px; }

  .table-wrap { background: none; box-shadow: none; overflow: visible; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr { display: block; }
  .data-table tr {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 10px; padding: 12px;
    border-bottom: none;
  }
  .data-table td {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 4px 0; border: none; white-space: normal;
    font-size: 13px;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--text-muted); font-size: 11px;
    text-transform: uppercase; flex-shrink: 0; width: 110px;
    padding-top: 1px;
  }
  .data-table td.empty::before { content: none; }
  .data-table td.empty { justify-content: center; }
  .form-row { grid-template-columns: 1fr; }
}
