/* ================================================================
   ZAPPSENDER v3 — Sidebar Layout
   ================================================================ */

/* ── 1. TOKENS ──────────────────────────────────────────────────── */
:root {
  /* Brand */
  --brand:        #00A884;
  --brand-dark:   #008069;
  --brand-light:  rgba(0,168,132,.12);
  --brand-500:    #00A884;
  --brand-600:    #008069;

  /* Sidebar */
  --sb-bg:        #0D1117;
  --sb-border:    rgba(255,255,255,.06);
  --sb-text:      rgba(255,255,255,.50);
  --sb-text-hover:rgba(255,255,255,.85);
  --sb-active-bg: rgba(0,168,132,.14);
  --sb-width:     230px;

  /* Content */
  --page-bg:   #F0F4F8;
  --card-bg:   #FFFFFF;
  --border:    #E2E8F0;

  /* Slate */
  --slate-50:  #F8FAFC;
  --slate-100: #F1F5F9;
  --slate-200: #E2E8F0;
  --slate-300: #CBD5E1;
  --slate-400: #94A3B8;
  --slate-500: #64748B;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1E293B;
  --slate-900: #0F172A;

  /* Semantic */
  --success-50:  #F0FDF4;
  --success-500: #22C55E;
  --success-600: #16A34A;
  --error-50:  #FEF2F2;
  --error-500: #EF4444;
  --error-600: #DC2626;
  --warning-500:#F59E0B;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 8px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 24px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.05);

  /* Radii */
  --radius-sm:  4px;
  --radius:     8px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-full:9999px;
}

/* ── 2. RESET ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--slate-700);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
h1,h2,h3,h4 { margin: 0; font-weight: 700; color: var(--slate-900); line-height: 1.3; }

/* ── 3. SHELL + SIDEBAR ─────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sb-width);
  min-width: var(--sb-width);
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 200;
  transition: transform .25s ease;
}

.main {
  margin-left: var(--sb-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
}

/* Brand */
.sidebar-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--sb-border);
}
.sidebar-brand img { height: 26px; }
.sidebar-brand-text {
  font-size: 17px; font-weight: 700;
  color: #fff; letter-spacing: -.3px;
}

/* Section labels */
.sb-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: rgba(255,255,255,.22);
  padding: 20px 18px 5px;
}

/* Nav items */
.sidebar-nav { flex: 1; padding-bottom: 8px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 18px;
  font-size: 13.5px; font-weight: 500;
  color: var(--sb-text);
  border-left: 2px solid transparent;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.sidebar-nav a:hover {
  color: var(--sb-text-hover);
  background: rgba(255,255,255,.04);
  text-decoration: none;
}
.sidebar-nav a.active {
  color: var(--brand);
  background: var(--sb-active-bg);
  border-left-color: var(--brand);
  font-weight: 600;
}
.sb-icon {
  width: 16px; text-align: center;
  opacity: .7; flex-shrink: 0;
  font-style: normal;
}
.sidebar-nav a.active .sb-icon { opacity: 1; }
.sidebar-nav a:hover .sb-icon { opacity: 1; }

/* Sidebar footer */
.sidebar-footer {
  border-top: 1px solid var(--sb-border);
  padding: 14px 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.sb-user-email {
  font-size: 12px; color: rgba(255,255,255,.4);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-footer-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.sb-logout {
  font-size: 12px; font-weight: 500;
  color: rgba(255,255,255,.35);
  padding: 4px 8px; border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
}
.sb-logout:hover {
  color: #fff;
  background: rgba(255,255,255,.08);
  text-decoration: none;
}
.sb-clear-btn {
  font-size: 11px; font-weight: 500;
  color: rgba(255,255,255,.3);
  background: none; border: none; cursor: pointer; padding: 4px 0;
  transition: color .15s;
}
.sb-clear-btn:hover { color: var(--error-500); }

/* Mobile toggle */
.sidebar-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 300;
  background: var(--sb-bg); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 18px; cursor: pointer;
}

/* Content area */
.content-area {
  padding: 32px 40px;
  flex: 1;
}

/* ── 4. AUTH PAGES ──────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px;
  background: var(--page-bg);
}
.auth-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow-md);
}
.auth-logo { margin-bottom: 28px; }
.auth-logo img { height: 30px; }
.auth-card h2 { font-size: 20px; margin-bottom: 6px; }
.auth-card .auth-sub { color: var(--slate-500); margin-bottom: 24px; }
.auth-footer { margin-top: 20px; font-size: 13px; color: var(--slate-500); text-align: center; }
.auth-footer a { color: var(--brand); font-weight: 500; }

/* ── 5. PAGE HEADER ─────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 24px; gap: 12px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header h2 { font-size: 18px; font-weight: 700; }

/* ── 6. CARDS ───────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  box-shadow: var(--shadow-xs);
}

/* ── 7. TABLE ───────────────────────────────────────────────────── */
.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.table {
  width: 100%; border-collapse: collapse;
}
.table thead th {
  background: var(--slate-50);
  padding: 10px 16px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--slate-500);
  border-bottom: 1px solid var(--border);
  text-align: left; white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--slate-100);
  font-size: 13.5px; color: var(--slate-700);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--slate-50); }

