/* Cadência — design system derivado de docs/design.md
   Banda teal profunda + pílula verde. Cards 12px, botões pill. */

:root {
    --brand-green: #00ed64;
    --brand-green-dark: #00684a;
    --brand-green-mid: #00a35c;
    --brand-green-soft: #c3f4d7;

    --brand-teal-deep: #001e2b;
    --brand-teal: #023430;
    --brand-teal-mid: #112733;

    --accent-purple: #5e4db2;
    --accent-orange: #c2571a;
    --accent-blue: #016bf8;
    --accent-amber: #f9a825;

    --canvas: #ffffff;
    --canvas-dark: #001e2b;
    --surface: #f9fbfa;
    --surface-soft: #f1f5f4;
    --surface-feature: #e3fcf7;

    --hairline: #e8edeb;
    --hairline-soft: #f1f5f4;
    --hairline-strong: #c1c7c6;
    --hairline-dark: #2c3f4b;

    --ink: #001e2b;
    --charcoal: #1c2d38;
    --slate: #3d4f58;
    --steel: #5c6c75;
    --stone: #889397;
    --muted: #b8c4c2;
    --on-dark: #ffffff;
    --on-dark-muted: rgba(255, 255, 255, 0.62);
    --on-dark-faint: rgba(255, 255, 255, 0.34);

    --warning-bg: #ffec9e;
    --warning-text: #944f01;
    --danger: #db3030;
    --danger-soft: #fdeceb;

    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    --shadow-1: rgba(0, 30, 43, 0.04) 0 1px 2px 0;
    --shadow-2: rgba(0, 30, 43, 0.08) 0 4px 12px 0;
    --shadow-3: rgba(0, 30, 43, 0.12) 0 12px 24px -4px;
    --shadow-4: rgba(0, 30, 43, 0.16) 0 16px 48px -8px;

    --font: "Euclid Circular A", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "Source Code Pro", "SF Mono", Menlo, Consolas, monospace;

    --sidebar-width: 250px;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-green-dark); text-decoration: none; }
h1, h2, h3, h4, h5 { margin: 0 0 8px; font-weight: 500; letter-spacing: -0.4px; line-height: 1.2; }
h1 { font-size: 30px; letter-spacing: -0.8px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }
p { margin: 0 0 12px; }
small, .small { font-size: 13px; }
.muted { color: var(--steel); }
.mono { font-family: var(--font-mono); font-size: 13px; }
.ico { flex: 0 0 auto; }

.eyebrow {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--steel);
    margin-bottom: 2px;
}

/* ── Shell ─────────────────────────────────────────────── */

/* Altura travada no viewport: quem rola são as áreas internas, nunca a página.
   É o que dá ao inbox o comportamento de aplicativo em vez de documento. */
.shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

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

/* Páginas comuns rolam aqui dentro; o inbox entrega o scroll às colunas. */
.content { flex: 1; min-height: 0; overflow-y: auto; padding: 28px 32px; max-width: 1280px; width: 100%; }
.content.wide { max-width: none; padding: 0; overflow: hidden; display: flex; flex-direction: column; }

/* ── Sidebar ───────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--brand-teal-deep);
    color: var(--on-dark);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px 12px 12px;
}

.is-master .sidebar {
    background: #000d14;
    box-shadow: inset -1px 0 0 rgba(249, 168, 37, 0.28);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 8px 16px;
}

.brand-mark {
    width: 26px; height: 26px;
    border-radius: var(--radius-sm);
    background: var(--brand-green);
    color: var(--ink);
    display: grid; place-items: center;
    font-weight: 700; font-size: 15px;
}

.brand-name { font-size: 16px; font-weight: 600; letter-spacing: -0.3px; }

.brand-tag {
    margin-left: auto;
    font-size: 10px; font-weight: 700; letter-spacing: 1px;
    color: var(--accent-amber);
    border: 1px solid rgba(249, 168, 37, 0.45);
    border-radius: var(--radius-xs);
    padding: 1px 5px;
}

/* Seletor de conta */

.workspace { position: relative; margin-bottom: 14px; }

.workspace-btn {
    width: 100%;
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: var(--on-dark);
    font-family: var(--font);
    cursor: pointer;
    text-align: left;
}

.workspace-btn:hover { background: rgba(255, 255, 255, 0.12); }
.is-master .workspace-btn { border-color: rgba(249, 168, 37, 0.4); }

.workspace-avatar {
    width: 30px; height: 30px; flex: 0 0 30px;
    border-radius: var(--radius-sm);
    background: var(--brand-green-soft);
    color: var(--brand-green-dark);
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px;
    text-transform: uppercase;
}

