/* ───────────── Tokens ───────────── */
:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --hover: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;

  --text: #18181b;
  --text-2: #52525b;
  --text-3: #a1a1aa;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --accent-text: #1e40af;

  --success: #16a34a;
  --success-soft: #ecfdf3;
  --success-text: #15803d;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --warning-text: #b45309;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-text: #b91c1c;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow: 0 1px 3px rgb(0 0 0 / 0.06), 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.12), 0 2px 6px rgb(0 0 0 / 0.06);

  --sidebar-w: 236px;
  --topbar-h: 48px;
  --drawer-w: 560px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
.lucide { width: 16px; height: 16px; stroke-width: 1.75; flex-shrink: 0; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }

/* ───────────── Layout ───────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; }

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  -webkit-app-region: drag;
}
.sidebar > * { -webkit-app-region: no-drag; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: var(--radius);
  display: grid; place-items: center;
  background: var(--text); color: #fff; font-weight: 600; font-size: 12px; letter-spacing: 0.02em;
}
.brand-name { font-weight: 600; font-size: 14px; }
.brand-sub { font-size: 11.5px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px; font-weight: 500; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--text-2); cursor: pointer; text-decoration: none; user-select: none;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.is-active { background: var(--hover); color: var(--text); font-weight: 500; }
.nav-item.is-active .lucide { color: var(--accent); }
.nav-item.is-disabled { color: var(--text-3); cursor: default; }
.nav-item.is-disabled:hover { background: none; }
.nav-item > span:first-of-type { flex: 1; }
.nav-tag { font-size: 10.5px; color: var(--text-3); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; line-height: 17px; }
.nav-count { font-size: 11.5px; color: var(--text-3); }

.sidebar-footer { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); }
.db-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.db-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.db-status.is-ok .dot { background: var(--success); }
.db-status.is-error .dot { background: var(--danger); }
/* painel web: sessão do administrador no rodapé da barra lateral */
.session-box { display: grid; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.session-last { line-height: 1.35; overflow-wrap: anywhere; }
.session-actions { display: flex; flex-wrap: wrap; gap: 2px; margin-left: -10px; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  display: flex; align-items: center; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
}
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 13px; }
.crumbs strong { color: var(--text); font-weight: 500; }
.content { flex: 1; overflow: auto; }
.page { width: 100%; padding: 20px 20px 32px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-header h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 4px; }

/* ───────────── Buttons ───────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 500; cursor: pointer; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger-text); }
.btn-danger:hover { background: var(--danger-soft); border-color: #fecaca; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #b91c1c; }
.btn-ghost { border-color: transparent; background: none; box-shadow: none; }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center;
  border: 0; background: none; border-radius: var(--radius-sm); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn:disabled { opacity: 0.4; cursor: default; background: none; }

/* ───────────── Stats ───────────── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--text-2); font-size: 12.5px; }
.stat-top .lucide { color: var(--text-3); }
.stat-value { font-size: 22px; font-weight: 600; margin-top: 6px; letter-spacing: -0.01em; }

/* ───────────── Card + toolbar + table ───────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border); }
.search {
  display: flex; align-items: center; gap: 8px; width: 280px; height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-3);
}
.search:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; outline: 0; background: none; flex: 1; color: var(--text); }
.segmented { display: inline-flex; padding: 2px; gap: 2px; background: var(--hover); border-radius: var(--radius); }
.segmented button {
  height: 28px; padding: 0 11px; border: 0; border-radius: var(--radius-sm); background: none;
  color: var(--text-2); font-weight: 500; font-size: 12.5px; cursor: pointer;
}
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--text-2);
  padding: 9px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-selected { background: var(--accent-soft); }
td.actions { width: 1%; white-space: nowrap; text-align: right; }
.cell-account { display: flex; align-items: center; gap: 11px; min-width: 0; }
.cell-account .name { font-weight: 500; }
.cell-account .sub { font-size: 12px; color: var(--text-3); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.with-icon { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.with-icon .lucide { width: 14px; height: 14px; color: var(--text-3); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--hover); color: var(--text-2); border: 1px solid var(--border);
}
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }

/* ───────────── Badges ───────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--hover); color: var(--text-2);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.success { background: var(--success-soft); color: var(--success-text); }
.badge.warning { background: var(--warning-soft); color: var(--warning-text); }
.badge.danger { background: var(--danger-soft); color: var(--danger-text); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.accent::before { display: none; }
.badge .lucide { width: 12px; height: 12px; }

.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── Empty states ───────────── */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 56px 24px; }
.empty-icon {
  width: 44px; height: 44px; border-radius: var(--radius-lg); display: grid; place-items: center;
  background: var(--hover); color: var(--text-2); margin-bottom: 14px;
}
.empty-icon .lucide { width: 20px; height: 20px; }
.empty h3 { font-size: 14.5px; font-weight: 600; margin-bottom: 4px; }
.empty p { color: var(--text-2); max-width: 360px; margin-bottom: 16px; }