/* ── 8. FORMS ───────────────────────────────────────────────────── */
.form { display: grid; gap: 16px; }
label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; font-weight: 500; color: var(--slate-700);
}
label.inline-label { flex-direction: row; align-items: center; }
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=tel], input[type=month],
input[type=date], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  background: #fff; color: var(--slate-800);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,168,132,.12);
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 90px; }
input[readonly] { background: var(--slate-50); color: var(--slate-500); }

/* ── 9. BUTTONS ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  font-size: 13.5px; font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--brand); color: #fff;
  transition: background .15s, opacity .15s, transform .08s;
  text-decoration: none; white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: #fff; color: var(--slate-700);
  border-color: var(--slate-200);
}
.btn-secondary:hover { background: var(--slate-50); color: var(--slate-900); }

.btn-danger, .btn-red {
  background: var(--error-500); color: #fff; border-color: transparent;
}
.btn-danger:hover, .btn-red:hover { background: var(--error-600); }

.btn-circle {
  border-radius: var(--radius-full);
  width: 36px; height: 36px; padding: 0;
}

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

/* ── 10. FILTER BAR ─────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: flex-end; gap: 12px;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
}
.filter-bar label { min-width: 100px; }

/* ── 11. PAGINATION ─────────────────────────────────────────────── */
.pagination {
  display: flex; gap: 4px; align-items: center;
  margin-top: 16px; flex-wrap: wrap;
}
.pagination .btn { padding: 5px 11px; font-size: 13px; }
.pagination span.btn {
  background: var(--brand); color: #fff; border-color: var(--brand);
  cursor: default; opacity: 1;
}
.pagination .btn-secondary { color: var(--slate-600); }
.pagination .btn-secondary:hover { background: var(--slate-50); }