.workspace-avatar.master { background: var(--accent-amber); color: #3a2600; }
.workspace-avatar.small { width: 22px; height: 22px; flex: 0 0 22px; font-size: 11px; border-radius: var(--radius-xs); }

.workspace-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.workspace-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--on-dark-faint); }
.workspace-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workspace-caret { margin-left: auto; color: var(--on-dark-faint); }

.workspace-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: var(--canvas);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-4);
    padding: 6px;
    z-index: 60;
}

.workspace-menu-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
    color: var(--stone); padding: 6px 8px 4px;
}

.workspace-menu-sep { height: 1px; background: var(--hairline); margin: 6px 4px; }

.workspace-option {
    width: 100%;
    display: flex; align-items: center; gap: 8px;
    padding: 8px;
    border: none; background: transparent;
    border-radius: var(--radius-md);
    font-family: var(--font); font-size: 14px;
    color: var(--ink); cursor: pointer; text-align: left;
}

.workspace-option:hover { background: var(--surface-soft); }
.workspace-option.current { background: var(--surface-feature); font-weight: 600; }
.workspace-option-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workspace-check { color: var(--brand-green-mid); font-weight: 700; }
.workspace-empty { padding: 10px 8px; font-size: 13px; color: var(--steel); }

/* Navegação */

.nav { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }

.nav-section {
    margin: 18px 0 6px;
    padding: 0 10px 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--on-dark-faint);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    cursor: default;
}

.nav-section:first-child { margin-top: 4px; }

.nav-item {
    position: relative;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px;
    margin-bottom: 1px;
    border-radius: var(--radius-md);
    color: var(--on-dark-muted);
    font-size: 14px;
    line-height: 1.3;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: var(--on-dark); }
.nav-item .ico { color: var(--on-dark-faint); }
.nav-item:hover .ico { color: var(--on-dark-muted); }

.nav-item.active { background: rgba(0, 237, 100, 0.13); color: var(--on-dark); font-weight: 600; }
.nav-item.active .ico { color: var(--brand-green); }
.nav-item.active::before {
    content: "";
    position: absolute; left: -4px; top: 8px; bottom: 8px;
    width: 3px; border-radius: var(--radius-full);
    background: var(--brand-green);
}

.is-master .nav-item.active { background: rgba(249, 168, 37, 0.16); }
.is-master .nav-item.active::before { background: var(--accent-amber); }
.is-master .nav-item.active .ico { color: var(--accent-amber); }

.nav-badge {
    margin-left: auto;
    min-width: 20px; text-align: center;
    background: var(--brand-green);
    color: var(--ink);
    font-size: 11px; font-weight: 700;
    border-radius: var(--radius-full);
    padding: 1px 6px;
}

.nav-badge.quiet { background: rgba(255, 255, 255, 0.14); color: var(--on-dark-muted); }

.sidebar-foot {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 8px 2px;
    margin-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.sidebar-user { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.sidebar-user-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-user-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--on-dark-faint); }

.sidebar-logout {
    background: transparent; border: none; cursor: pointer;
    color: var(--on-dark-faint); padding: 6px; border-radius: var(--radius-sm);
    display: grid; place-items: center;
}
.sidebar-logout:hover { background: rgba(255, 255, 255, 0.09); color: var(--on-dark); }

/* ── Faixas de contexto ────────────────────────────────── */

.ribbon {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 9px 32px;
    font-size: 13px;
    flex-wrap: wrap;
}

.ribbon .inline { gap: 8px; }
.ribbon.danger { background: var(--danger); color: #fff; }
.ribbon.master { background: #1d1503; color: #ffdf99; border-bottom: 1px solid rgba(249, 168, 37, 0.3); }
.ribbon.tenant { background: var(--surface-feature); color: var(--brand-green-dark); border-bottom: 1px solid var(--hairline); }

.ribbon-btn {
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid currentColor;
    color: inherit;
    font: inherit; font-weight: 600; font-size: 12px;
    border-radius: var(--radius-full);
    padding: 4px 12px; cursor: pointer;
    white-space: nowrap;
}
.ribbon.tenant .ribbon-btn { background: transparent; }
.ribbon-btn:hover { filter: brightness(1.1); }

/* ── Cabeçalho de página ───────────────────────────────── */

.page-head, .header-row {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 20px; flex-wrap: wrap;
    margin-bottom: 22px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--hairline);
}

.page-head-text { min-width: 0; }
.page-head h1 { margin-bottom: 4px; }
.page-head-desc { color: var(--steel); font-size: 14px; margin: 0; max-width: 62ch; }
.page-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Linha título+ações dentro de card */
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }

