/* ============================================================
   TheBeSync — Painel · Design System (Fase 10)
   Tema claro (default) + escuro via :root[data-theme="dark"]
   ============================================================ */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e9ecf1;
  --border: #e7e9ee;
  --border-2: #dce0e7;
  --text: #1a1d23;
  --text-2: #606a78;
  --text-3: #9aa3af;
  --accent: #6d4aff;
  --accent-2: #5a37e0;
  --accent-soft: #efeaff;
  --success: #12a150;
  --success-soft: #e3f6ec;
  --warning: #c2740b;
  --warning-soft: #fdf0dc;
  --danger: #dc2626;
  --danger-soft: #fdeaea;
  --info: #2563eb;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-pop: 0 8px 28px rgba(16, 24, 40, .14);
  --sidebar-w: 232px;
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Syne', var(--font-ui);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1015;
    --surface: #161a21;
    --surface-2: #1c212a;
    --surface-3: #232a35;
    --border: #262c37;
    --border-2: #313947;
    --text: #e6e8ec;
    --text-2: #98a2af;
    --text-3: #5f6b78;
    --accent: #8b6dff;
    --accent-2: #7857f5;
    --accent-soft: rgba(139, 109, 255, .15);
    --success: #3ddc6e;
    --success-soft: rgba(61, 220, 110, .13);
    --warning: #ffc94d;
    --warning-soft: rgba(255, 201, 77, .13);
    --danger: #ff5b5b;
    --danger-soft: rgba(255, 91, 91, .13);
    --info: #5dadff;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, .25);
    --shadow-pop: 0 10px 34px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  --bg: #0e1015;
  --surface: #161a21;
  --surface-2: #1c212a;
  --surface-3: #232a35;
  --border: #262c37;
  --border-2: #313947;
  --text: #e6e8ec;
  --text-2: #98a2af;
  --text-3: #5f6b78;
  --accent: #8b6dff;
  --accent-2: #7857f5;
  --accent-soft: rgba(139, 109, 255, .15);
  --success: #3ddc6e;
  --success-soft: rgba(61, 220, 110, .13);
  --warning: #ffc94d;
  --warning-soft: rgba(255, 201, 77, .13);
  --danger: #ff5b5b;
  --danger-soft: rgba(255, 91, 91, .13);
  --info: #5dadff;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .25);
  --shadow-pop: 0 10px 34px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, .display { font-family: var(--font-display); font-weight: 700; letter-spacing: -.01em; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }

/* ---------- LOGIN ---------- */
#login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 50; padding: 20px;
}
.login-card {
  width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 32px; box-shadow: var(--shadow-card);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.login-brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-family: var(--font-display); }
.login-brand b { font-family: var(--font-display); font-size: 16px; }
.login-brand span { font-size: 12px; color: var(--text-2); display: block; }
.login-card h2 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { font-size: 13px; color: var(--text-2); margin-bottom: 22px; }

/* ---------- SHELL ---------- */
#app { display: none; min-height: 100vh; }
#app.on { display: grid; grid-template-columns: var(--sidebar-w) 1fr; }

.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 14px; }
.sidebar-brand .mark { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-family: var(--font-display); font-size: 13px; }
.sidebar-brand b { font-family: var(--font-display); font-size: 14px; }

.cliente-switch {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; margin-bottom: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
}
.cliente-switch.clicavel { cursor: pointer; }
.cliente-switch.clicavel:hover { border-color: var(--accent); }
.cliente-switch .avatar { width: 22px; height: 22px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 11px; font-weight: 800; flex-shrink: 0; }
.cliente-switch .nome { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cliente-switch .chev { color: var(--text-3); font-size: 11px; }

.nav-grupo { font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; user-select: none;
}
.nav-item .ico { width: 17px; text-align: center; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.ativo { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding-top: 12px; }
.btn-sair { width: 100%; padding: 9px; background: transparent; border: 1px solid var(--border-2); border-radius: var(--radius-sm); color: var(--text-2); font-size: 12px; cursor: pointer; }
.btn-sair:hover { border-color: var(--danger); color: var(--danger); }

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

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 28px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 8;
}
.crumbs { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.crumbs b { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--text-3); }
.topbar .push { margin-left: auto; }
.topbar-acoes { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.user-chip { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; padding: 5px 10px 5px 6px; border: 1px solid var(--border); border-radius: 999px; }
.user-chip .avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 800; }

.view { padding: 26px 28px 60px; max-width: 1160px; width: 100%; }

/* ---------- COMPONENTES ---------- */
.pagina-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.pagina-titulo { font-size: 22px; }
.pagina-sub { font-size: 13px; color: var(--text-2); margin-top: 3px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.card-pad { padding: 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-card); }
.stat .n { font-family: var(--font-display); font-size: 25px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--text-2); margin-top: 3px; }

