:root {
  --ink: #16231f;
  --muted: #64716c;
  --line: #dce4e0;
  --surface: #ffffff;
  --surface-soft: #f5f8f6;
  --green: #165c49;
  --green-dark: #0d4435;
  --green-pale: #e5f2ed;
  --blue-pale: #eaf1f7;
  --amber-pale: #fff2d7;
  --purple-pale: #f1eafa;
  --danger: #a53a3a;
  --shadow: 0 18px 50px rgba(21, 50, 40, 0.09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #eef3f0;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: #f7f9f8; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.13em;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  background: var(--green);
  color: white;
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
}

.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; font-size: 1.15rem; }

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 32px;
  background:
    radial-gradient(circle at 15% 15%, rgba(61, 132, 107, 0.17), transparent 30%),
    linear-gradient(135deg, #0e3229 0%, #164d3e 48%, #eef4f1 48%, #f7f9f8 100%);
}

.login-shell {
  display: grid;
  width: min(100%, 1020px);
  min-height: 600px;
  grid-template-columns: 1.12fr 0.88fr;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.45);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 28px 90px rgba(6, 31, 24, 0.25);
}

.login-brand {
  padding: 64px;
  background: linear-gradient(145deg, #123b30, #0c2e26);
  color: white;
}

.login-brand .brand-mark { margin-bottom: 68px; background: white; color: var(--green-dark); }
.login-brand .eyebrow { color: #9fd0bf; }
.login-brand h1 { margin: 0 0 22px; font-family: Georgia, serif; font-size: clamp(2.4rem, 5vw, 4rem); font-weight: 500; }
.login-intro { max-width: 520px; margin: 0; color: #d7e6e0; font-size: 1.08rem; line-height: 1.7; }
.trust-list { display: grid; gap: 14px; margin: 58px 0 0; padding: 0; list-style: none; color: #cce1d9; }
.trust-list li::before { content: "✓"; margin-right: 11px; color: #8dc8b4; font-weight: 700; }

.login-card { align-self: center; padding: 64px 54px; }
.login-card h2 { margin: 0 0 34px; font-family: Georgia, serif; font-size: 2.1rem; font-weight: 500; }
.login-card form { display: grid; gap: 10px; }
.login-card label { margin-top: 10px; color: #39453f; font-size: 0.86rem; font-weight: 700; }
.login-card input {
  width: 100%;
  padding: 14px 15px;
  border: 1px solid #cbd7d1;
  border-radius: 10px;
  background: #fbfcfb;
  outline: none;
}
.login-card input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,92,73,0.12); }
.primary-button {
  border: 0;
  border-radius: 10px;
  padding: 14px 20px;
  background: var(--green);
  color: white;
  font-weight: 750;
  box-shadow: 0 8px 22px rgba(22,92,73,0.2);
}
.primary-button:hover { background: var(--green-dark); }
.primary-button:focus-visible, .quiet-button:focus-visible, .icon-button:focus-visible, .example-query:focus-visible, .result-action:focus-visible {
  outline: 3px solid rgba(43, 119, 92, 0.35);
  outline-offset: 2px;
}
.login-card .primary-button { margin-top: 22px; }
.form-error { margin: 8px 0 0; color: var(--danger); font-size: 0.9rem; }
.login-footnote { margin: 34px 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1.5; }
.setup-notice { padding: 18px; border: 1px solid #ecd5a5; border-radius: 12px; background: var(--amber-pale); line-height: 1.5; }
.setup-notice p { margin: 8px 0 0; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 0 4vw;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(12px);
}
.app-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.app-brand strong { display: block; font-family: Georgia, serif; font-size: 1.08rem; }
.app-brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.67rem; text-transform: uppercase; letter-spacing: 0.08em; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.quiet-button, .icon-button {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  background: white;
  color: #42504a;
}
.quiet-button:hover { background: var(--surface-soft); }
.user-chip { padding: 8px 11px; border-radius: 999px; background: var(--green-pale); color: var(--green-dark); font-size: 0.8rem; font-weight: 700; }

.app-main { width: min(100% - 40px, 1280px); margin: 0 auto; padding: 62px 0 90px; }
.search-hero { max-width: 1010px; margin: 0 auto; text-align: center; }
.search-hero h1 { max-width: 820px; margin: 0 auto 15px; font-family: Georgia, serif; font-size: clamp(2.25rem, 5vw, 4.1rem); font-weight: 500; line-height: 1.08; letter-spacing: -0.025em; }
.search-hero > p:not(.eyebrow) { max-width: 720px; margin: 0 auto; color: var(--muted); line-height: 1.65; }
.search-form { margin-top: 36px; padding: 12px; border: 1px solid #cfdbd5; border-radius: 17px; background: white; box-shadow: var(--shadow); text-align: left; }
.search-input-row { display: grid; grid-template-columns: 1fr auto; align-items: stretch; gap: 10px; }
.search-input-row textarea { resize: vertical; min-height: 66px; max-height: 190px; padding: 14px 15px; border: 0; outline: none; color: var(--ink); line-height: 1.5; }
.search-input-row textarea::placeholder { color: #8b9691; }
.search-submit { align-self: stretch; min-width: 150px; }
.search-options { display: flex; align-items: center; gap: 10px; padding: 10px 4px 1px; border-top: 1px solid #edf1ef; color: var(--muted); font-size: 0.8rem; }
.search-options label { font-weight: 700; color: #46524d; }
.search-options select { max-width: 290px; padding: 7px 28px 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: white; color: #35413c; }
.search-policy { margin-left: auto; }
.example-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin-top: 18px; color: var(--muted); font-size: 0.78rem; }
.example-query { border: 1px solid var(--line); border-radius: 999px; padding: 7px 10px; background: white; color: #4d5a54; }
.example-query:hover { border-color: #a9bcb3; color: var(--green); }

.search-state { min-height: 32px; margin: 34px auto 0; text-align: center; color: var(--muted); }
.loading-line { display: inline-flex; align-items: center; gap: 10px; }
.spinner { width: 17px; height: 17px; border: 2px solid #bed0c8; border-top-color: var(--green); border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.state-error, .state-empty { max-width: 720px; margin: 0 auto; padding: 18px; border-radius: 12px; }
.state-error { background: #fbecec; color: #8c3232; }
.state-empty { background: var(--surface-soft); color: #4f5d57; }

.results-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 28px; margin-top: 34px; align-items: start; }
.results-main { min-width: 0; }
.results-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.results-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }
.count-badge { padding: 7px 11px; border-radius: 999px; background: var(--green-pale); color: var(--green-dark); font-size: 0.78rem; font-weight: 750; }
.policy-note { margin-bottom: 14px; padding: 12px 14px; border-left: 3px solid #82a99a; background: #eef5f2; color: #4c5b55; font-size: 0.82rem; line-height: 1.5; }
.result-list { display: grid; gap: 13px; }
.result-card { padding: 21px 22px; border: 1px solid var(--line); border-radius: 15px; background: white; box-shadow: 0 6px 22px rgba(25,55,44,0.045); }
.result-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-bottom: 11px; }
.source-badge { padding: 5px 8px; border-radius: 6px; font-size: 0.67rem; font-weight: 800; letter-spacing: 0.055em; }
.source-badge.legal { background: var(--green-pale); color: #0f5a43; }
.source-badge.court { background: var(--blue-pale); color: #2d587b; }
.source-badge.material { background: var(--amber-pale); color: #805c12; }
.source-badge.guidance { background: var(--purple-pale); color: #63458a; }
.result-topic { color: var(--muted); font-size: 0.75rem; }
.result-card h3 { margin: 0 0 7px; font-family: Georgia, serif; font-size: 1.23rem; font-weight: 600; line-height: 1.35; }
.citation-line { margin: 0 0 13px; color: #52605a; font-size: 0.82rem; font-weight: 650; }
.result-snippet { display: -webkit-box; overflow: hidden; margin: 0; color: #35423d; font-family: Georgia, serif; font-size: 0.98rem; line-height: 1.65; -webkit-box-orient: vertical; -webkit-line-clamp: 5; }
.result-snippet.expanded { display: block; }
.result-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-top: 17px; padding-top: 13px; border-top: 1px solid #edf1ef; }
.result-facts { color: var(--muted); font-size: 0.72rem; }
.result-actions { display: flex; gap: 8px; }
.result-action { border: 0; padding: 7px 0; background: transparent; color: var(--green); font-size: 0.77rem; font-weight: 750; text-decoration: none; }
.result-action + .result-action { padding-left: 10px; border-left: 1px solid var(--line); }
.result-aside { position: sticky; top: 96px; display: grid; gap: 13px; }
.aside-card { padding: 19px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.aside-card h3 { margin: 0 0 15px; font-family: Georgia, serif; font-size: 1.05rem; }
.legend-list { display: grid; gap: 14px; margin: 0; }
.legend-list div { display: grid; gap: 3px; }
.legend-list dt { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; font-weight: 750; }
.legend-list dd { margin: 0 0 0 17px; color: var(--muted); font-size: 0.7rem; line-height: 1.4; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.legend-dot.court { background: #4d7da1; }
.legend-dot.material { background: #d29b2c; }
.legend-dot.guidance { background: #8061a8; }
.caution-card { background: #fbfaf6; }
.caution-card p { margin: 0; color: #625d50; font-size: 0.76rem; line-height: 1.55; }

.status-panel {
  position: fixed;
  z-index: 50;
  top: 0;
  right: 0;
  width: min(92vw, 430px);
  height: 100vh;
  overflow-y: auto;
  padding: 30px;
  border-left: 1px solid var(--line);
  background: white;
  box-shadow: -18px 0 60px rgba(18,47,37,0.16);
}
.status-header { display: flex; align-items: start; justify-content: space-between; }
.status-header h2 { margin: 0; font-family: Georgia, serif; font-size: 1.7rem; }
.icon-button { width: 38px; height: 38px; padding: 0; font-size: 1.5rem; }
.panel-backdrop { position: fixed; z-index: 40; inset: 0; background: rgba(9,31,24,0.28); backdrop-filter: blur(2px); }
.status-content { display: grid; gap: 12px; margin-top: 28px; }
.status-metric { padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.status-metric span { display: block; color: var(--muted); font-size: 0.72rem; }
.status-metric strong { display: block; margin-top: 5px; font-size: 1rem; }

@media (max-width: 850px) {
  .login-body { padding: 0; background: #f7f9f8; }
  .login-shell { grid-template-columns: 1fr; min-height: 100vh; border-radius: 0; }
  .login-brand { padding: 38px 28px; }
  .login-brand .brand-mark { margin-bottom: 30px; }
  .trust-list { margin-top: 28px; }
  .login-card { padding: 42px 28px; }
  .results-layout { grid-template-columns: 1fr; }
  .result-aside { position: static; grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 620px) {
  .app-header { padding: 0 15px; }
  .user-chip { display: none; }
  .quiet-button { padding: 8px; font-size: 0.74rem; }
  .app-main { width: min(100% - 24px, 1280px); padding-top: 38px; }
  .search-hero h1 { font-size: 2.35rem; }
  .search-input-row { grid-template-columns: 1fr; }
  .search-submit { min-height: 48px; }
  .search-options { align-items: stretch; flex-direction: column; }
  .search-policy { margin-left: 0; }
  .example-row > span { width: 100%; }
  .results-heading { align-items: start; }
  .result-card { padding: 18px; }
  .result-footer { align-items: start; flex-direction: column; }
  .result-aside { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; }
}