/* Abas entre páginas irmãs */

.subnav {
    display: flex; gap: 4px; flex-wrap: wrap;
    margin: -8px 0 22px;
    border-bottom: 1px solid var(--hairline);
}

.subnav-item {
    padding: 8px 14px;
    font-size: 14px; font-weight: 500;
    color: var(--steel);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    display: inline-flex; align-items: center; gap: 6px;
}

.subnav-item:hover { color: var(--ink); }
.subnav-item.active { color: var(--brand-green-dark); border-bottom-color: var(--brand-green-dark); font-weight: 600; }
.subnav-count { background: var(--surface-soft); border-radius: var(--radius-full); padding: 0 7px; font-size: 12px; color: var(--steel); }

/* ── Botões ────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font-family: var(--font); font-size: 14px; font-weight: 600; line-height: 1.3;
    padding: 10px 22px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    cursor: pointer;
    background: var(--brand-green);
    color: var(--ink);
    transition: filter 160ms ease;
}

.btn:hover { filter: brightness(0.94); }
.btn[disabled] { background: var(--hairline); color: var(--stone); cursor: not-allowed; filter: none; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--hairline-strong); }
.btn.secondary:hover { background: var(--surface-soft); filter: none; }
.btn.ghost { background: transparent; color: var(--slate); border-radius: var(--radius-md); padding: 8px 12px; }
.btn.ghost:hover { background: var(--surface-soft); filter: none; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { font-size: 13px; padding: 6px 14px; }
.btn.block { width: 100%; }

.link { background: none; border: none; padding: 0; font: inherit; color: var(--brand-green-dark); cursor: pointer; font-weight: 500; font-size: 14px; }
.link:hover { text-decoration: underline; }

/* ── Cards ─────────────────────────────────────────────── */

.card {
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.card.feature { padding: 28px; }
.card.dark { background: var(--brand-teal-deep); color: var(--on-dark); border-color: transparent; }
.card.featured { background: var(--surface-feature); border: 2px solid var(--brand-green); }
.card + .card { margin-top: 16px; }
.card h3 { margin-bottom: 10px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat { font-size: 30px; font-weight: 500; letter-spacing: -1px; line-height: 1.15; }
.stat.small { font-size: 22px; }

/* ── Formulários ───────────────────────────────────────── */

label, .label { display: block; font-size: 13px; font-weight: 600; color: var(--charcoal); margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--steel); margin-top: 4px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="search"], select, textarea {
    width: 100%;
    background: var(--canvas);
    color: var(--ink);
    border: 1px solid var(--hairline-strong);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-family: var(--font);
    font-size: 14px;
    min-height: 44px;
}

textarea { min-height: 96px; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border: 2px solid var(--brand-green-dark); padding: 9px 11px; }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 160px; }
.row.tight > * { flex: 0 0 auto; min-width: 0; }
.inline { display: flex; gap: 8px; align-items: center; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 8px; }
.checkline input { width: auto; min-height: 0; }

/* ── Badges ────────────────────────────────────────────── */

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 12px; font-weight: 600;
    border-radius: var(--radius-full);
    padding: 3px 10px;
    background: var(--surface-soft);
    color: var(--slate);
    white-space: nowrap;
}

