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

:root {
  --dark:    #1a3a5c;
  --med:     #2d6a9f;
  --light:   #f0f4f8;
  --white:   #ffffff;
  --accent:  #e8a020;
  --fatal:   #c0392b;
  --warn:    #e67e22;
  --ok:      #27ae60;
  --gray:    #666666;
  --border:  #d0dae6;
  --shadow:  0 2px 8px rgba(0,0,0,.12);
  --radius:  8px;
  --font:    -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

html, body { height: 100%; font-family: var(--font); background: var(--light);
             color: #1a1a2e; font-size: 14px; }

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen { position: fixed; inset: 0; overflow: auto; }
.screen.hidden { display: none; }
.screen.active { display: block; }

/* ── Login ───────────────────────────────────────────────────────────────── */
#screen-login {
  background: linear-gradient(135deg, var(--dark) 0%, var(--med) 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--white); border-radius: 16px; padding: 40px 36px;
  width: 100%; max-width: 380px; box-shadow: 0 8px 40px rgba(0,0,0,.25);
}
.login-logo { text-align: center; margin-bottom: 14px; }
.login-card h1 {
  text-align: center; color: var(--dark); font-size: 22px;
  line-height: 1.3; margin-bottom: 6px;
}
.login-sub { text-align: center; color: var(--gray); font-size: 12px; margin-bottom: 24px; }
.login-note { text-align: center; color: #aaa; font-size: 11px; margin-top: 16px; }

/* ── Top Nav ─────────────────────────────────────────────────────────────── */
.topnav {
  background: var(--dark); color: var(--white);
  display: flex; align-items: center; padding: 0 16px;
  height: 52px; position: sticky; top: 0; z-index: 200;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.topnav-brand { display: flex; align-items: center; gap: 8px; flex: 1; }
.topnav-icon  { font-size: 20px; }
.topnav-title { font-weight: 700; font-size: 15px; color: var(--accent); }
.topnav-actions { display: flex; align-items: center; gap: 8px; }
.nav-user { font-size: 12px; color: #aaccee; margin-right: 4px; }
.hamburger {
  display: none; background: none; border: none;
  color: var(--white); font-size: 22px; cursor: pointer; padding: 4px 8px;
}

/* ── App body ────────────────────────────────────────────────────────────── */
#screen-app { display: flex; flex-direction: column; }
.app-body {
  display: flex; flex: 1;
  height: calc(100vh - 52px); overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 280px; min-width: 280px; background: var(--dark);
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .25s ease;
}
.sidebar-header {
  padding: 12px 12px 8px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: .5px;
}
.sidebar-search { padding: 0 10px 8px; }
.sidebar-search input {
  width: 100%; padding: 6px 10px; border-radius: 6px;
  border: none; background: #0f2640; color: var(--white);
  font-size: 13px; outline: none;
}
.sidebar-search input::placeholder { color: #6688aa; }
.exam-list { flex: 1; overflow-y: auto; list-style: none; padding: 0 6px 10px; }
.exam-list li {
  padding: 9px 10px; border-radius: 6px; cursor: pointer;
  color: #cce0f5; font-size: 12px; margin-bottom: 2px;
  border-left: 3px solid transparent;
  transition: background .15s;
}
.exam-list li:hover  { background: #1f4a70; }
.exam-list li.active { background: var(--med); color: var(--white);
                        border-left-color: var(--accent); }
.exam-list .exam-status {
  font-size: 10px; color: #88aacc; display: block; margin-top: 2px;
}
.exam-list li.active .exam-status { color: #aaccee; }

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; padding: 0; background: var(--light); }
.view { display: none; }
.view.active { display: block; }

/* ── Welcome ─────────────────────────────────────────────────────────────── */
.welcome-box {
  max-width: 520px; margin: 80px auto; text-align: center; padding: 20px;
}
.welcome-icon { text-align: center; margin-bottom: 12px; }
.welcome-box h2 { color: var(--dark); font-size: 22px; margin-bottom: 10px; }
.welcome-box p  { color: var(--gray); margin-bottom: 24px; }
.welcome-box .btn { display: block; margin: 10px auto; max-width: 300px; }

/* ── Exam Header ─────────────────────────────────────────────────────────── */
.exam-header {
  background: var(--white); padding: 14px 20px;
  display: flex; align-items: flex-start; justify-content: space-between;
  border-bottom: 2px solid var(--border); flex-wrap: wrap; gap: 10px;
}
.exam-header h2 { font-size: 17px; color: var(--dark); margin-bottom: 4px; }
.exam-header-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; color: var(--white);
}
.status-badge.clear  { background: var(--ok); }
.status-badge.defect { background: var(--fatal); }
.status-badge.review { background: var(--warn); }
.status-badge.progress { background: var(--med); }

/* ── Summary bar ─────────────────────────────────────────────────────────── */
.summary-bar {
  display: flex; gap: 0; background: var(--dark);
  overflow-x: auto; padding: 0;
}
.summary-stat {
  flex: 1; min-width: 100px; text-align: center;
  padding: 10px 8px; border-right: 1px solid #2a4a6c;
  color: var(--white);
}
.summary-stat:last-child { border-right: none; }
.summary-stat .stat-val  { font-size: 22px; font-weight: 700; }
.summary-stat .stat-lbl  { font-size: 10px; color: #88aacc; margin-top: 2px; }
.summary-stat.fatal      { background: rgba(192,57,43,.25); }
.summary-stat.fatal .stat-val { color: #ff7070; }
.summary-stat.warn .stat-val  { color: var(--accent); }
.summary-stat.ok .stat-val    { color: #5ddb8a; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; background: var(--med); overflow-x: auto;
  padding: 0 10px; gap: 2px;
}
.tab-btn {
  background: none; border: none; color: rgba(255,255,255,.7);
  padding: 10px 16px; cursor: pointer; font-size: 13px; font-weight: 600;
  white-space: nowrap; border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover  { color: var(--white); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; padding: 16px 20px; }
.tab-panel.active { display: block; }

/* ── Tab toolbar ─────────────────────────────────────────────────────────── */
.tab-toolbar {
  display: flex; gap: 8px; align-items: center; margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar-info { font-size: 12px; color: var(--gray); margin-left: 8px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 16px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.span2 { grid-column: span 2; }
.form-group.span-all { grid-column: 1 / -1; }
.form-group label {
  font-size: 11px; font-weight: 700; color: var(--dark); text-transform: uppercase;
  letter-spacing: .3px;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 6px;
  font-size: 13px; background: var(--white); color: #1a1a2e;
  font-family: var(--font); outline: none;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--med); }
.form-group textarea { resize: vertical; }
.form-hint { font-size: 10px; color: var(--gray); }
.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--dark); font-weight: 600;
  cursor: pointer; margin-top: 6px; text-transform: none; letter-spacing: 0;
}
.checkbox-label input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--ok);
  flex-shrink: 0;
}
.hint-inline { font-size: 10px; color: var(--warn); font-weight: 400; margin-left: 6px; }
.form-section-header {
  background: var(--med); color: var(--white);
  padding: 6px 10px; border-radius: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  grid-column: 1 / -1; margin-top: 6px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 5px; padding: 7px 14px; border-radius: 6px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: opacity .15s, transform .1s; white-space: nowrap;
  font-family: var(--font);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--med);   color: var(--white); }
.btn-success { background: var(--ok);    color: var(--white); }
.btn-danger  { background: var(--fatal); color: var(--white); }
.btn-warning { background: var(--warn);  color: var(--white); }
.btn-dark    { background: var(--dark);  color: var(--white); }
.btn-ghost   { background: #e8edf2;      color: var(--dark);  }
.btn-outline { background: transparent; border: 2px solid var(--med); color: var(--med); }
.btn-sm  { padding: 4px 10px; font-size: 12px; }
.btn-lg  { padding: 10px 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:hover { opacity: .88; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--white); border-radius: var(--radius);
  border: 1.5px solid var(--border); overflow: hidden;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; font-weight: 700; font-size: 13px;
}
.card-header.fatal   { background: #fdecea; color: var(--fatal); border-bottom: 2px solid var(--fatal); }
.card-header.warning { background: #fef9e7; color: #9a5800;      border-bottom: 2px solid var(--warn); }
.card-header.ok      { background: #eafaf1; color: #1a6640;      border-bottom: 2px solid var(--ok); }
.card-header.info    { background: #eaf4fe; color: var(--med);   border-bottom: 2px solid var(--med); }
.card-header.resolved { background: #f0f0f0; color: #888;        border-bottom: 2px solid #ccc; }
.card-body { padding: 10px 14px; }
.card-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px;
  font-size: 12px;
}
.card-grid .lbl { color: var(--gray); font-weight: 600; font-size: 11px; }
.card-grid .val { color: var(--dark); }
.card-findings { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.finding {
  padding: 6px 10px; border-radius: 4px; margin-bottom: 5px;
  font-size: 12px; line-height: 1.5;
}
.finding.fatal   { background: #fdecea; border-left: 3px solid var(--fatal); }
.finding.warning { background: #fef9e7; border-left: 3px solid var(--warn); }
.finding.info    { background: #eafaf1; border-left: 3px solid var(--ok); }
.finding-code  { font-weight: 700; margin-right: 4px; }
.finding-guide { font-size: 11px; color: var(--gray); margin-top: 3px; padding-left: 8px; }
.card-actions { padding: 8px 14px; border-top: 1px solid var(--border);
                display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Chain table ─────────────────────────────────────────────────────────── */
.chain-table-wrap { overflow-x: auto; }
.chain-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
  background: var(--white); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.chain-table th {
  background: var(--dark); color: var(--white);
  padding: 9px 12px; text-align: left; font-size: 11px; letter-spacing: .3px;
  white-space: nowrap;
}
.chain-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.chain-table tr:hover td { background: #f5f8fc; }
.chain-table tr:last-child td { border-bottom: none; }
.chain-gap td { background: #fdecea !important; }

/* ── Issues ──────────────────────────────────────────────────────────────── */
.issue-card .card-header { justify-content: space-between; }
.issue-actions { display: flex; gap: 6px; }
.badge {
  display: inline-block; background: var(--fatal); color: var(--white);
  font-size: 10px; font-weight: 700; border-radius: 10px;
  padding: 1px 6px; margin-left: 4px; vertical-align: middle;
}
.badge.hidden { display: none; }

/* ── Activity feed ───────────────────────────────────────────────────────── */
.activity-feed { display: flex; flex-direction: column; gap: 1px; }
.activity-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; background: var(--white);
  border-bottom: 1px solid var(--border); font-size: 12px;
}
.activity-icon { font-size: 18px; flex-shrink: 0; }
.activity-text { flex: 1; }
.activity-who  { font-weight: 700; color: var(--dark); }
.activity-what { color: var(--gray); }
.activity-when { font-size: 10px; color: #aaa; margin-top: 2px; }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 500; }
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.45); backdrop-filter: blur(2px);
}
.modal-dialog {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: var(--white); border-radius: 12px;
  width: 90%; max-width: 700px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 48px rgba(0,0,0,.3);
  z-index: 1;
}
.modal-dialog.modal-lg  { max-width: 860px; }
.modal-dialog.modal-sm  { max-width: 440px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 2px solid var(--border);
  background: var(--dark); border-radius: 12px 12px 0 0;
}
.modal-header h3 { color: var(--accent); font-size: 16px; }
.modal-close {
  background: none; border: none; color: var(--white);
  font-size: 18px; cursor: pointer; padding: 4px 8px;
}
.modal-body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.modal-footer {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: #f8fafc; border-radius: 0 0 12px 12px;
}
.modal-tip { font-size: 11px; color: var(--warn); margin-left: auto; }

/* ── Defect result block ─────────────────────────────────────────────────── */
.defect-result {
  margin-top: 16px; padding: 14px; border-radius: 8px;
  background: #f9f9f0; border: 1px solid var(--border);
}
.defect-result.has-defects { background: #fdecea; border-color: var(--fatal); }
.defect-result.has-warnings{ background: #fef9e7; border-color: var(--warn); }
.defect-result.all-ok      { background: #eafaf1; border-color: var(--ok); }

/* ── Analysis box ────────────────────────────────────────────────────────── */
.analysis-box {
  padding: 14px; border-radius: 8px; margin-bottom: 14px;
  background: #f9f9f0; border: 1px solid var(--border);
  font-size: 13px; line-height: 1.6; white-space: pre-wrap;
}
.analysis-box.hidden { display: none; }

/* ── Guidance ────────────────────────────────────────────────────────────── */
.guidance-wrap { padding: 20px; max-width: 820px; margin: 0 auto; }
.guidance-wrap h2 { color: var(--dark); margin-bottom: 14px; }
.guidance-tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.gtab {
  padding: 7px 16px; border-radius: 20px; border: 2px solid var(--med);
  background: transparent; color: var(--med); font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all .15s;
}
.gtab.active { background: var(--med); color: var(--white); }
.guidance-text {
  background: var(--white); border: 1px solid var(--border);
  border-radius: 8px; padding: 20px; font-family: "Courier New", monospace;
  font-size: 13px; line-height: 1.7; white-space: pre-wrap;
  overflow-x: auto; box-shadow: var(--shadow);
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 10px;
}
.alert-error   { background: #fdecea; color: var(--fatal); border: 1px solid #f5b7b1; }
.alert-info    { background: #eaf4fe; color: var(--med);   border: 1px solid #aed6f1; }
.alert-success { background: #eafaf1; color: var(--ok);    border: 1px solid #a9dfbf; }
.alert.hidden  { display: none; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  padding: 12px 20px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: var(--dark); color: var(--white); box-shadow: 0 4px 20px rgba(0,0,0,.3);
  transition: opacity .3s;
}
.toast.hidden { display: none; }
.toast.success { background: var(--ok); }
.toast.error   { background: var(--fatal); }
.toast.warning { background: var(--warn); }

/* ── Attorney-only elements hidden for paralegals ─────────────────────────── */
.attorney-only { display: none; }
body.role-attorney .attorney-only { display: inline-flex; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 52px; bottom: 0; left: 0; z-index: 150;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .topnav-actions .btn { font-size: 11px; padding: 4px 8px; }

  .exam-header { flex-direction: column; }
  .exam-header-actions { width: 100%; }
  .exam-header-actions .btn { flex: 1; font-size: 12px; padding: 6px 8px; }

  .summary-bar { flex-wrap: wrap; }
  .summary-stat { min-width: 90px; flex: 1 1 90px; }

  .form-grid { grid-template-columns: 1fr; }
  .form-group.span2, .form-group.span-all { grid-column: 1; }

  .modal-dialog { width: 98%; top: 2%; transform: translate(-50%, 0); max-height: 96vh; }

  .card-grid { grid-template-columns: 1fr; }

  .chain-table th:nth-child(5),
  .chain-table td:nth-child(5) { display: none; }

  .tab-btn { font-size: 12px; padding: 8px 10px; }
}

@media (max-width: 480px) {
  .topnav-title { font-size: 13px; }
  .exam-header-actions .btn span { display: none; }
  .summary-stat { min-width: 75px; }
  .summary-stat .stat-val { font-size: 18px; }
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: var(--white);
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress Tracker ────────────────────────────────────────────────────── */
.progress-tracker { display: flex; flex-direction: column; gap: 0; }
.progress-phase {
  background: var(--dark); color: var(--accent);
  padding: 8px 16px; font-size: 11px; font-weight: 700;
  letter-spacing: .5px; margin-top: 10px; border-radius: 5px;
}
.progress-step {
  display: flex; align-items: center; gap: 12px;
  background: var(--white); padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.progress-step:hover { background: #f8fafc; }
.progress-step-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--med); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.progress-step-label { flex: 1; font-size: 13px; color: var(--dark); font-weight: 600; }
.progress-step-note  { font-size: 11px; color: var(--gray); margin-top: 2px; font-weight: 400; }
.progress-status {
  display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end;
}
.status-btn {
  padding: 4px 10px; border-radius: 12px; border: 2px solid transparent;
  font-size: 11px; font-weight: 700; cursor: pointer; transition: all .15s;
  background: #f0f4f8; color: var(--gray);
}
.status-btn:hover { opacity: .85; }
.status-btn.active-not-started  { background: #e8edf2; color: var(--dark);  border-color: var(--dark); }
.status-btn.active-in-process   { background: #fef9e7; color: var(--warn);  border-color: var(--warn); }
.status-btn.active-completed    { background: #eafaf1; color: var(--ok);    border-color: var(--ok); }
.status-btn.active-on-hold      { background: #fdecea; color: var(--fatal); border-color: var(--fatal); }
.progress-step-num.completed    { background: var(--ok); }
.progress-step-num.in-process   { background: var(--warn); }
.progress-step-num.on-hold      { background: var(--fatal); }
.progress-overall {
  display: flex; gap: 12px; padding: 12px 14px;
  background: var(--dark); border-radius: 8px; margin-bottom: 12px;
  align-items: center;
}
.progress-bar-wrap {
  flex: 1; background: rgba(255,255,255,.15); border-radius: 10px; height: 10px;
}
.progress-bar-fill {
  height: 10px; border-radius: 10px; background: var(--ok);
  transition: width .4s ease;
}
.progress-pct { color: var(--accent); font-size: 16px; font-weight: 700; min-width: 40px; text-align: right; }
.progress-label { color: #aaccee; font-size: 11px; }

/* ── Document Summary Table ──────────────────────────────────────────────── */
.doc-summary-wrap {
  overflow-x: auto; margin-bottom: 4px;
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.doc-summary-table {
  width: 100%; border-collapse: collapse;
  background: var(--white); font-size: 12px;
}
.doc-summary-table th {
  background: var(--dark); color: var(--white);
  padding: 7px 10px; text-align: left;
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap;
}
.doc-summary-row {
  cursor: pointer; transition: background .12s;
  border-bottom: 1px solid var(--border);
}
.doc-summary-row:hover { background: #eef4fb; }
.doc-summary-row td { padding: 7px 10px; vertical-align: middle; }
.doc-summary-row:last-child { border-bottom: none; }
