/* ═══════════════════════════════════════════════════════════════════
   AJLO Counsel — brand system
   Fir green #014B41 · rendered surface #144139 · Gold #D6B455
   Secondaries: #3F7450 #298787 #9FBD96 #DFEAB8 #D0B665 #FFD37B
   Type: Cairo (UI) · Amiri (accents)
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --fir: #014B41;
  --fir-surface: #144139;      /* matches the brand-sheet render → PNGs blend */
  --fir-deep: #0C332C;
  --fir-2: #3F7450;
  --teal: #298787;
  --sage: #9FBD96;
  --mist: #DFEAB8;
  --gold: #D6B455;
  --gold-2: #D0B665;
  --gold-soft: #FFD37B;
  --ivory: #F7F5EF;
  --paper: #FFFFFF;
  --ink: #1C2B27;
  --ink-soft: #5A6B65;
  --line: #E4E0D4;
  --shadow: 0 10px 34px rgba(1, 75, 65, 0.10);
  --radius: 14px;
  --arch: 18px 18px 18px 4px;  /* the brand leaf-arch corner */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: 'Cairo', 'Segoe UI', sans-serif;
  background: var(--ivory);
  color: var(--ink);
  overflow: hidden;
}

.hidden { display: none !important; }

/* Leaf-arch tile used as watermark on green surfaces */
.sidebar-pattern, .gate-pattern {
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='84' viewBox='0 0 56 84'%3E%3Cpath d='M8 6 h22 a18 18 0 0 1 18 18 v48 a6 6 0 0 1 -6 6 h-28 a6 6 0 0 1 -6 -6 z' fill='none' stroke='%239FBD96' stroke-opacity='0.045' stroke-width='1.2'/%3E%3C/svg%3E");
  background-size: 56px 84px;
  pointer-events: none;
  /* keep the motif as a whisper at the top, gone behind the content below */
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), rgba(0,0,0,.35) 45%, transparent 80%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.9), rgba(0,0,0,.35) 45%, transparent 80%);
}

/* ═══════════ Access gate ═══════════ */
.gate {
  position: fixed; inset: 0; z-index: 50;
  background:
    radial-gradient(1100px 700px at 78% -10%, rgba(214,180,85,0.14), transparent 60%),
    radial-gradient(900px 700px at 8% 108%, rgba(41,135,135,0.20), transparent 55%),
    linear-gradient(160deg, var(--fir-surface), var(--fir-deep));
  display: grid; place-items: center;
}

.gate-card {
  position: relative;
  width: min(430px, 92vw);
  text-align: center;
  padding: 54px 44px 44px;
  border: 1px solid rgba(214, 180, 85, 0.35);
  border-radius: var(--arch);
  background: var(--fir-surface);
  box-shadow: 0 30px 80px rgba(0,0,0,0.35);
  animation: rise .7s cubic-bezier(.2,.8,.2,1);
}

.gate-logo { width: 170px; display: block; margin: 0 auto 8px; }
.gate-slogan { width: 190px; display: block; margin: 0 auto 26px; opacity: .95; }

.gate-note { color: var(--mist); font-size: 13.5px; margin-bottom: 22px; font-weight: 300; }

#gateForm { display: flex; gap: 10px; }

#gateCode {
  flex: 1; padding: 13px 16px;
  border-radius: 10px;
  border: 1px solid rgba(159, 189, 150, 0.4);
  background: rgba(1, 75, 65, 0.45);
  color: #fff; font-family: inherit; font-size: 15px;
  letter-spacing: 2px; text-align: center;
  outline: none; transition: border-color .2s;
}
#gateCode:focus { border-color: var(--gold); }
#gateCode::placeholder { letter-spacing: 0; color: rgba(223, 234, 184, 0.5); }

#gateForm button {
  padding: 13px 26px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  color: var(--fir-deep); font-family: inherit; font-weight: 700; font-size: 15px;
  cursor: pointer; transition: transform .15s, box-shadow .2s;
}
#gateForm button:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(214,180,85,.35); }

