:root {
  --bg: #0a0a0b;
  --bg-panel: #17171b;
  --bg-sunken: #1f1f24;
  --bg-elevated: #1c1c21;
  --ink: #f5f5f7;
  --ink-soft: #a3a3ad;
  --ink-faint: #6b6b76;
  --accent: #ff2f7e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(255, 47, 126, 0.14);
  --rule: rgba(255, 255, 255, 0.08);
  --rule-soft: rgba(255, 255, 255, 0.05);
  --shadow: rgba(0, 0, 0, 0.5);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --sidebar-w: 248px;

  /* Gradientes grafite/preto — superfícies com profundidade, estilo PRESET BOS */
  --graphite-panel: linear-gradient(160deg, #232328 0%, #17171b 45%, #0c0c0e 100%);
  --graphite-elevated: linear-gradient(160deg, #29292f 0%, #1c1c21 45%, #0e0e10 100%);
  --graphite-sunken: linear-gradient(160deg, #1a1a1f 0%, #121215 100%);
  --graphite-sidebar: linear-gradient(190deg, #131316 0%, #0a0a0c 55%, #050506 100%);
  --graphite-hero: radial-gradient(120% 140% at 0% 0%, #2a2a30 0%, #16161a 45%, #060607 100%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(70% 60% at 15% 0%, rgba(255, 255, 255, 0.05), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
::selection { background: var(--accent-soft); color: var(--ink); }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(60% 50% at 15% 10%, rgba(255, 47, 126, 0.10), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--graphite-panel);
  border: 1px solid var(--rule);
  border-radius: 18px;
  padding: 2.25rem 2rem;
  box-shadow: 0 30px 60px -30px var(--shadow);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 1.75rem;
}
.login-brand-badge {
  width: 38px; height: 38px; border-radius: 10px;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem; color: #0a0a0b; flex-shrink: 0;
}
.login-brand-text { line-height: 1.25; }
.login-brand-text .name { font-weight: 800; font-size: 1.02rem; letter-spacing: -0.01em; }
.login-brand-text .sub { font-size: 0.72rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.login-sub {
  color: var(--ink-soft);
  font-size: 0.88rem;
  margin: 0 0 1.6rem;
}
label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}
input[type="email"], input[type="password"], input[type="text"], input[type="date"], input[type="number"], input[type="search"] {
  width: 100%;
  padding: 0.68rem 0.85rem;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--bg-sunken);
  color: var(--ink);
  font-size: 0.92rem;
  margin-bottom: 1.1rem;
  font-family: inherit;
}
input::placeholder { color: var(--ink-faint); }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary {
  width: 100%;
  padding: 0.72rem;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: filter 0.15s;
}
button.primary:hover { filter: brightness(1.1); }
.form-error {
  color: var(--danger);
  font-size: 0.83rem;
  margin: -0.6rem 0 0.9rem;
  min-height: 1em;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--graphite-sidebar);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1.3rem 1.2rem 1.1rem;
  border-bottom: 1px solid var(--rule-soft);
}
.sidebar-brand-badge {
  width: 34px; height: 34px; border-radius: 9px;
  background: #fff;
  color: #0a0a0b;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.95rem; flex-shrink: 0;
}
.sidebar-brand-text .name { font-weight: 800; font-size: 0.9rem; letter-spacing: -0.01em; }
.sidebar-brand-text .name sup { color: #fff; font-size: 0.6rem; opacity: 0.7; }
.sidebar-brand-text .sub { font-size: 0.66rem; color: var(--ink-faint); }

.sidebar-nav { padding: 0.9rem; display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  border: none; background: transparent; color: var(--ink-soft);
  font-weight: 600; font-size: 0.87rem;
  padding: 0.6rem 0.75rem; border-radius: 9px; cursor: pointer;
  text-align: left; width: 100%;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--bg-elevated); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.active svg { opacity: 1; }
.nav-badge {
  margin-left: auto;
  background: var(--accent); color: #fff; font-size: 0.68rem; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.nav-badge[hidden] { display: none; }

.sidebar-footer { padding: 0.9rem; border-top: 1px solid var(--rule-soft); }
.user-card { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.3rem 0.7rem; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: var(--bg-elevated); border: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.78rem; color: var(--ink); flex-shrink: 0;
}
.user-meta { line-height: 1.3; overflow: hidden; }
.user-name { font-size: 0.82rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--ink-faint); }
.logout-btn {
  width: 100%; border: 1px solid var(--rule); background: transparent; color: var(--ink-soft);
  font-size: 0.8rem; font-weight: 600; padding: 0.5rem; border-radius: 8px; cursor: pointer;
}
.logout-btn:hover { color: var(--ink); border-color: var(--ink-faint); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 10;
  background: rgba(10, 10, 11, 0.85);
  backdrop-filter: blur(10px);
}
.search-box {
  flex: 1; max-width: 380px;
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--graphite-sunken); border: 1px solid var(--rule);
  border-radius: 9px; padding: 0.5rem 0.8rem;
}
.search-box svg { width: 15px; height: 15px; color: var(--ink-faint); flex-shrink: 0; }
.search-box input {
  border: none; background: transparent; margin: 0; padding: 0;
  color: var(--ink); font-size: 0.85rem; width: 100%;
}
.search-box input:focus { outline: none; }
.topbar-spacer { flex: 1; }
.icon-btn {
  position: relative;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--rule); background: var(--bg-panel);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--ink-soft);
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-badge {
  position: absolute; top: -5px; right: -5px;
  background: var(--accent); color: #fff; font-size: 0.62rem; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
  border: 2px solid #0a0a0b;
}
.icon-badge[hidden] { display: none; }

.content { flex: 1; padding: 1.6rem 1.75rem 2.5rem; max-width: 1400px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.page-head { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1.4rem; }
.page-badge {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.15rem; flex-shrink: 0;
}
.page-head h1 { margin: 0; font-size: 1.4rem; font-weight: 800; letter-spacing: -0.01em; }
.page-head p { margin: 0.15rem 0 0; color: var(--ink-soft); font-size: 0.85rem; }

/* ---------- KPI cards ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}
.kpi-card {
  background: var(--graphite-panel); border: 1px solid var(--rule); border-radius: 14px;
  padding: 1.1rem 1.2rem;
}
.kpi-label { font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 0.55rem; }
.kpi-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; }
.kpi-value.accent { color: var(--accent); }

/* ---------- Kanban ---------- */
.board-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}
.scope-toggle { display: flex; background: var(--graphite-sunken); border: 1px solid var(--rule); border-radius: 9px; padding: 3px; }
.scope-toggle button {
  border: none; background: transparent; padding: 0.4rem 0.85rem; border-radius: 6px;
  font-size: 0.83rem; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.scope-toggle button.active { background: var(--bg-elevated); color: var(--ink); }

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 1rem;
}
.column {
  background: var(--graphite-panel);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 0.9rem;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.column-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0 0.2rem 0.2rem;
}
.column-head .count {
  background: var(--bg-sunken);
  border-radius: 999px;
  padding: 0.08rem 0.5rem;
  font-size: 0.7rem;
  color: var(--ink-faint);
}
.column.drag-over { outline: 2px dashed var(--accent); outline-offset: -4px; }
.column.flash { animation: flash-column 1s ease; }
@keyframes flash-column {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 0 2px var(--accent); }
}

.card {
  background: var(--graphite-elevated);
  border: 1px solid var(--rule-soft);
  border-radius: 11px;
  padding: 0.75rem 0.8rem;
  cursor: grab;
}
.card:hover { border-color: var(--rule); }
.card:active { cursor: grabbing; }
.card.hidden { display: none; }
.card-name { font-weight: 700; font-size: 0.9rem; margin-bottom: 0.15rem; }
.card-meta { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.4rem; }
.pill {
  font-size: 0.68rem; font-weight: 700; padding: 0.12rem 0.5rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.pill.birthday { background: var(--ok-soft); color: var(--ok); }
.card-preview {
  font-size: 0.8rem; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-time { font-size: 0.7rem; color: var(--ink-faint); margin-top: 0.4rem; }
.empty-hint { color: var(--ink-faint); font-size: 0.83rem; text-align: center; padding: 1rem 0; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--graphite-panel); border: 1px solid var(--rule); border-radius: 16px; max-width: 480px; width: 100%;
  max-height: 82vh; display: flex; flex-direction: column; box-shadow: 0 30px 60px -20px var(--shadow);
}
.modal-head { padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 1rem; }
.modal-close { border: none; background: none; font-size: 1.2rem; color: var(--ink-faint); cursor: pointer; }
.modal-close:hover { color: var(--ink); }
.modal-slots { padding: 0.9rem 1.3rem; border-bottom: 1px solid var(--rule); font-size: 0.82rem; color: var(--ink-soft); display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 1rem; }
.modal-thread { padding: 1rem 1.3rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.55rem; }
.msg { max-width: 82%; padding: 0.5rem 0.75rem; border-radius: 12px; font-size: 0.87rem; }
.msg.user { background: var(--bg-sunken); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.assistant { background: var(--accent-soft); color: var(--ink); align-self: flex-end; border-bottom-right-radius: 3px; }
.msg.human { background: var(--ok-soft); color: var(--ink); align-self: flex-end; border-bottom-right-radius: 3px; }

/* ---------- Mensagens (WhatsApp Web style) ---------- */
.messages-layout {
  display: flex;
  height: calc(100vh - 148px);
  min-height: 420px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  overflow: hidden;
  background: var(--graphite-panel);
}

.conv-list-panel {
  width: 320px; flex-shrink: 0;
  border-right: 1px solid var(--rule);
  display: flex; flex-direction: column;
  min-height: 0;
}
.conv-list-search {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.8rem;
  border-bottom: 1px solid var(--rule);
}
.conv-list-search svg { width: 15px; height: 15px; color: var(--ink-faint); flex-shrink: 0; }
.conv-list-search input { border: none; background: var(--bg-sunken); margin: 0; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.75rem 0.9rem; cursor: pointer;
  border-bottom: 1px solid var(--rule-soft);
}
.conv-row:hover { background: var(--bg-elevated); }
.conv-row.active { background: var(--accent-soft); }
.conv-row.hidden { display: none; }
.conv-avatar {
  width: 40px; height: 40px; border-radius: 999px; flex-shrink: 0;
  background: var(--bg-elevated); border: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; color: var(--ink-soft);
}
.conv-row-body { min-width: 0; flex: 1; }
.conv-row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.conv-row-name { font-weight: 700; font-size: 0.87rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-row-time { font-size: 0.68rem; color: var(--ink-faint); flex-shrink: 0; }
.conv-row-preview {
  font-size: 0.79rem; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 0.3rem;
}
.conv-row-manual-dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--ok); flex-shrink: 0;
}
.conv-list-empty { padding: 2rem 1rem; text-align: center; color: var(--ink-faint); font-size: 0.85rem; }

.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.8rem; color: var(--ink-faint);
}
.chat-empty svg { width: 42px; height: 42px; opacity: 0.5; }
.chat-empty p { margin: 0; font-size: 0.88rem; }
.chat-empty[hidden] { display: none; }
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-active[hidden] { display: none; }

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--rule);
}
.chat-head-name { font-weight: 700; font-size: 0.95rem; }
.chat-head-sub { font-size: 0.76rem; color: var(--ink-soft); margin-top: 0.1rem; }
.chat-takeover-btn {
  border: 1px solid var(--rule); background: var(--bg-elevated); color: var(--ink-soft);
  font-size: 0.78rem; font-weight: 700; padding: 0.4rem 0.8rem; border-radius: 8px; cursor: pointer;
  white-space: nowrap;
}
.chat-takeover-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.chat-takeover-btn.manual { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

.chat-thread {
  flex: 1; overflow-y: auto; padding: 1.1rem; display: flex; flex-direction: column; gap: 0.6rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.02), transparent 40%),
    radial-gradient(circle at 80% 60%, rgba(255, 255, 255, 0.02), transparent 40%);
}
.chat-thread .msg { max-width: 68%; }
.chat-thread .msg-label { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; opacity: 0.7; margin-bottom: 0.15rem; }
.chat-thread .msg-time { font-size: 0.65rem; opacity: 0.55; margin-top: 0.25rem; }