/* ───────────── Drawer (side panel) ───────────── */
.drawer-backdrop { position: fixed; inset: 0; background: rgb(24 24 27 / 0.12); opacity: 0; transition: opacity 0.18s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--drawer-w); max-width: 100vw;
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer-root-open .drawer-backdrop { opacity: 1; }
.drawer-root-open .drawer { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 56px 20px 18px; border-bottom: 1px solid var(--border); }
.drawer-head .title { font-size: 15px; font-weight: 600; }
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-body { flex: 1; overflow: auto; padding: 4px 20px 24px; }
.section { padding: 18px 0; border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kv { display: grid; grid-template-columns: 130px 1fr; row-gap: 9px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.callout { display: flex; gap: 10px; padding: 11px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); margin-top: 12px; font-size: 13px; }
.callout .lucide { margin-top: 2px; }
.callout.success { background: var(--success-soft); border-color: #bbf7d0; color: var(--success-text); }
.callout.warning { background: var(--warning-soft); border-color: #fde68a; color: var(--warning-text); }
.callout.danger { background: var(--danger-soft); border-color: #fecaca; color: var(--danger-text); }
.callout.accent { background: var(--accent-soft); border-color: #c7d7fe; color: var(--accent-text); }
.callout .meta { font-size: 12px; opacity: 0.8; margin-top: 2px; }

.note-form textarea { min-height: 84px; resize: vertical; line-height: 1.55; }
.note-form .row { display: flex; justify-content: flex-end; margin-top: 10px; }
.notes { list-style: none; margin: 20px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.note { padding: 12px 14px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.note-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.note-head .meta { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.note-head .meta .lucide { width: 13px; height: 13px; }
.note-head .icon-btn { width: 26px; height: 26px; margin: -4px -6px -4px 0; opacity: 0; transition: opacity 0.12s; }
.note:hover .note-head .icon-btn, .note-head .icon-btn:focus-visible { opacity: 1; }
.note p { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; color: var(--text); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; font-size: 13px; }
.timeline .when { margin-left: auto; color: var(--text-3); font-size: 12px; white-space: nowrap; }
.timeline .msg { color: var(--text-2); font-size: 12px; }

/* ───────────── Forms ───────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 500; }
.field .hint { font-size: 12px; color: var(--text-3); }
.input, textarea.input {
  width: 100%; height: 36px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
  outline: none; transition: border-color 0.12s, box-shadow 0.12s;
}
textarea.input { height: auto; padding: 9px 11px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group { position: relative; }
.input-group .input { padding-right: 38px; }
.input-group .icon-btn { position: absolute; right: 3px; top: 3px; }
.input-prefix { position: relative; }
.input-prefix span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); display: flex; align-items: center; }
.input-prefix span .lucide { width: 14px; height: 14px; }
.input-prefix:has(.is-mail) .input { padding-left: 32px; }
.input-prefix .input { padding-left: 26px; }
.form-error { color: var(--danger-text); background: var(--danger-soft); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 12.5px; margin-bottom: 12px; }
.inline-form { display: flex; gap: 8px; }
.inline-form .input-group { flex: 1; }

/* ───────────── Modal ───────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgb(24 24 27 / 0.32);
  display: grid; place-items: center; padding: 24px; animation: fade 0.14s ease-out;
}
.modal {
  width: 440px; max-width: 100%; background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); animation: pop 0.16s ease-out;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 6px; }
.modal-head h2 { font-size: 15.5px; font-weight: 600; }
.modal-head p { color: var(--text-2); margin-top: 3px; }
.modal-body { padding: 14px 20px 6px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

/* ───────────── Toasts ───────────── */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; align-items: center; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; min-width: 260px; max-width: 380px;
  padding: 11px 14px; background: var(--text); color: #fafafa; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: 13px; animation: pop 0.16s ease-out;
}
.toast .lucide { margin-top: 2px; }
.toast.success .lucide { color: #4ade80; }
.toast.error .lucide { color: #f87171; }
.toast.warning .lucide { color: #fbbf24; }

#drawer-root { position: relative; z-index: 20; }
#modal-root { position: relative; z-index: 30; }

.login-mail { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.login-mail .lucide { width: 14px; height: 14px; color: var(--text-3); }

/* Proxy por conta */
.proxy-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.proxy-row > .lucide { color: var(--text-3); flex: none; }
.proxy-row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.proxy-mark { display: inline-flex; vertical-align: middle; margin-left: 6px; color: var(--text-3); }
.proxy-mark .lucide { width: 13px; height: 13px; }
.proxy-mark.is-error { color: var(--danger, #dc2626); }
.inline-form .input.mono { flex: 1; }
