/* ============================================================
   CACTUS CHAT — Design tokens & base styles
   Lima Amorim & Advogados Associados
   ============================================================ */

:root {
  /* Brand greens */
  --green-900: #16200C;
  --green-800: #1E2A12;
  --green-700: #2B3616;   /* PRIMARY — topbar, sidebar, buttons */
  --green-600: #3A4A1E;
  --green-500: #5A6E2A;   /* highlight / active / links */
  --green-400: #7BA05B;   /* accent — cactus, details */
  --green-200: #C7D3A8;
  --green-100: #E8EDD8;   /* light highlight — sent bubble, hover */
  --green-50:  #F1F4E7;

  --gold:      #B8924A;   /* premium / selos */
  --gold-soft: #EBDCC0;

  /* Status */
  --st-open:    #C2683A;  /* Aberto — terracota */
  --st-active:  #3A6B5E;  /* Em atendimento — azul-petróleo */
  --st-wait:    #D9A84E;  /* Aguardando — âmbar */
  --st-done:    #5A6E2A;  /* Resolvido — verde */

  /* Neutrals (LIGHT theme defaults) */
  --bg:         #F5F6F2;
  --bg-sunken:  #ECEEE6;
  --surface:    #FFFFFF;
  --surface-2:  #FAFBF7;
  --surface-3:  #F1F2EC;
  --border:     #E3E5DC;
  --border-soft:#EDEEE7;
  --text:       #1F2417;
  --text-2:     #6B7280;
  --text-3:     #9AA08F;
  --on-green:   #F3F5EC;
  --on-green-2: #B9C4A0;

  --note-bg:    #FBF3CF;
  --note-border:#F0E3A8;

  /* Chat canvas texture */
  --chat-bg:    #ECEAE0;

  /* Geometry */
  --r-sm: 6px;
  --r:    8px;
  --r-lg: 12px;
  --r-xl: 18px;
  --shadow-sm: 0 1px 2px rgba(31,36,23,.06), 0 1px 3px rgba(31,36,23,.04);
  --shadow:    0 2px 8px rgba(31,36,23,.07), 0 1px 2px rgba(31,36,23,.05);
  --shadow-lg: 0 12px 32px rgba(31,36,23,.16), 0 4px 12px rgba(31,36,23,.10);
  --shadow-pop: 0 8px 28px rgba(22,32,12,.22);

  --font-title: "Playfair Display", Georgia, serif;
  --font-body:  "Lato", system-ui, -apple-system, sans-serif;

  --sidebar-w: 64px;
  --topbar-h: 56px;
  --list-w: 364px;
  --contact-w: 366px;
}

[data-theme="dark"] {
  --bg:         #11160B;
  --bg-sunken:  #0C1107;
  --surface:    #1A2113;
  --surface-2:  #1F2717;
  --surface-3:  #232C1A;
  --border:     #2E3A20;
  --border-soft:#283320;
  --text:       #ECEFE3;
  --text-2:     #A6B091;
  --text-3:     #79835F;
  --on-green:   #F3F5EC;
  --on-green-2: #B9C4A0;
  --green-700:  #233012;
  --green-100:  #2C3A1A;   /* sent bubble dark */
  --green-50:   #1E2713;
  --surface-bubble-in: #20281800;
  --note-bg:    #3A3413;
  --note-border:#544C1C;
  --chat-bg:    #141A0D;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow:    0 2px 10px rgba(0,0,0,.45);
  --shadow-lg: 0 14px 36px rgba(0,0,0,.6);
  --shadow-pop: 0 8px 28px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
#root { height: 100%; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(120,130,100,.32); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120,130,100,.5); }
::-webkit-scrollbar-track { background: transparent; }

h1,h2,h3,h4 { font-family: var(--font-title); font-weight: 700; margin: 0; color: var(--text); }
.serif { font-family: var(--font-title); }

/* ---------- App shell ---------- */
.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.app-body { flex: 1; display: flex; min-height: 0; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--green-700);
  color: var(--on-green);
  display: flex; align-items: center;
  padding: 0 16px 0 14px;
  gap: 14px;
  flex-shrink: 0;
  z-index: 40;
  box-shadow: 0 1px 0 rgba(0,0,0,.12);
}
.topbar .tb-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar .tb-user .name { font-weight: 700; font-size: 13.5px; line-height: 1.1; }
.topbar .tb-user .org { font-size: 11.5px; color: var(--on-green-2); }
.topbar .tb-sep { width: 1px; height: 26px; background: rgba(255,255,255,.14); }
.topbar .tb-spacer { flex: 1; }
.tb-icons { display: flex; align-items: center; gap: 2px; }
.tb-btn {
  width: 36px; height: 36px; border-radius: 8px; border: none; background: transparent;
  color: var(--on-green); display: grid; place-items: center; position: relative;
  transition: background .15s;
}
.tb-btn:hover { background: rgba(255,255,255,.12); }
.tb-btn .caret { margin-left: 1px; opacity: .7; }
.tb-dot {
  position: absolute; top: 6px; right: 7px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--st-open); border: 1.5px solid var(--green-700);
}
.tb-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
  border-radius: 999px; background: rgba(255,255,255,.1); font-size: 12px; font-weight: 700;
}