.tabela-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-card); }
table.tabela { width: 100%; border-collapse: collapse; }
.tabela th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; padding: 11px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.tabela td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.tabela tr:last-child td { border-bottom: none; }
.tabela tbody tr.clicavel { cursor: pointer; }
.tabela tbody tr.clicavel:hover { background: var(--surface-2); }
.tabela tfoot td { padding: 11px 16px; font-weight: 700; border-top: 2px solid var(--border-2); font-size: 13px; }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid transparent; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--success); color: #fff; }
.btn-primary:hover { filter: brightness(.95); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-sm { padding: 6px 11px; font-size: 12px; }

.input, .select, .textarea {
  width: 100%; padding: 9px 12px; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); color: var(--text); font-size: 13px; font-family: inherit; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 80px; }
.campo { margin-bottom: 14px; }
.campo label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }

.filtros { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filtros .busca { position: relative; }
.filtros .busca input { padding-left: 30px; min-width: 240px; }
.filtros .busca::before { content: "🔍"; position: absolute; left: 9px; top: 7px; font-size: 12px; opacity: .5; }
.filtros .select { width: auto; }
.seg-btns { display: inline-flex; border: 1px solid var(--border-2); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btns button { padding: 7px 12px; background: var(--surface); border: none; border-right: 1px solid var(--border-2); color: var(--text-2); font-size: 12px; cursor: pointer; }
.seg-btns button:last-child { border-right: none; }
.seg-btns button.ativo { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.tag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.tag.warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.tag.off { color: var(--text-3); }

.pill-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.warn { background: var(--warning-soft); color: var(--warning); }

/* kanban */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.kb-col { flex: 0 0 268px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 230px); }
.kb-col-h { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; }
.kb-col-h .t { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.kb-col-h .t .dot { width: 8px; height: 8px; border-radius: 50%; }
.kb-col-h .c { font-size: 11px; color: var(--text-2); background: var(--surface); padding: 2px 8px; border-radius: 999px; }
.kb-cards { padding: 0 10px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.kb-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 12px; cursor: pointer; box-shadow: var(--shadow-card); }
.kb-card:hover { border-color: var(--accent); }
.kb-card .top { display: flex; align-items: center; gap: 8px; }
.kb-card .av { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; flex-shrink: 0; }
.kb-card .nome { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-card .fone { font-size: 11px; color: var(--text-2); margin: 4px 0 8px; }
.kb-card .row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kb-card select { width: 100%; margin-top: 8px; padding: 6px 8px; font-size: 11px; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 6px; color: var(--text); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 18, .55); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 20px; }
.modal { width: 440px; max-width: 100%; max-height: 84vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow-pop); }
.modal-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-h h3 { font-size: 16px; }
.modal-sub { font-size: 12px; color: var(--text-2); margin-bottom: 16px; }
.modal-acoes { margin-top: 18px; display: flex; justify-content: flex-end; gap: 8px; }
.x-btn { background: transparent; border: none; color: var(--text-3); font-size: 18px; cursor: pointer; line-height: 1; }
.x-btn:hover { color: var(--text); }

.empty { padding: 44px 20px; text-align: center; color: var(--text-3); font-size: 13px; }

.stars { display: inline-flex; gap: 3px; }
.stars button { background: none; border: none; cursor: pointer; font-size: 17px; line-height: 1; padding: 0; color: var(--text-3); }
.stars button.on, .stars button:hover { color: var(--warning); }

#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border-2); border-left: 3px solid var(--success); padding: 11px 16px; border-radius: var(--radius-sm); font-size: 13px; box-shadow: var(--shadow-pop); max-width: 340px; }
.toast.erro { border-left-color: var(--danger); }

/* charts precisam de altura fixa no container */
.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-card); }

/* ---------- responsivo ---------- */
@media (max-width: 900px) {
  #app.on { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-pop); }
  .sidebar.aberta { transform: none; }
  .sidebar-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 29; }
  .topbar .menu-toggle { display: grid; }
  .view { padding: 18px 16px 50px; }
}
.menu-toggle { display: none; }
