:root {
  --brand: #3F87FC;
  --brand-dark: #2563EB;
  --brand-soft: #EFF6FF;
  --ink: #111827;
  --muted: #64748B;
  --surface: #FFFFFF;
  --canvas: #F5F8FC;
  --border: #E5E7EB;
  --success: #16A34A;
  --warning: #D97706;
  --danger: #DC2626;
  --sidebar: 272px;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: #1D4ED8; }
.btn { min-height: 42px; border-radius: 10px; font-weight: 650; padding-inline: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 34px; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark); }
.btn-soft-primary { background: var(--brand-soft); color: var(--brand-dark); border: 1px solid #D6E6FF; }
.btn-soft-primary:hover { background: #DBEAFE; color: #1D4ED8; }
.form-control, .form-select { min-height: 44px; border-color: var(--border); border-radius: 10px; color: var(--ink); }
textarea.form-control { min-height: 120px; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .22rem rgba(63, 135, 252, .14); }
.form-label { font-weight: 650; color: #334155; margin-bottom: .45rem; }
.form-text { color: var(--muted); }

.app-sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: #111827; color: #CBD5E1; z-index: 1040; display: flex; flex-direction: column; transition: transform .24s ease; }
.brand-block { padding: 24px 22px 20px; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 43px; height: 43px; flex: 0 0 43px; background: var(--brand); color: #fff; border-radius: 13px; display: grid; place-items: center; font-size: 21px; box-shadow: 0 7px 20px rgba(63,135,252,.28); }
.brand-name { color: #fff; font-size: 15px; line-height: 1.2; font-weight: 750; }
.brand-subtitle { color: #94A3B8; font-size: 11px; margin-top: 4px; }
.sidebar-nav { overflow-y: auto; padding: 14px 12px; flex: 1; scrollbar-width: thin; }
.nav-section { color: #64748B; font-size: 10px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; padding: 14px 12px 7px; }
.sidebar-link { min-height: 43px; color: #CBD5E1; display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 3px 0; border-radius: 10px; font-weight: 560; transition: background .16s ease, color .16s ease; }
.sidebar-link i { font-size: 17px; width: 20px; text-align: center; }
.sidebar-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-link.active { background: var(--brand); color: #fff; box-shadow: 0 8px 18px rgba(63,135,252,.22); }
.sidebar-footer { padding: 14px 12px 18px; border-top: 1px solid rgba(255,255,255,.08); }
.emergency-btn { width: 100%; border: 1px solid rgba(248,113,113,.38); color: #FCA5A5; background: rgba(220,38,38,.09); }
.emergency-btn:hover { background: #DC2626; color: #fff; }

.app-main { margin-left: var(--sidebar); min-height: 100vh; display: flex; flex-direction: column; }
.app-topbar { height: 76px; padding: 0 30px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1020; backdrop-filter: blur(10px); }
.page-heading { font-size: 20px; font-weight: 750; margin: 0; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.wa-pill { height: 36px; padding: 0 12px; border: 1px solid var(--border); background: #fff; border-radius: 999px; display: flex; align-items: center; gap: 8px; color: #475569; font-weight: 650; font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #EF4444; box-shadow: 0 0 0 4px rgba(239,68,68,.1); }
.status-dot.connected { background: #22C55E; box-shadow: 0 0 0 4px rgba(34,197,94,.1); }
.topbar-icon { border: 1px solid var(--border); background: #fff; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: #475569; }
.avatar { width: 38px; height: 38px; border-radius: 11px; background: var(--brand-soft); color: var(--brand-dark); display: grid; place-items: center; font-weight: 800; }
.mobile-menu { display: none; }
.content-wrap { flex: 1; padding: 28px 30px 36px; width: 100%; max-width: 1720px; margin: 0 auto; }
.app-footer { color: #94A3B8; font-size: 12px; text-align: center; padding: 18px 30px 24px; }
.app-footer small { display: block; margin-top: 4px; }

.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { background: #fff; border-bottom: 1px solid var(--border); padding: 19px 22px; border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-body { padding: 22px; }
.section-title { font-size: 16px; font-weight: 750; margin: 0; }
.section-subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }
.page-intro { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 22px; }
.page-intro h2 { font-size: 25px; font-weight: 780; margin: 0 0 5px; letter-spacing: -.025em; }
.page-intro p { color: var(--muted); margin: 0; }

.stat-card { padding: 20px; height: 100%; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; width: 70px; height: 70px; border-radius: 50%; right: -28px; top: -28px; background: var(--brand-soft); }
.stat-icon { width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 19px; margin-bottom: 17px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 680; text-transform: uppercase; letter-spacing: .045em; }
.stat-value { font-size: 27px; font-weight: 800; margin-top: 4px; letter-spacing: -.03em; }
.stat-meta { color: var(--muted); margin-top: 3px; font-size: 12px; }
.stat-card.success .stat-icon { background: #ECFDF5; color: var(--success); }
.stat-card.warning .stat-icon { background: #FFFBEB; color: var(--warning); }
.stat-card.danger .stat-icon { background: #FEF2F2; color: var(--danger); }

.table { margin: 0; color: #334155; }
.table > :not(caption) > * > * { border-bottom-color: #EEF2F7; padding: .9rem .85rem; vertical-align: middle; }
.table thead th { color: #64748B; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 750; background: #F8FAFC; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #FBFDFF; }
.badge { font-weight: 700; padding: .42rem .62rem; border-radius: 999px; letter-spacing: .01em; }
.badge-status-sent, .badge-status-connected, .badge-status-completed, .badge-status-active, .badge-status-confirmed { background: #DCFCE7; color: #15803D; }
.badge-status-failed, .badge-status-error, .badge-status-stopped, .badge-status-opted_out, .badge-status-inactive, .badge-status-cancelled { background: #FEE2E2; color: #B91C1C; }
.badge-status-pending, .badge-status-paused, .badge-status-unknown, .badge-status-skipped { background: #FEF3C7; color: #B45309; }
.badge-status-running, .badge-status-processing, .badge-status-draft, .badge-status-queued { background: #DBEAFE; color: #1D4ED8; }
.pagination .page-link { color: var(--brand-dark); border-color: var(--border); min-width: 38px; text-align: center; }
.pagination .active .page-link { background: var(--brand); border-color: var(--brand); }

.empty-state { text-align: center; padding: 55px 24px; }
.empty-icon { width: 68px; height: 68px; margin: 0 auto 18px; border-radius: 20px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 29px; }
.empty-state h3 { font-size: 18px; font-weight: 750; }
.empty-state p { color: var(--muted); max-width: 390px; margin: 8px auto 20px; }
.alert { border: 0; border-radius: 12px; }
.progress { height: 10px; background: #E8EEF7; border-radius: 999px; }
.progress-bar { background: var(--brand); border-radius: 999px; }
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-item { display: flex; gap: 12px; padding: 13px 0; border-bottom: 1px solid #EEF2F7; }
.activity-item:last-child { border-bottom: 0; }
.activity-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--brand); flex: 0 0 8px; }
.activity-time { color: #94A3B8; font-size: 11px; }

.device-shell { max-width: 920px; margin: 0 auto; }
.device-hero { text-align: center; padding: 34px 24px 20px; }
.device-icon { width: 76px; height: 76px; border-radius: 23px; display: grid; place-items: center; margin: 0 auto 18px; background: var(--brand-soft); color: var(--brand); font-size: 35px; }
.qr-frame { width: 368px; max-width: 100%; min-height: 368px; margin: 20px auto; border: 2px solid #D6E6FF; border-radius: 22px; padding: 13px; display: grid; place-items: center; background: #fff; position: relative; }
.qr-frame::before, .qr-frame::after { content: ''; position: absolute; width: 46px; height: 46px; border-color: var(--brand); border-style: solid; }
.qr-frame::before { left: -2px; top: -2px; border-width: 4px 0 0 4px; border-radius: 20px 0 0 0; }
.qr-frame::after { right: -2px; bottom: -2px; border-width: 0 4px 4px 0; border-radius: 0 0 20px 0; }
.qr-frame img { max-width: 100%; border-radius: 10px; }
.instruction-list { counter-reset: steps; list-style: none; padding: 0; margin: 0; }
.instruction-list li { counter-increment: steps; display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.instruction-list li::before { content: counter(steps); width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-dark); font-weight: 800; }

.wizard-steps { display: grid; grid-template-columns: repeat(5,1fr); margin-bottom: 22px; gap: 8px; }
.wizard-step-label { position: relative; text-align: center; color: #94A3B8; font-weight: 650; font-size: 12px; }
.wizard-step-label span { width: 34px; height: 34px; margin: 0 auto 7px; background: #E2E8F0; color: #64748B; display: grid; place-items: center; border-radius: 50%; position: relative; z-index: 1; }
.wizard-step-label.active, .wizard-step-label.done { color: var(--brand-dark); }
.wizard-step-label.active span, .wizard-step-label.done span { background: var(--brand); color: #fff; }
.wizard-panel { display: none; }
.wizard-panel.active { display: block; }
.message-preview { white-space: pre-wrap; background: #E7FFDB; border-radius: 12px 12px 3px 12px; padding: 14px 16px; max-width: 440px; box-shadow: 0 2px 4px rgba(15,23,42,.07); }
.upload-zone { border: 2px dashed #BDD4F8; border-radius: 16px; background: #F8FBFF; padding: 42px 20px; text-align: center; transition: .2s; }
.upload-zone.dragover { border-color: var(--brand); background: var(--brand-soft); }
.upload-zone i { color: var(--brand); font-size: 35px; }
.filter-bar { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 18px; }
.check-list { max-height: 330px; overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; padding: 6px; }
.check-list .form-check { padding: 10px 10px 10px 35px; margin: 0; border-bottom: 1px solid #F1F5F9; }
.check-list .form-check:last-child { border-bottom: 0; }
.chart-wrap { min-height: 300px; position: relative; }
.about-hero { background: #111827; color: #fff; border-radius: 20px; padding: 44px; position: relative; overflow: hidden; }
.about-hero::after { content: ''; position: absolute; width: 250px; height: 250px; right: -80px; top: -100px; background: rgba(63,135,252,.18); border-radius: 50%; }
.about-hero .brand-mark { margin-bottom: 22px; }
.about-hero p { color: #CBD5E1; max-width: 690px; font-size: 15px; line-height: 1.75; }

.auth-page { min-height: 100vh; background: #EEF4FD; display: grid; place-items: center; padding: 24px; }
.auth-shell { width: 100%; max-width: 1040px; display: grid; grid-template-columns: 1.05fr .95fr; border-radius: 24px; overflow: hidden; background: #fff; box-shadow: 0 24px 80px rgba(15,23,42,.13); }
.auth-brand { background: #111827; color: #fff; padding: 58px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-brand::after { content: ''; width: 330px; height: 330px; background: rgba(63,135,252,.17); position: absolute; right: -120px; bottom: -150px; border-radius: 50%; }
.auth-brand h1 { font-size: 36px; font-weight: 800; letter-spacing: -.04em; margin: 36px 0 15px; }
.auth-brand p { color: #CBD5E1; line-height: 1.7; max-width: 400px; }
.auth-form { padding: 58px; align-self: center; }
.auth-form h2 { font-size: 27px; font-weight: 800; letter-spacing: -.03em; }
.credit { color: #94A3B8; font-size: 11px; position: relative; z-index: 1; }
.install-shell { width: min(1080px, 100%); background: #fff; border-radius: 24px; box-shadow: 0 24px 80px rgba(15,23,42,.12); overflow: hidden; }
.install-header { background: #111827; color: #fff; padding: 26px 34px; display: flex; align-items: center; gap: 14px; }
.install-body { padding: 34px; }
.requirement-row { display: flex; justify-content: space-between; gap: 20px; padding: 14px 0; border-bottom: 1px solid var(--border); }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open::after { content: ''; position: fixed; inset: 0; background: rgba(15,23,42,.48); z-index: 1030; }
  .app-main { margin-left: 0; }
  .mobile-menu { display: grid; }
  .auth-shell { grid-template-columns: 1fr; max-width: 600px; }
  .auth-brand { padding: 32px; min-height: 260px; }
  .auth-brand h1 { font-size: 29px; margin-top: 24px; }
  .wizard-steps { grid-template-columns: repeat(5, minmax(58px, 1fr)); overflow-x: auto; }
}

@media (max-width: 767.98px) {
  .app-topbar { height: 66px; padding: 0 16px; }
  .content-wrap { padding: 20px 16px 30px; }
  .page-heading { font-size: 17px; }
  .wa-pill .wa-label { display: none; }
  .topbar-actions { gap: 7px; }
  .page-intro { flex-direction: column; }
  .page-intro .d-flex { width: 100%; flex-wrap: wrap; }
  .page-intro .btn { flex: 1; }
  .card-body, .card-header { padding: 17px; }
  .auth-page { padding: 0; display: block; background: #fff; }
  .auth-shell, .install-shell { min-height: 100vh; border-radius: 0; box-shadow: none; }
  .auth-brand { min-height: 230px; }
  .auth-form { padding: 34px 25px; }
  .install-header, .install-body { padding: 24px 20px; }
  .qr-frame { min-height: 280px; width: 300px; }
  .about-hero { padding: 30px 24px; }
  .filter-bar .row > div { margin-bottom: 8px; }
  .table-responsive { font-size: 13px; }
  .wizard-step-label { min-width: 66px; }
  .wizard-step-label small { display: none; }
}