.chat-error { color: var(--danger); font-size: 0.78rem; margin: 0; padding: 0 1.1rem; min-height: 0; }
.chat-error:empty { display: none; }

.chat-compose {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.8rem 1.1rem; border-top: 1px solid var(--rule);
}
.chat-compose input {
  flex: 1; margin: 0; background: var(--bg-sunken);
}
.chat-send-btn {
  width: 38px; height: 38px; border-radius: 999px; flex-shrink: 0;
  border: none; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.chat-send-btn:hover { filter: brightness(1.1); }
.chat-send-btn svg { width: 16px; height: 16px; }

@media (max-width: 980px) {
  .messages-layout { flex-direction: column; height: auto; }
  .conv-list-panel { width: 100%; max-height: 260px; border-right: none; border-bottom: 1px solid var(--rule); }
  .chat-panel { min-height: 420px; }
}

/* ---------- Eventos ---------- */
.events-layout { display: grid; grid-template-columns: 340px 1fr; gap: 1.5rem; align-items: start; }
.panel-card {
  background: var(--graphite-panel); border: 1px solid var(--rule); border-radius: 14px; padding: 1.3rem;
}
.panel-card h2 { margin: 0 0 1rem; font-size: 0.98rem; }
.event-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 0.8rem;
  padding: 0.85rem 0; border-top: 1px solid var(--rule-soft);
}
.event-row:first-child { border-top: none; padding-top: 0; }
.event-name { font-weight: 700; font-size: 0.92rem; }
.event-detail { font-size: 0.8rem; color: var(--ink-soft); margin-top: 0.15rem; }
.event-date { font-size: 0.76rem; font-weight: 700; color: var(--accent); text-transform: uppercase; }
.row-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.row-actions button {
  border: none; background: none; cursor: pointer; font-size: 0.78rem; color: var(--ink-faint);
}
.row-actions button:hover { color: var(--ink); }
.row-actions button.danger:hover { color: var(--danger); }

#sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 980px) {
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 35;
  }
  .app-shell { display: block; }
  #sidebar-toggle { display: flex; }
  .board { grid-template-columns: 1fr; }
  .events-layout { grid-template-columns: 1fr; }
  .search-box { max-width: none; }
}