.gate-error { color: #F3B0A0; font-size: 13px; margin-top: 14px; }

/* ═══════════ App shell ═══════════ */
.app {
  display: grid;
  grid-template-columns: 322px 1fr;
  height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
  position: relative;
  background: linear-gradient(175deg, var(--fir-surface) 55%, var(--fir-deep));
  color: var(--mist);
  overflow: hidden;
}

.sidebar-inner {
  position: relative; z-index: 1;
  height: 100%;
  display: flex; flex-direction: column;
  padding: 26px 20px 18px;
}

.brand-logo { width: 132px; display: block; margin: 0 auto 24px; }

.btn-new {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 12px;
  border: 1px solid rgba(214, 180, 85, 0.55);
  border-radius: var(--arch);
  background: transparent; color: var(--gold);
  font-family: inherit; font-size: 14.5px; font-weight: 700;
  cursor: pointer; transition: background .2s, color .2s;
}
.btn-new:hover { background: var(--gold); color: var(--fir-deep); }

.modes { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }

.mode {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 14px;
  border: 1px solid transparent; border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--mist); font-family: inherit; text-align: start;
  cursor: pointer; transition: background .2s, border-color .2s;
}
.mode:hover { background: rgba(255, 255, 255, 0.09); }
.mode.active {
  background: rgba(214, 180, 85, 0.13);
  border-color: rgba(214, 180, 85, 0.5);
}
.mode-ic { font-size: 19px; filter: grayscale(.2); }
.mode-txt { display: flex; flex-direction: column; line-height: 1.5; }
.mode-txt b { font-size: 14px; color: #fff; font-weight: 700; }
.mode.active .mode-txt b { color: var(--gold-soft); }
.mode-txt small { font-size: 11.5px; color: var(--sage); font-weight: 300; }

/* Case scope panel */
.case-panel { margin-top: 16px; }
.case-panel-title {
  font-size: 11px; letter-spacing: .12em; color: var(--sage);
  margin-bottom: 8px; font-weight: 600;
}
.case-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }

