/* ================= Base / Theme ================= */
:root {
  --navy: #132844;
  --navy-dark: #0a1729;
  --navy-mid: #1d3a5f;
  --gold: #b8863f;
  --gold-light: #e8c789;
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e1e6ee;
  --border-soft: #ebeef4;
  --text: #1b2432;
  --muted: #6c7789;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --success: #1e7a34;
  --success-bg: #e9f7ec;
  --info: #1a4d8f;
  --info-bg: #e8f0fb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(19, 40, 68, .06);
  --shadow-md: 0 4px 14px rgba(19, 40, 68, .08), 0 1px 3px rgba(19, 40, 68, .06);
  --shadow-lg: 0 20px 50px rgba(10, 20, 35, .28);
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15.5px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--navy-mid); text-decoration: none; transition: color .15s ease; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .55em; color: var(--navy); font-weight: 700; letter-spacing: -.01em; }
h1 { font-family: var(--serif); font-weight: 700; }
p { margin: 0 0 1em; }
::selection { background: var(--gold-light); color: var(--navy-dark); }

/* ================= Topbar ================= */
.topbar {
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  position: sticky; top: 0; z-index: 200;
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 28px; height: 60px;
}
.brand {
  color: #fff; font-weight: 700; font-size: 1.12rem; letter-spacing: .2px;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  font-family: var(--serif);
}
.brand:hover { text-decoration: none; opacity: .92; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: var(--navy-dark); font-size: 1rem; flex-shrink: 0;
}
.nav-toggle {
  display: none; margin-left: auto; background: none; border: 1px solid rgba(255,255,255,.25);
  color: #fff; border-radius: 6px; padding: 7px 10px; cursor: pointer; font-size: 1rem;
}
.mainnav { display: flex; align-items: center; gap: 4px; flex: 1; }
.mainnav a {
  color: #c8d3e2; font-size: .91rem; padding: 8px 12px; border-radius: 6px;
  transition: background .15s ease, color .15s ease; white-space: nowrap;
}
.mainnav a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,.08); }
.mainnav a.active { color: #fff; background: rgba(255,255,255,.12); font-weight: 600; }
.cart-link { display: inline-flex; align-items: center; gap: 6px; }
.cart-badge {
  background: var(--gold); color: #241c05; font-size: .72rem; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; min-width: 18px; text-align: center;
}
.user-menu { display: flex; align-items: center; gap: 12px; font-size: .87rem; color: #cbd5e1; white-space: nowrap; }
.user-menu a { color: #cbd5e1; padding: 6px 4px; }
.user-menu a:hover { color: #fff; }

@media (max-width: 1060px) {
  .nav-toggle { display: inline-flex; align-items: center; gap: 6px; }
  .mainnav {
    display: none; position: absolute; top: 60px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 2px;
    background: var(--navy-dark); padding: 10px; box-shadow: var(--shadow-lg);
  }
  .mainnav.open { display: flex; }
  .mainnav a { padding: 10px 12px; }
  .topbar-inner { flex-wrap: wrap; height: auto; min-height: 60px; padding: 10px 16px; }
  .user-menu { margin-left: auto; }
}

/* ================= Layout ================= */
.page-wrap { max-width: 1240px; margin: 0 auto; padding: 28px 20px 64px; }
footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 24px; }

.card {
  background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px; margin-bottom: 22px;
}
.card h2 { margin-top: 0; font-size: 1.08rem; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 1.7rem; }

/* ================= Flash messages ================= */
.flash {
  padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: .92rem;
  display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow-sm);
}
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid #b9e3c1; }
.flash-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f2c1bd; }
.flash-info { background: var(--info-bg); color: var(--info); border: 1px solid #c3d9f5; }

/* ================= Forms ================= */
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 6px; color: #33404f; }
.form-row { margin-bottom: 17px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
input[type=text], input[type=search], input[type=password], input[type=date], input[type=file], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid #ccd3dd; border-radius: var(--radius-sm);
  font-size: .95rem; font-family: inherit; background: #fff; color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--navy-mid); box-shadow: 0 0 0 3px rgba(19,40,68,.12); }
input:hover, textarea:hover, select:hover { border-color: #b7c0cc; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 5px; line-height: 1.5; }
.short-note-field textarea { min-height: 180px; } /* ~quarter page of writing room */

#citationRows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.citation-row { display: flex; gap: 8px; align-items: center; }
.citation-row input { flex: 1 1 auto; }
.citation-row .remove-citation-btn { flex: 0 0 auto; padding: 8px 12px; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 16px; }
legend { font-weight: 700; font-size: .85rem; padding: 0 8px; color: var(--navy); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 7px 0; }
.checkbox-row input { width: auto; accent-color: var(--navy-mid); }
.checkbox-row label { margin: 0; font-weight: 400; cursor: pointer; }

/* ================= Buttons ================= */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--navy); background: var(--navy); color: #fff;
  padding: 10px 20px; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 600;
  text-decoration: none; box-shadow: var(--shadow-sm);
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--navy-mid); text-decoration: none; box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn-secondary { background: #fff; color: var(--navy); border-color: #ccd3dd; }
.btn-secondary:hover { background: #f4f6fa; box-shadow: var(--shadow-sm); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #8f1f18; }
.btn-sm { padding: 6px 13px; font-size: .8rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ================= Tables ================= */
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--border-soft); font-size: .89rem; vertical-align: top; }
th { background: #f6f8fb; color: #445064; font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
tbody tr { transition: background .1s ease; }
tbody tr:hover td { background: #f9fafc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border-soft); border-radius: var(--radius); }
.table-wrap table { border: none; }
.muted { color: var(--muted); }
.tag { display: inline-block; background: #eef1f6; border-radius: 4px; padding: 1px 8px; font-size: .76rem; color: #445; }
mark { background: #ffe9a3; padding: 0 2px; border-radius: 2px; }

/* ================= Modal / popup (PDF search) ================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,16,28,.6); backdrop-filter: blur(1px);
  display: none; align-items: flex-start; justify-content: center; z-index: 1000; padding: 40px 16px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 12px; width: 100%; max-width: 780px; max-height: 85vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 1.02rem; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.pdf-hit { padding: 14px 0; border-bottom: 1px solid var(--border-soft); }
.pdf-hit:last-child { border-bottom: none; }
.pdf-hit h4 { margin: 0 0 4px; font-size: .95rem; }
.pdf-hit .snippet { font-size: .87rem; color: #333; line-height: 1.55; }
.spinner-row { text-align: center; color: var(--muted); padding: 34px 0; }

/* ================= Search results checkboxes ================= */
.add-report-cell { text-align: center; width: 46px; }
.add-report-cell input { width: 18px; height: 18px; accent-color: var(--navy-mid); }

/* ================= Pagination ================= */
.pagination { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: .85rem; }
.pagination a:hover { background: var(--bg); text-decoration: none; }
.pagination .current { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }

/* ================= Print report layout ================= */
.report-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.report-fields-picker { display: flex; gap: 18px; flex-wrap: wrap; }

.print-sheet {
  background: #fff; max-width: 900px; margin: 0 auto; padding: 30px 34px;
  border: 1px solid var(--border-soft); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.print-sheet h1.report-title { text-align: center; font-size: 1.35rem; margin-bottom: 4px; }
.print-sheet .report-meta { text-align: center; color: var(--muted); font-size: .8rem; margin-bottom: 22px; }

.case-entry { padding: 12px 0; border-bottom: 1px solid #dde3ec; }
.case-entry:last-child { border-bottom: none; }
.case-entry .case-num { flex: 0 0 auto; font-weight: 700; color: var(--gold); margin-right: 6px; font-family: var(--serif); }
.case-line { display: flex; flex-wrap: nowrap; align-items: baseline; gap: 4px 20px; font-size: .88rem; margin: 3px 0; }
.case-line .field { flex: 1 1 40%; min-width: 0; overflow-wrap: break-word; }
.case-line .field-grow { flex: 1 1 60%; }
.case-line .field:only-child { flex: 0 1 auto; }
.case-line .field b { color: var(--navy); font-weight: 700; }
.short-note-block { margin-top: 5px; font-size: .87rem; }
.short-note-block .sn-title { font-weight: 700; color: var(--navy); display: block; margin-bottom: 2px; }
.short-note-block .sn-text { white-space: pre-wrap; }
.pdf-attached-note { font-size: .78rem; color: var(--muted); margin-top: 3px; }

/* ================= Print media ================= */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .page-wrap { max-width: none; padding: 0; margin: 0; }
  .print-sheet { border: none; padding: 0; max-width: none; box-shadow: none; }
  .case-entry { break-inside: avoid; padding: 6px 0; }
  .case-line, .short-note-block { font-size: 10.5pt; }
  .case-entry .case-num { font-size: 10.5pt; }
  a { color: inherit; text-decoration: none; }
  @page { margin: 14mm 12mm; }
}

/* ================= Misc ================= */
.empty-state { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty-state-icon { font-size: 2.2rem; display: block; margin-bottom: 10px; opacity: .7; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: #fff; border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm); display: flex; align-items: center; gap: 14px;
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
  background: linear-gradient(135deg, var(--info-bg), #dbe8fb); color: var(--navy);
}
.stat-card .num { font-size: 1.9rem; font-weight: 700; color: var(--navy); line-height: 1; font-family: var(--serif); }
.stat-card .label { color: var(--muted); font-size: .82rem; margin-top: 3px; }

/* ================= Case view page ================= */
.view-case-card { max-width: 820px; }
.view-party { margin: 0 0 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border-soft); font-size: 1.4rem; }
.view-fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 28px; margin-bottom: 20px; }
.view-field { display: flex; flex-direction: column; gap: 3px; }
.view-field-wide { grid-column: 1 / -1; }
.vf-label { font-size: .73rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.vf-value { font-size: .98rem; color: var(--text); }
.view-short-note { margin: 22px 0; padding-top: 18px; border-top: 1px solid var(--border-soft); }
.view-short-note h3 { margin: 0 0 8px; font-size: .95rem; color: var(--navy); }
.view-note-text { white-space: pre-wrap; line-height: 1.65; }
.view-pdf-row { display: flex; align-items: center; gap: 12px; margin: 22px 0; padding: 15px 16px; background: var(--bg); border-radius: var(--radius); flex-wrap: wrap; }
.view-report-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-soft); flex-wrap: wrap; }
.view-meta { margin: 16px 0 0; font-size: .8rem; }

.role-badge {
  display: inline-block; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px; padding: 1px 9px; font-size: .7rem; margin-left: 4px; vertical-align: middle;
}
.party-link { font-weight: 600; color: var(--navy-mid); }
.party-link:hover { text-decoration: underline; }
.row-actions { white-space: nowrap; }

.role-pill { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.role-pill-associate { background: var(--info-bg); color: var(--info); }
.role-pill-senior_associate { background: #fdf1dc; color: #8a5a10; }
.role-pill-admin { background: var(--danger-bg); color: #9a2c22; }
.btn-link-danger { background: none; border: none; padding: 0; color: var(--danger); cursor: pointer; font-size: .9rem; text-decoration: underline; }
.btn-link-danger:hover { color: #8f1f18; }

/* ================= Auth pages (login / setup) ================= */
.auth-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: radial-gradient(circle at 20% 15%, var(--navy-mid) 0%, var(--navy) 45%, var(--navy-dark) 100%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 34px 32px; position: relative;
}
.auth-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--gold), var(--gold-light)); border-radius: 14px 14px 0 0;
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; text-align: center; }
.auth-brand .brand-mark { width: 46px; height: 46px; border-radius: 12px; font-size: 1.5rem; }
.auth-brand h1 { font-size: 1.25rem; margin: 0; }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: .95rem; }