/* ── 12. STATUS PILLS ───────────────────────────────────────────── */
.status-pill {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.status-connected    { background: var(--success-500); box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
.status-disconnected { background: var(--slate-400); }
.status-pill-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500;
}
.ok  { color: var(--success-600); }
.bad { color: var(--error-500); }
.muted { color: var(--slate-500); font-size: .875em; }

/* ── 13. TOAST ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 360px;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 8px;
  transition: opacity .3s, transform .3s;
  opacity: 1; transform: translateY(0);
}
.toast.success { background: var(--success-600); color: #fff; }
.toast.error   { background: var(--error-600);   color: #fff; }
.toast.info    { background: var(--slate-800);    color: #fff; }

/* ── 14. LOADING OVERLAY ────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 15. MODAL (QR / Confirm) ───────────────────────────────────── */
.qr-modal {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.qr-modal[hidden] { display: none; }
.qr-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh; overflow-y: auto;
}
.qr-pre {
  font-family: monospace; font-size: 11px; line-height: 1.1;
  white-space: pre; overflow: hidden; background: #000;
  color: #fff; padding: 12px; border-radius: var(--radius-sm);
  user-select: none;
}

/* ── 16. iOS TOGGLE ─────────────────────────────────────────────── */
.switch {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  width: fit-content;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.slider {
  flex-shrink: 0;
  width: 38px; height: 22px; border-radius: 11px;
  background: var(--slate-300);
  position: relative; transition: background .2s;
}
.slider::after {
  content: ''; position: absolute;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::after { transform: translateX(16px); }
.switch .label { font-size: 13.5px; font-weight: 500; color: var(--slate-700); }

/* ── 17. PASSWORD CRITERIA ──────────────────────────────────────── */
.crit { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 3px; }
.crit li { font-size: 12px; color: var(--slate-500); padding-left: 16px; position: relative; }
.crit li::before { content: '○'; position: absolute; left: 0; }
.crit li.ok  { color: var(--success-600); }
.crit li.ok::before { content: '●'; }
.crit li.bad { color: var(--error-500); }
.crit li.bad::before { content: '✕'; }

/* ── 18. DRAG & DROP ────────────────────────────────────────────── */
.msg-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 6px;
  cursor: grab;
}
.msg-item.is-dragging { opacity: .5; }
.msg-item.drag-active { border-color: var(--brand); background: var(--brand-light); }
.drag-floating {
  position: fixed; pointer-events: none; opacity: .9;
  border: 2px dashed var(--brand); z-index: 8000;
}
.msg-label { flex: 1; font-size: 13.5px; color: var(--slate-700); }
.remove-msg {
  background: none; border: none; cursor: pointer;
  color: var(--slate-400); font-size: 18px; line-height: 1; padding: 0;
  transition: color .15s;
}
.remove-msg:hover { color: var(--error-500); }

/* ── 19. METRIC CARDS ───────────────────────────────────────────── */
.admin-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.metric { text-align: left; }
.metric .label { font-size: 12px; font-weight: 600; color: var(--slate-500); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.metric .value { font-size: 2.2rem; font-weight: 800; color: var(--slate-900); line-height: 1; }

/* ── 20. ADMIN SUBNAV ───────────────────────────────────────────── */
.admin-subnav {
  display: flex; gap: 2px; flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-xs);
}
.admin-subnav a {
  padding: 7px 14px; border-radius: 6px;
  font-size: 13px; font-weight: 500;
  color: var(--slate-600);
  text-decoration: none;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.admin-subnav a:hover { background: var(--slate-100); color: var(--slate-900); }
.admin-subnav a.active {
  background: var(--brand); color: #fff;
}

/* ── 21. EMPTY STATE ────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--slate-400); font-size: 14px;
}

/* ── 22. MISC UTILITIES ─────────────────────────────────────────── */
.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.invert-toggle { filter: invert(1); }
code, .qr-pre { font-family: 'Courier New', monospace; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
legend { font-size: 12px; font-weight: 600; color: var(--slate-500); padding: 0 6px; }

/* fin-row (finance) */
.fin-row { cursor: pointer; }

/* Flash messages */
.flashes { list-style: none; padding: 0; margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13.5px; }
.flash.success { background: var(--success-50); color: var(--success-600); border: 1px solid #BBF7D0; }
.flash.error   { background: var(--error-50);   color: var(--error-600);   border: 1px solid #FECACA; }
.flash.info    { background: var(--slate-100);  color: var(--slate-700);   border: 1px solid var(--slate-200); }

/* ── 23. RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sb-width: 200px; }
  .content-area { padding: 24px 24px; }
}

@media (max-width: 680px) {
  .sidebar {
    transform: translateX(-100%);
    width: 240px; min-width: 240px;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .sidebar-toggle { display: block; }
  .content-area { padding: 20px 16px; }
  .admin-subnav { gap: 0; }
  .table td, .table th { padding: 10px 12px; font-size: 13px; }
  .auth-card { padding: 28px 20px; }
}

@media (max-width: 480px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .admin-cards { grid-template-columns: 1fr 1fr; }
}

/* ── V4 PATCH: WA Status Button ─────────────────────────────────── */
.wa-status-btn {
  font-size: 13.5px; font-weight: 600;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  transition: background .15s, transform .08s;
}
.wa-status-btn.status-disconnected {
  background: var(--slate-600); color: #fff;
}
.wa-status-btn.status-disconnected:hover { background: var(--slate-700); }
.wa-status-btn.status-connected {
  background: var(--success-600); color: #fff;
}
.wa-status-btn.status-connected:hover { background: var(--success-700, #15803d); }

/* ── V4 PATCH: Message Item Layout ──────────────────────────────── */
.msg-item {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 6px !important;
  cursor: default !important;
}
.msg-select-row {
  display: flex; align-items: center; gap: 8px;
}
.msg-select-row select { flex: 1; margin: 0; }

/* ── V4 PATCH: Remove msg button (pleasant, no red circle) ──────── */
.remove-msg {
  background: var(--slate-100) !important;
  border: 1px solid var(--slate-200) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--slate-500) !important;
  font-size: 13px !important; font-weight: 600 !important;
  width: 32px !important; height: 32px !important; padding: 0 !important;
  display: inline-flex !important; align-items: center !important; justify-content: center !important;
  cursor: pointer !important; flex-shrink: 0 !important;
  transition: background .15s, color .15s !important;
}
.remove-msg:hover {
  background: var(--slate-200) !important;
  color: var(--slate-800) !important;
}

/* ── V4 PATCH: Message group scrollable container ───────────────── */
#message-group { scrollbar-width: thin; scrollbar-color: var(--slate-300) transparent; }
#message-group::-webkit-scrollbar { width: 5px; }
#message-group::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 4px; }

/* ── V5 PATCH: QR modal offset p/ sidebar em desktop ───────────── */
@media (min-width: 769px) {
  .qr-modal { left: 230px !important; }
}

/* ── V5 PATCH: Message select — 25% largura ─────────────────────── */
.msg-item { max-width: 440px !important; }
.msg-select-row { max-width: 100%; }
.msg-select-row select { max-width: 100%; }

/* ── V5 PATCH: Botões sem classe — fallback global ──────────────── */
form button:not([class]),
form button[class=""] {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; font-size: 13.5px; font-weight: 600;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; background: var(--brand); color: #fff;
  transition: background .15s; line-height: 1.4;
}
form button:not([class]):hover,
form button[class=""]:hover { background: var(--brand-dark); }