.badge.green { background: var(--brand-green); color: var(--ink); }
.badge.green-soft { background: var(--brand-green-soft); color: var(--brand-green-dark); }
.badge.dark { background: var(--brand-teal-deep); color: var(--brand-green); }
.badge.warning { background: var(--warning-bg); color: var(--warning-text); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.purple { background: var(--accent-purple); color: #fff; border-radius: var(--radius-xs); }
.badge.orange { background: var(--accent-orange); color: #fff; border-radius: var(--radius-xs); }
.badge.tiny { font-size: 10px; padding: 1px 6px; }

.dot-state { width: 8px; height: 8px; border-radius: var(--radius-full); display: inline-block; background: var(--muted); }
.dot-state.open { background: var(--brand-green-mid); }
.dot-state.closed { background: var(--danger); }
.dot-state.connecting, .dot-state\.qr-code { background: var(--accent-orange); }

/* ── Tabelas ───────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border: 1px solid var(--hairline); border-radius: var(--radius-lg); background: var(--canvas); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--steel); padding: 11px 14px; border-bottom: 1px solid var(--hairline); font-weight: 700; background: var(--surface); }
td { padding: 12px 14px; border-bottom: 1px solid var(--hairline-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: var(--surface); cursor: pointer; }

/* ── Abas internas (filtros) ───────────────────────────── */

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
    font-size: 13px; padding: 6px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--hairline);
    color: var(--steel); background: var(--canvas); cursor: pointer;
    font-family: var(--font);
}
.tab:hover { border-color: var(--hairline-strong); color: var(--ink); }
.tab.active { background: var(--ink); color: var(--on-dark); border-color: var(--ink); font-weight: 600; }

/* ── Inbox ─────────────────────────────────────────────── */

.inbox { display: grid; grid-template-columns: 310px minmax(0, 1fr) 300px; flex: 1; min-height: 0; height: 100%; overflow: hidden; }
.inbox .col { border-right: 1px solid var(--hairline); background: var(--canvas); display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.inbox .col:last-child { border-right: none; }
.inbox .scroll { overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; }
.inbox .col > .pad { flex: 0 0 auto; }
.inbox .pad { padding: 14px; }

.conv-item { padding: 12px 14px; border-bottom: 1px solid var(--hairline-soft); cursor: pointer; display: block; border-left: 3px solid transparent; }
.conv-item:hover { background: var(--surface); }
.conv-item.active { background: var(--surface-feature); border-left-color: var(--brand-green); }
.conv-item .title { font-weight: 600; font-size: 14px; color: var(--ink); }
.conv-item .preview { font-size: 13px; color: var(--steel); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.thread { background: var(--surface); padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 68%; padding: 10px 14px; border-radius: var(--radius-lg); font-size: 14px; box-shadow: var(--shadow-1); white-space: pre-wrap; word-wrap: break-word; }
.bubble.out { align-self: flex-end; background: var(--brand-green-soft); color: var(--ink); }
.bubble.in { align-self: flex-start; background: var(--canvas); border: 1px solid var(--hairline); }
.bubble.system { align-self: center; background: var(--warning-bg); color: var(--warning-text); font-size: 13px; max-width: 82%; text-align: center; }
.bubble .meta { font-size: 11px; color: var(--steel); margin-top: 6px; display: flex; gap: 8px; }

.composer { border-top: 1px solid var(--hairline); padding: 12px 14px; background: var(--canvas); }
.composer .paused { background: var(--warning-bg); color: var(--warning-text); border-radius: var(--radius-md); padding: 10px 12px; margin-bottom: 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ── Diversos ──────────────────────────────────────────── */

.flash { padding: 12px 16px; border-radius: var(--radius-md); margin-bottom: 18px; font-size: 14px; }
.flash.ok { background: var(--brand-green-soft); color: var(--brand-green-dark); }
.flash.err { background: var(--danger-soft); color: var(--danger); }

.checklist { margin: 0; padding: 0; }
.checklist li { list-style: none; padding: 9px 0; border-bottom: 1px solid var(--hairline-soft); display: flex; gap: 10px; align-items: center; font-size: 14px; }
.check-ok { color: var(--brand-green-mid); font-weight: 700; }
.check-no { color: var(--danger); font-weight: 700; }

.code {
    background: var(--canvas-dark);
    color: var(--on-dark);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: 13px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.spin-track { display: flex; gap: 4px; margin: 6px 0 2px; }
.spin-step { height: 6px; flex: 1; border-radius: var(--radius-full); background: var(--hairline); }
.spin-step.on { background: var(--brand-green-mid); }

.auth { min-height: 100vh; display: grid; place-items: center; background: var(--brand-teal-deep); padding: 24px; }
.auth .card { width: 100%; max-width: 380px; }

/* ── Responsivo ────────────────────────────────────────── */

@media (max-width: 1100px) {
    .inbox { grid-template-columns: 270px minmax(0, 1fr); }
    .inbox .col.lead-panel { display: none; }
    .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
    .shell { flex-direction: column; height: auto; overflow: visible; }
    .content, .content.wide { overflow: visible; }
    .inbox { height: auto; overflow: visible; }
    .inbox .col { overflow: visible; }
    .inbox .scroll { max-height: 70vh; }
    .sidebar { width: 100%; flex: none; height: auto; position: static; padding-bottom: 12px; }
    .nav { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 8px; }
    .nav-section { grid-column: 1 / -1; margin-top: 12px; }
    .main { min-height: 0; }
    .content { padding: 20px 16px; }
    .ribbon { padding: 9px 16px; }
    .inbox { grid-template-columns: 1fr; }
    .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

/* ── Estado do tempo real ──────────────────────────────── */

.rt-badge {
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    padding: 7px 16px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-3);
}

.rt-badge.warn { background: var(--warning-bg); color: var(--warning-text); }
.rt-badge.err { background: var(--danger); color: #fff; }