.case-item {
  padding: 10px 12px;
  border: 1px solid rgba(159, 189, 150, 0.18);
  border-radius: 10px;
  background: rgba(1, 75, 65, 0.35);
  cursor: pointer; transition: border-color .2s, background .2s;
}
.case-item:hover { border-color: rgba(214, 180, 85, 0.45); }
.case-item.active { border-color: var(--gold); background: rgba(214, 180, 85, 0.12); }
.case-item .ci-title { font-size: 12.5px; font-weight: 700; color: #fff; line-height: 1.45; }
.case-item.active .ci-title { color: var(--gold-soft); }
.case-item .ci-meta { font-size: 11px; color: var(--sage); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.ci-badge {
  display: inline-block; font-size: 9.5px; padding: 1px 7px;
  border-radius: 20px; background: var(--teal); color: #fff; font-weight: 600;
}

/* History */
.history { flex: 1; margin-top: 20px; overflow-y: auto; min-height: 40px; }
.history-title {
  font-size: 11px; letter-spacing: .12em; color: var(--sage);
  margin-bottom: 8px; font-weight: 600;
}
.hist-item {
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
  font-size: 12.5px; color: var(--mist);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .15s;
}
.hist-item:hover { background: rgba(255,255,255,0.07); }
.hist-item.active { background: rgba(214,180,85,0.12); color: var(--gold-soft); }

.sidebar-foot { margin-top: 14px; text-align: center; }
.foot-slogan {
  width: 128px; display: block; margin: 0 auto 10px;
  background: var(--fir-surface);
  padding: 10px 16px;
  border: 1px solid rgba(214, 180, 85, 0.22);
  border-radius: var(--arch);
}

.lang-toggle {
  border: 1px solid rgba(159, 189, 150, 0.35); border-radius: 20px;
  background: transparent; color: var(--sage);
  padding: 5px 18px; font-family: inherit; font-size: 12px; cursor: pointer;
  transition: color .2s, border-color .2s;
}
.lang-toggle:hover { color: var(--gold); border-color: var(--gold); }

/* ─── Main column ─── */
.main { display: flex; flex-direction: column; height: 100vh; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 34px;
  background: rgba(247, 245, 239, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.topbar-ctx { display: flex; align-items: center; gap: 14px; }
.topbar h1 { font-size: 17px; font-weight: 900; color: var(--fir); }

.ctx-chip {
  font-size: 11.5px; font-weight: 600; color: var(--fir);
  background: var(--mist); border: 1px solid var(--sage);
  padding: 3px 12px; border-radius: 20px;
  max-width: 380px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-right { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-soft); }
.model-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px rgba(41, 135, 135, 0.18);
}
.model-dot.busy { background: var(--gold); box-shadow: 0 0 0 3px rgba(214, 180, 85, 0.25); animation: pulse 1.2s infinite; }

@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(214, 180, 85, 0.12); } }

/* ─── Thread ─── */
.thread {
  flex: 1; overflow-y: auto;
  padding: 34px 0 20px;
  scroll-behavior: smooth;
}

/* Hero / empty state */
.hero {
  max-width: 720px; margin: 6vh auto 0; text-align: center; padding: 0 28px;
  animation: rise .8s cubic-bezier(.2,.8,.2,1);
}
.hero-slogan {
  width: 220px; margin-bottom: 26px;
  background: var(--fir-surface);
  padding: 18px 26px; border-radius: var(--arch);
  box-shadow: var(--shadow);
}
.hero h2 { font-size: 27px; font-weight: 900; color: var(--fir); margin-bottom: 8px; }
.hero p { font-size: 14.5px; color: var(--ink-soft); font-weight: 300; max-width: 520px; margin: 0 auto 34px; line-height: 1.9; }

.starters {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: start;
}
.starter {
  padding: 15px 17px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--arch);
  font-size: 13px; line-height: 1.8; color: var(--ink);
  cursor: pointer; transition: transform .18s, box-shadow .2s, border-color .2s;
}
.starter:hover {
  transform: translateY(-2px);
  border-color: var(--gold-2);
  box-shadow: var(--shadow);
}
.starter .st-k {
  display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  color: var(--teal); margin-bottom: 3px;
}

/* Messages */
.msg { max-width: 780px; margin: 0 auto 22px; padding: 0 34px; display: flex; gap: 14px; animation: rise .35s ease; }

.msg .avatar {
  flex: 0 0 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 900;
}
.msg.user .avatar { background: var(--fir); color: var(--gold-soft); }
.msg.bot .avatar { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: var(--fir-deep); }

.msg .bubble { flex: 1; min-width: 0; }

.msg.user .bubble {
  background: var(--fir);
  color: #F4F8F0;
  padding: 13px 18px;
  border-radius: var(--arch);
  font-size: 14.5px; line-height: 2;
  width: fit-content; max-width: 100%;
}

.msg.bot .bubble {
  background: var(--paper);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 14.5px; line-height: 2.05;
  box-shadow: 0 3px 14px rgba(1, 75, 65, 0.05);
}

.bubble h3 { font-size: 15px; color: var(--fir); margin: 12px 0 4px; font-weight: 900; }
.bubble h4 { font-size: 14px; color: var(--fir-2); margin: 10px 0 3px; font-weight: 700; }
.bubble p { margin: 7px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-inline-start: 22px; }
.bubble li { margin: 3px 0; }
.bubble strong { color: var(--fir); }

