:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1a1f29;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2c5282;
  --accent-ink: #fff;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
.btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
}
.btn.secondary { background: #fff; color: var(--accent); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* ---- top bar ---- */
header.topbar {
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
}
header.topbar .brand { font-weight: 700; letter-spacing: .3px; }
header.topbar .brand small { font-weight: 400; color: #aeb6c2; margin-left: 8px; }
header.topbar .who { font-size: 13px; color: #cdd3dc; }
header.topbar .who .role { background: #2c5282; color:#fff; padding: 2px 8px; border-radius: 20px; margin-left: 8px; font-size:11px; text-transform: uppercase; letter-spacing:.5px;}
header.topbar .who .role.lawyer { background:#4a5568; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }

/* ---- score banner ---- */
.score-banner { display: flex; gap: 0; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px; }
.score-banner:empty { display: none; }
.sb-grade { color: #fff; padding: 16px 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 150px; text-align: center; }
.sb-level { font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: .5px; }
.sb-sub { font-size: 11px; opacity: .9; margin-top: 6px; text-transform: uppercase; letter-spacing: .5px; }
.sb-body { flex: 1; padding: 14px 18px; min-width: 0; }
.sb-top { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.sb-title { font-weight: 700; font-size: 16px; }
.sb-strength { font-size: 13px; color: var(--muted); }
.sb-bar { height: 9px; background: #edf0f4; border-radius: 6px; overflow: hidden; margin: 8px 0 12px; }
.sb-fill { height: 100%; border-radius: 6px; transition: width .4s; }
.sb-baker { font-size: 13px; margin-bottom: 8px; }
.sb-baker .bk { display: inline-block; background: #eef2f7; border: 1px solid var(--line); border-radius: 20px; padding: 2px 9px; font-size: 12px; margin: 3px 4px 0 0; }
.sb-cc { font-size: 12px; color: var(--danger); margin-bottom: 6px; }
.sb-sevline { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.sb-frame { font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.sb-disc { font-style: italic; }
@media (max-width: 600px) { .score-banner { flex-direction: column; } .sb-grade { flex-direction: row; gap: 10px; min-width: 0; } }

/* ---- stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); border-left: 4px solid var(--muted); }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

/* ---- toolbar ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search], .toolbar select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background:#fff; font: inherit;
}
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.pillar-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip {
  border: 1px solid var(--line); background:#fff; border-radius: 20px; padding: 5px 12px; font-size: 13px; color: var(--ink);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; display:inline-block; }
.chip.active { color:#fff; border-color: transparent; }

/* ---- cards ---- */
.card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 14px; border-left: 4px solid var(--muted);
}
.card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card .date { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.card h3 { margin: 2px 0 8px; font-size: 17px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.tag { font-size: 11px; padding: 2px 9px; border-radius: 20px; color:#fff; font-weight:600; }
.sev { font-size: 11px; padding: 2px 9px; border-radius: 6px; font-weight:700; text-transform: uppercase; letter-spacing:.4px; }
.sev.low { background:#e6f4ea; color:#1e7e34; }
.sev.medium { background:#fff3cd; color:#8a6d00; }
.sev.high { background:#fde0dd; color:#c0392b; }
blockquote {
  margin: 10px 0; padding: 10px 14px; background:#f8f9fb; border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0; white-space: pre-wrap; font-style: italic;
}
.card .context { margin: 8px 0; white-space: pre-wrap; }
.card .meta { font-size: 13px; color: var(--muted); margin-top: 8px; display:flex; flex-wrap:wrap; gap:14px; }
.card .meta a { word-break: break-all; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumbs a img { height: 76px; border-radius: 6px; border: 1px solid var(--line); object-fit: cover; }
.thumbs a.fileicon { display:flex; align-items:center; gap:6px; padding:8px 10px; border:1px solid var(--line); border-radius:6px; background:#fff; font-size:13px; text-decoration:none; color:var(--ink);}
.card .actions { display: flex; gap: 8px; margin-top: 12px; }
.empty { text-align:center; color: var(--muted); padding: 60px 20px; }

/* ---- modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,20,30,.55); display:none; align-items:flex-start; justify-content:center; padding: 40px 16px; overflow:auto; z-index: 50;}
.modal-backdrop.open { display: flex; }
.modal { background:#fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal header { display:flex; justify-content:space-between; align-items:center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin:0; font-size: 18px; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 14px 20px; border-top:1px solid var(--line); display:flex; justify-content:flex-end; gap:10px; }
label.field { display:block; margin-bottom: 14px; font-size: 13px; font-weight:600; color:#374151; }
label.field input, label.field textarea, label.field select {
  display:block; width:100%; margin-top:5px; padding:8px 10px; border:1px solid var(--line); border-radius:8px; font: inherit;
}
label.field textarea { min-height: 80px; resize: vertical; }
.pillar-picker { display:flex; flex-wrap:wrap; gap:8px; margin-top:5px; }
.pillar-picker label { display:inline-flex; align-items:center; gap:6px; font-weight:500; border:1px solid var(--line); padding:5px 10px; border-radius:8px; cursor:pointer; }
.two { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.error-banner { background:#fde0dd; color:#a3271b; padding:10px 14px; border-radius:8px; margin-bottom:14px; display:none; }

/* ---- sources panel ---- */
.tabs { display:flex; gap: 6px; margin-bottom: 16px; }
.tabs button { background:transparent; border:none; padding:8px 14px; border-radius:8px 8px 0 0; color:var(--muted); font-weight:600; }
.tabs button.active { background:var(--panel); color:var(--ink); box-shadow: var(--shadow); }
.tree { background:var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; }
.tree ul { list-style:none; margin:0; padding-left: 18px; }
.tree > ul { padding-left: 0; }
.tree li { padding: 3px 0; }
.tree .dir > span { font-weight:600; cursor: default; }
.tree .file a { text-decoration:none; }
.tree .size { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ---- login ---- */
.login-page { display:flex; min-height: 100vh; align-items:center; justify-content:center; background: var(--ink); }
.login-card { background:#fff; padding: 32px; border-radius: 14px; width: 340px; box-shadow: 0 12px 40px rgba(0,0,0,.4); }
.login-card h1 { margin:0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card label { display:block; font-size:13px; font-weight:600; margin-bottom:12px; }
.login-card input { display:block; width:100%; margin-top:5px; padding:10px; border:1px solid var(--line); border-radius:8px; font: inherit; }
.login-card .btn { width:100%; margin-top:6px; padding: 11px; }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top:8px; }

/* ---- clickable cards + detail view ---- */
.card.clickable { cursor: pointer; transition: box-shadow .15s, transform .05s; }
.card.clickable:hover { box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.modal.detail { max-width: 760px; }
.dmeta-top { display: flex; align-items: center; gap: 12px; }
.dmeta-top .date { font-variant-numeric: tabular-nums; color: var(--muted); }
.dlabel { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; margin: 14px 0 4px; }
.drow { display: flex; gap: 12px; margin: 6px 0; font-size: 14px; align-items: baseline; }
.drow .dlabel { margin: 0; min-width: 140px; }
.dval, .drow .dval { word-break: break-word; }
.detail-shots { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
img.detail-shot { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; }
.img-shot { display: inline-block; cursor: zoom-in; }
.pagebadge { background: var(--accent); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 20px; font-weight: 600; margin-left: 4px; }

/* ---- in-app PDF viewer ---- */
.pdf-backdrop { align-items: center; padding: 18px; z-index: 90; }
.pdf-wrap { background: #fff; border-radius: 10px; width: 94vw; max-width: 1100px; height: 92vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 14px 50px rgba(0,0,0,.45); }
.pdf-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.pdf-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-actions { display: flex; gap: 8px; flex-shrink: 0; }
.pdf-iframe { flex: 1; width: 100%; border: none; background: #525659; }
.pdf-link { cursor: pointer; }

/* ---- lightbox / slideshow ---- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.93); display: none; align-items: center; justify-content: center; z-index: 100; }
.lightbox.open { display: flex; }
.lb-img { max-width: 92vw; max-height: 88vh; object-fit: contain; border-radius: 4px; box-shadow: 0 6px 40px rgba(0,0,0,.6); }
.lb-btn { position: absolute; background: rgba(255,255,255,.12); color: #fff; border: none; cursor: pointer; border-radius: 8px; display: flex; align-items: center; justify-content: center; transition: background .15s; }
.lb-btn:hover { background: rgba(255,255,255,.28); }
.lb-close { top: 18px; right: 22px; width: 44px; height: 44px; font-size: 22px; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); width: 60px; height: 92px; font-size: 44px; line-height: 1; }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-counter { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 14px; background: rgba(0,0,0,.55); padding: 6px 16px; border-radius: 20px; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) {
  .lb-prev, .lb-next { width: 44px; height: 70px; font-size: 32px; }
}

@media print {
  header.topbar, .toolbar, .pillar-chips, .tabs, .card .actions, .stat .l + *, #addBtn { display:none !important; }
  .card { box-shadow:none; border:1px solid #ccc; break-inside: avoid; }
  body { background:#fff; }
}