/* ---------- Narrow sidebar ---------- */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--green-700);
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 0; position: relative; z-index: 35;
}
.sb-logo {
  width: 42px; height: 42px; border-radius: 11px; margin-bottom: 10px;
  display: grid; place-items: center; flex-shrink: 0;
}
.sb-scroll { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; overflow: visible; }
.sb-item {
  width: 44px; height: 44px; border-radius: 11px; border: none; background: transparent;
  color: var(--on-green-2); display: grid; place-items: center; position: relative;
  transition: background .15s, color .15s;
}
.sb-item:hover { background: rgba(255,255,255,.1); color: var(--on-green); }
.sb-item.active { background: var(--green-100); color: var(--green-700); }
[data-theme="dark"] .sb-item.active { background: var(--green-400); color: var(--green-900); }
.sb-item.active::before {
  content: ""; position: absolute; left: -10px; top: 11px; bottom: 11px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--green-400);
}
.sb-spacer { flex: 1; }
/* flyout */
.sb-flyout {
  position: absolute; left: calc(var(--sidebar-w) - 2px); white-space: nowrap;
  background: var(--green-800); color: var(--on-green);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-pop); transform: translateX(-6px); opacity: 0;
  pointer-events: none; transition: opacity .14s, transform .14s; z-index: 60;
}
.sb-item:hover .sb-flyout, .sb-itemwrap:hover .sb-flyout { opacity: 1; transform: translateX(0); }
.sb-itemwrap { position: relative; }
.sb-submenu {
  position: absolute; left: calc(var(--sidebar-w) - 2px); top: -6px;
  background: var(--green-800); color: var(--on-green); border-radius: 12px;
  padding: 8px; min-width: 232px; box-shadow: var(--shadow-pop);
  opacity: 0; pointer-events: none; transform: translateX(-6px); transition: opacity .14s, transform .14s; z-index: 60;
}
.sb-itemwrap:hover .sb-submenu { opacity: 1; pointer-events: auto; transform: translateX(0); }
.sb-submenu .sm-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--on-green-2); padding: 4px 10px 7px; }
.sb-submenu a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--on-green); text-decoration: none; font-size: 13px; font-weight: 600;
}
.sb-submenu a:hover { background: rgba(255,255,255,.1); }

/* ---------- Generic buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--r); padding: 9px 15px;
  font-size: 13px; font-weight: 700; line-height: 1; transition: filter .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--green-700); color: var(--on-green); }
.btn-primary:hover { filter: brightness(1.12); }
.btn-accent { background: var(--green-500); color: #fff; }
.btn-accent:hover { filter: brightness(1.08); }
.btn-gold { background: var(--gold); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-soft { background: var(--green-100); color: var(--green-700); }
[data-theme="dark"] .btn-soft { color: var(--green-400); }
.btn-soft:hover { filter: brightness(.97); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: var(--r-sm); }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.btn-block { width: 100%; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 12px; font-weight: 700; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 9px 12px; color: var(--text); font-size: 13px;
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--green-400); box-shadow: 0 0 0 3px rgba(123,160,91,.18); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.textarea { resize: none; }
.input-search { position: relative; }
.input-search .input { padding-left: 34px; }
.input-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

/* ---------- Badges / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 800; letter-spacing: .01em; line-height: 1.4; white-space: nowrap;
}
.badge .bdot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-open   { color: var(--st-open);   background: color-mix(in srgb, var(--st-open) 14%, transparent); }
.badge-active { color: var(--st-active); background: color-mix(in srgb, var(--st-active) 15%, transparent); }
.badge-wait   { color: #b1842f;          background: color-mix(in srgb, var(--st-wait) 22%, transparent); }
.badge-done   { color: var(--st-done);   background: color-mix(in srgb, var(--st-done) 15%, transparent); }
[data-theme="dark"] .badge-open   { color: #e89368; }
[data-theme="dark"] .badge-active { color: #66b3a0; }
[data-theme="dark"] .badge-wait   { color: #e3bf6e; }
[data-theme="dark"] .badge-done   { color: #9bbb5e; }

/* tag chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 6px;
  font-size: 11.5px; font-weight: 700; line-height: 1.3;
}
.chip .x { opacity: .55; cursor: pointer; display: inline-flex; }
.chip .x:hover { opacity: 1; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px; }

/* ---------- Avatars ---------- */
.av { border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-weight: 800; color: #fff; overflow: hidden; }
.av img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Misc layout helpers ---------- */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap6 { gap: 6px; } .gap8 { gap: 8px; } .gap10 { gap: 10px; } .gap12 { gap: 12px; } .gap16 { gap: 16px; }
.spacer { flex: 1; }
.muted { color: var(--text-2); }
.tiny { font-size: 11.5px; }
.scroll-y { overflow-y: auto; min-height: 0; }
.divider { height: 1px; background: var(--border); }

/* fade-in for route changes — transform-only so content can never be trapped invisible
   (inactive iframes freeze animations at t=0; opacity:0 there would hide content) */
@keyframes routeIn { from { transform: translateY(8px); } }
.route-anim { animation: routeIn .28s ease; }
@media (prefers-reduced-motion: reduce) { .route-anim { animation: none; } }