.tbl-wrap { overflow-x: auto; margin: 10px 0; }
.bubble table { border-collapse: collapse; width: 100%; font-size: 13px; }
.bubble th {
  background: var(--fir); color: var(--gold-soft);
  padding: 7px 12px; text-align: start; font-weight: 700; white-space: nowrap;
}
.bubble th:first-child { border-start-start-radius: 10px; }
.bubble th:last-child { border-start-end-radius: 10px; }
.bubble td { padding: 7px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.bubble tbody tr:nth-child(even) { background: rgba(159, 189, 150, 0.09); }

/* Citation chips: statutes & articles glow gold */
.cite {
  display: inline-block;
  background: linear-gradient(135deg, rgba(214,180,85,.16), rgba(255,211,123,.22));
  border: 1px solid rgba(208, 182, 101, 0.55);
  border-radius: 7px;
  padding: 0 7px;
  font-weight: 700; color: #7A5F1D;
  font-size: 0.93em;
}

/* Streaming cursor */
.cursor {
  display: inline-block; width: 8px; height: 17px;
  background: var(--gold); border-radius: 2px;
  vertical-align: text-bottom;
  animation: blink .85s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* thinking shimmer */
.thinking { display: inline-flex; gap: 5px; align-items: center; padding: 4px 0; }
.thinking i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold-2); animation: hop 1.1s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes hop { 40% { transform: translateY(-5px); opacity: .5; } }

.msg-tools { margin-top: 8px; display: flex; gap: 8px; }
.msg-tools button {
  border: 1px solid var(--line); border-radius: 7px; background: transparent;
  color: var(--ink-soft); font-family: inherit; font-size: 11px;
  padding: 3px 10px; cursor: pointer; transition: color .2s, border-color .2s;
}
.msg-tools button:hover { color: var(--fir); border-color: var(--sage); }

.err-note {
  color: #A33B25; background: #FBEDE8; border: 1px solid #EFCFC5;
  border-radius: 10px; padding: 10px 14px; font-size: 13px;
}

/* ─── Composer ─── */
.composer-wrap { padding: 10px 34px 16px; background: linear-gradient(transparent, var(--ivory) 30%); }

.domain-chips {
  max-width: 780px; margin: 0 auto 9px;
  display: flex; gap: 7px; flex-wrap: wrap;
}
.dchip {
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--paper); color: var(--ink-soft);
  padding: 4px 14px; font-family: inherit; font-size: 11.5px; font-weight: 600;
  cursor: pointer; transition: all .18s;
}
.dchip:hover { border-color: var(--gold-2); color: var(--fir); }
.dchip.active {
  background: var(--fir); border-color: var(--fir); color: var(--gold-soft);
}

.sources {
  margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line);
  font-size: 11px; color: var(--ink-soft);
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.sources .src {
  background: var(--mist); border: 1px solid var(--sage);
  color: var(--fir); border-radius: 14px; padding: 1px 10px; font-weight: 600;
}

.composer {
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--arch);
  padding: 10px 12px;
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--gold-2); box-shadow: 0 6px 24px rgba(214, 180, 85, 0.14); }

#input {
  flex: 1; border: none; outline: none; resize: none;
  font-family: inherit; font-size: 14.5px; line-height: 1.9;
  max-height: 180px; background: transparent; color: var(--ink);
}

.send {
  flex: 0 0 42px; height: 42px;
  border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--fir), var(--fir-2));
  color: var(--gold-soft); cursor: pointer;
  display: grid; place-items: center;
  transition: transform .15s, box-shadow .2s, opacity .2s;
}
.send svg { transform: scaleX(-1); }        /* point into RTL reading direction */
[dir="ltr"] .send svg { transform: none; }
.send:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(1, 75, 65, 0.3); }
.send:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }

.disclaimer {
  max-width: 780px; margin: 9px auto 0;
  text-align: center; font-size: 11px; color: #97917F; font-weight: 300;
}

/* ─── Scrollbars & misc ─── */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb { background: rgba(1, 75, 65, 0.18); border-radius: 5px; }
.sidebar ::-webkit-scrollbar-thumb { background: rgba(159, 189, 150, 0.25); }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* LTR (English) adjustments */
[dir="ltr"] body, [dir="ltr"] { font-family: 'Cairo', 'Segoe UI', sans-serif; }

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .starters { grid-template-columns: 1fr; }
}
