/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --compliant:      #16a34a;
  --compliant-bg:   #dcfce7;
  --non-compliant:  #dc2626;
  --non-compliant-bg: #fee2e2;
  --in-progress:    #d97706;
  --in-progress-bg: #fef3c7;
  --not-applicable: #6b7280;
  --not-applicable-bg: #f3f4f6;
  --not-started:    #94a3b8;
  --not-started-bg: #f8fafc;
  --primary:        #1e40af;
  --primary-light:  #dbeafe;
  --border:         #e2e8f0;
  --bg:             #f8fafc;
  --card:           #ffffff;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --sidebar-w:      240px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ───────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 16px;
  border-bottom: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand .logo {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.sidebar-brand h1 { font-size: 13px; font-weight: 600; color: #f1f5f9; line-height: 1.3; }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid #334155;
  flex-shrink: 0;
}
.logout-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px;
  color: #94a3b8;
  font-size: 13px;
  border-radius: 6px;
  transition: background .15s, color .15s;
  text-decoration: none;
}
.logout-link:hover { background: #334155; color: #f1f5f9; text-decoration: none; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  color: #94a3b8;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: #334155; color: #f1f5f9; text-decoration: none;
}
.sidebar-nav .section-group { margin-top: 4px; }
.sidebar-nav .section-label {
  padding: 6px 16px 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
}
.sidebar-nav .dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--not-started);
}
.sidebar-nav .dot.compliant      { background: var(--compliant); }
.sidebar-nav .dot.non-compliant  { background: var(--non-compliant); }
.sidebar-nav .dot.in-progress    { background: var(--in-progress); }
.sidebar-nav .dot.not-applicable { background: var(--not-applicable); }
.sidebar-nav .dot.mixed          { background: linear-gradient(135deg, var(--compliant) 50%, var(--in-progress) 50%); }

.main { flex: 1; min-width: 0; padding: 24px; }

/* ─── Topbar ───────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.topbar .breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
}
.topbar .breadcrumb span { color: var(--text); font-weight: 600; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; }

/* ─── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

/* ─── Status Badge ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.compliant      { background: var(--compliant-bg);      color: var(--compliant); }
.badge.non-compliant  { background: var(--non-compliant-bg);  color: var(--non-compliant); }
.badge.in-progress    { background: var(--in-progress-bg);    color: var(--in-progress); }
.badge.not-applicable { background: var(--not-applicable-bg); color: var(--not-applicable); }
.badge.not-started    { background: var(--not-started-bg);    color: var(--not-started); }

/* ─── Progress Bar ─────────────────────────────────────────────────── */
.progress-wrap {
  height: 8px; background: #e2e8f0; border-radius: 4px;
  overflow: hidden; display: flex;
}
.progress-seg { height: 100%; transition: width .3s; }
.progress-seg.compliant      { background: var(--compliant); }
.progress-seg.non-compliant  { background: var(--non-compliant); }
.progress-seg.in-progress    { background: var(--in-progress); }
.progress-seg.not-applicable { background: var(--not-applicable); }

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; font-size: 13px;
  font-weight: 500; cursor: pointer; border: 1px solid transparent;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-outline   { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f1f5f9; }
.btn-danger    { background: #fee2e2; color: var(--non-compliant); border-color: #fecaca; }
.btn-danger:hover { background: #fecaca; }
.btn-sm        { padding: 4px 10px; font-size: 12px; }
.btn-icon      { padding: 5px; border-radius: 6px; }

/* ─── Dashboard ────────────────────────────────────────────────────── */
.dashboard-header {
  display: flex; align-items: flex-start; gap: 24px;
  flex-wrap: wrap; margin-bottom: 24px;
}
.donut-wrap { position: relative; width: 120px; height: 120px; flex-shrink: 0; }
.donut-wrap svg { width: 120px; height: 120px; transform: rotate(-90deg); }
.donut-wrap .donut-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-text .pct  { font-size: 22px; font-weight: 700; color: var(--text); }
.donut-text .lbl  { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

.overall-stats { flex: 1; }
.overall-stats h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.overall-stats p  { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 12px; }
.stat-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.stat-dot  { width: 10px; height: 10px; border-radius: 50%; }

.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  text-decoration: none; color: inherit; display: block;
}
.section-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); border-color: #93c5fd; text-decoration: none; }
.section-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.section-card .progress-wrap { margin-bottom: 8px; }
.section-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; font-size: 12px; }
.section-stats span { display: flex; align-items: center; gap: 4px; color: var(--text-muted); }

/* ─── Section Page ─────────────────────────────────────────────────── */
.criteria-table { width: 100%; border-collapse: collapse; }
.criteria-table th, .criteria-table td {
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.criteria-table th { font-weight: 600; background: #f8fafc; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.criteria-table tr:last-child td { border-bottom: none; }
.criteria-table tr:hover td { background: #f8fafc; }
.criteria-table .code-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  background: var(--primary-light); color: var(--primary);
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.file-count { font-size: 12px; color: var(--text-muted); }
.file-count.has-files { color: var(--primary); font-weight: 600; }

.status-select {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; font-weight: 600;
  cursor: pointer; background: #fff;
}
.status-select.compliant      { border-color: var(--compliant);      color: var(--compliant);      background: var(--compliant-bg); }
.status-select.non-compliant  { border-color: var(--non-compliant);  color: var(--non-compliant);  background: var(--non-compliant-bg); }
.status-select.in-progress    { border-color: var(--in-progress);    color: var(--in-progress);    background: var(--in-progress-bg); }
.status-select.not-applicable { border-color: var(--not-applicable); color: var(--not-applicable); background: var(--not-applicable-bg); }
.status-select.not-started    { border-color: var(--not-started);    color: var(--not-started);    background: var(--not-started-bg); }

/* ─── Criterion Page ───────────────────────────────────────────────── */
.criterion-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .criterion-layout { grid-template-columns: 1fr; } }

.criterion-header { margin-bottom: 20px; }
.criterion-header .code { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--primary); margin-bottom: 4px; }
.criterion-header h2 { font-size: 20px; font-weight: 700; }
.criterion-header .section-crumb { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.criterion-nav { display: flex; gap: 8px; margin-top: 16px; }

.status-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.status-btn {
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 2px solid transparent; transition: all .15s;
}
.status-btn.compliant      { border-color: var(--compliant);      background: #fff;                 color: var(--compliant); }
.status-btn.compliant.active, .status-btn.compliant:hover      { background: var(--compliant-bg); }
.status-btn.non-compliant  { border-color: var(--non-compliant);  background: #fff;                 color: var(--non-compliant); }
.status-btn.non-compliant.active, .status-btn.non-compliant:hover  { background: var(--non-compliant-bg); }
.status-btn.in-progress    { border-color: var(--in-progress);    background: #fff;                 color: var(--in-progress); }
.status-btn.in-progress.active, .status-btn.in-progress:hover    { background: var(--in-progress-bg); }
.status-btn.not-applicable { border-color: var(--not-applicable); background: #fff;                 color: var(--not-applicable); }
.status-btn.not-applicable.active, .status-btn.not-applicable:hover { background: var(--not-applicable-bg); }
.status-btn.not-started    { border-color: var(--not-started);    background: #fff;                 color: var(--not-started); }
.status-btn.not-started.active, .status-btn.not-started:hover    { background: var(--not-started-bg); }

.notes-area {
  width: 100%; min-height: 100px;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; font-family: inherit;
  resize: vertical; transition: border-color .15s;
}
.notes-area:focus { outline: none; border-color: #93c5fd; }

.form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; display: block; }

/* ─── Requirements Modal ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #fff; border-radius: 12px;
  width: 100%; max-width: 680px; max-height: 85vh;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 18px; line-height: 1;
}
.modal-close:hover { background: #f1f5f9; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body h4 { font-size: 13px; font-weight: 700; margin: 14px 0 6px; color: var(--text); }
.modal-body h4:first-child { margin-top: 0; }
.modal-body ul, .modal-body ol { padding-left: 20px; margin: 6px 0; }
.modal-body li { margin-bottom: 4px; font-size: 13px; }
.modal-body p  { font-size: 13px; margin-bottom: 8px; }
.modal-body em { color: var(--text-muted); }

/* ─── Evidence Section Header ──────────────────────────────────────── */
.evidence-section-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
}
.evidence-count-badge {
  background: var(--primary-light); color: var(--primary);
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
}

/* ─── Evidence Item Card ───────────────────────────────────────────── */
.evidence-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  margin-bottom: 14px;
}
.evidence-card-header {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  overflow: hidden;
}
.evidence-num-badge {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.evidence-item-text {
  flex: 1; font-size: 13px; font-weight: 500; color: var(--text); line-height: 1.5;
}
.evidence-file-count {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: #f1f5f9; padding: 2px 8px; border-radius: 20px;
  white-space: nowrap; flex-shrink: 0; margin-top: 2px;
}
.evidence-file-count.has-files {
  color: var(--primary); background: var(--primary-light);
}
.evidence-card-body {
  padding: 12px 14px;
}

/* ─── Compact Upload Zone ──────────────────────────────────────────── */
.upload-zone-sm {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  border: 1.5px dashed var(--border); border-radius: 8px;
  padding: 10px 14px; cursor: pointer;
  font-size: 12px; color: var(--text-muted);
  transition: border-color .15s, background .15s;
}
.upload-zone-sm:hover, .upload-zone-sm.drag-over {
  border-color: #93c5fd; background: #eff6ff;
}
.upload-zone-sm-icon { font-size: 16px; }
.upload-zone-sm strong { color: var(--primary); }

/* ─── Upload Zone ──────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border); border-radius: 10px;
  padding: 24px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: #93c5fd; background: #eff6ff;
}
.upload-zone input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.upload-zone .icon { font-size: 28px; margin-bottom: 6px; }
.upload-zone p { font-size: 13px; color: var(--text-muted); }
.upload-zone p strong { color: var(--primary); }

.desc-input {
  width: 100%; margin-top: 10px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 13px; font-family: inherit;
}
.desc-input:focus { outline: none; border-color: #93c5fd; }

/* ─── File List ────────────────────────────────────────────────────── */
.file-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: #fff;
}
.file-icon {
  width: 36px; height: 36px; border-radius: 6px;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; }
.file-info .fname { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-info .fmeta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.file-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* ─── Kebab Menu ───────────────────────────────────────────────────── */
.kebab-wrap { position: relative; }
.kebab-btn {
  background: none; border: none; cursor: pointer;
  padding: 5px 7px; border-radius: 6px; font-size: 16px; color: var(--text-muted);
  line-height: 1;
}
.kebab-btn:hover { background: #f1f5f9; }
.kebab-menu {
  position: absolute; right: 0; top: 100%; margin-top: 4px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.1);
  min-width: 130px; z-index: 100; overflow: hidden;
}
.kebab-menu.hidden { display: none; }
.kebab-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 14px;
  background: none; border: none; cursor: pointer;
  font-size: 13px; text-align: left; color: var(--text);
}
.kebab-menu button:hover { background: #f1f5f9; }
.kebab-menu button.danger { color: var(--non-compliant); }
.kebab-menu button.danger:hover { background: #fee2e2; }

/* ─── Toast ────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 2000;
}
.toast {
  padding: 12px 16px; border-radius: 8px; font-size: 13px;
  color: #fff; max-width: 300px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  animation: slideIn .25s ease;
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─── Misc ─────────────────────────────────────────────────────────── */
.section-header { margin-bottom: 20px; }
.section-header h2 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }

.loading { color: var(--text-muted); font-size: 13px; padding: 24px; text-align: center; }
.empty   { color: var(--text-muted); font-size: 13px; text-align: center; padding: 32px; }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.last-modified { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ─── File Tree View ────────────────────────────────────────────────── */
.tree-section { margin-bottom: 8px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--card); }

.tree-section-hdr {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer;
  background: #f1f5f9; border-bottom: 1px solid var(--border);
  user-select: none;
}
.tree-section-hdr:hover { background: #e2e8f0; }
.tree-toggle { font-size: 11px; color: var(--text-muted); width: 12px; flex-shrink: 0; }
.tree-section-icon { font-size: 15px; }
.tree-section-label { font-weight: 700; font-size: 13px; flex: 1; }
.tree-section-meta { display: flex; gap: 6px; flex-shrink: 0; }

.tree-badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: 10px;
  background: var(--primary-light); color: var(--primary);
}
.tree-badge-files { background: #f3f4f6; color: var(--text-muted); }

.tree-criterion { border-bottom: 1px solid var(--border); }
.tree-criterion:last-child { border-bottom: none; }
.tree-criterion-empty { opacity: .65; }

.tree-criterion-hdr {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 28px; font-size: 13px;
}
.tree-ccode { font-weight: 700; color: var(--primary); min-width: 60px; flex-shrink: 0; }
.tree-ctitle { flex: 1; }
.tree-status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tree-status-label { font-size: 11px; font-weight: 600; min-width: 90px; flex-shrink: 0; }

.tree-evidence { padding: 4px 14px 8px 44px; }
.tree-ev-label { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.tree-ev-num { font-size: 11px; font-weight: 700; color: var(--text-muted); min-width: 68px; flex-shrink: 0; }
.tree-ev-text { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.tree-files { padding-left: 76px; }
.tree-no-files { font-size: 11px; color: #cbd5e1; font-style: italic; padding: 1px 0 4px; }

.tree-file {
  display: flex; align-items: baseline; gap: 6px;
  padding: 3px 0; font-size: 12px;
  border-left: 2px solid var(--border); padding-left: 10px; margin-bottom: 2px;
}
.tree-file-icon { font-size: 13px; flex-shrink: 0; }
.tree-file-name { font-weight: 600; color: var(--primary); word-break: break-all; }
.tree-file-name:hover { text-decoration: underline; }
.tree-file-meta { color: var(--text-muted); font-size: 11px; flex-shrink: 0; white-space: nowrap; }
.tree-file-desc { color: var(--text-muted); font-size: 11px; font-style: italic; }
