:root {
    --navy: #11233f;
    --blue: #1d7ed0;
    --cyan: #2bbbd8;
    --bg: #f4f7fb;
    --text: #172033;
    --muted: #637083;
    --line: #dde5ef;
    --danger: #d92d20;
    --success: #16803c;
    --warning: #b7791f;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #fff; padding: 22px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; margin-bottom: 28px; line-height: 1.2; }
.brand img { width: 36px; height: 36px; flex: 0 0 auto; border-radius: 8px; }
.nav a { display: block; color: #dce9f8; padding: 11px 12px; border-radius: 8px; margin-bottom: 4px; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.main { padding: 24px; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 20px; }
.topbar-title { min-width: 0; }
.topbar-app-name { display: block; margin-bottom: 4px; color: var(--blue); font-size: 14px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.topbar h1 { margin: 0; font-size: 26px; }
.top-user { color: var(--muted); font-weight: 700; }
.panel, .card { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(17,35,63,.06); }
.panel { padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.card { padding: 16px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 8px; }
.control-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.control-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 8px 24px rgba(17,35,63,.05); }
.control-item span { color: var(--muted); font-size: 13px; }
.control-item strong { font-size: 15px; }
.control-item.ok { border-left: 4px solid var(--success); }
.control-item.warn { border-left: 4px solid var(--warning); }
.control-item.danger { border-left: 4px solid var(--danger); }
.control-item.info { border-left: 4px solid var(--blue); }
.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric-card { min-height: 132px; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); box-shadow: 0 8px 24px rgba(17,35,63,.06); }
.metric-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.metric-card strong { font-size: 34px; line-height: 1; }
.metric-card small { color: var(--muted); font-size: 12px; }
.metric-card.success { border-top: 4px solid var(--success); }
.metric-card.warn { border-top: 4px solid var(--warning); }
.metric-card.danger { border-top: 4px solid var(--danger); }
.metric-card.info { border-top: 4px solid var(--blue); }
.metric-card.ok { border-top: 4px solid var(--success); }
.metric-card strong, .control-item strong, .limit-card strong { transition: color .25s ease; }
.metric-card.live-updated strong, .control-item.live-updated strong, .limit-card.live-updated strong { color: var(--blue); }
.split-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.event-line { display: grid; grid-template-columns: auto 1fr 1fr 1.4fr; gap: 10px; align-items: center; color: var(--muted); }
.event-line strong { color: var(--text); }
.event-line.danger strong { color: var(--danger); }
.limit-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.limit-card { min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.limit-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.limit-card strong { font-size: 24px; line-height: 1.1; }
.limit-card small { color: var(--muted); font-size: 12px; }
.limit-card.ok { border-left: 4px solid var(--success); }
.limit-card.warn { border-left: 4px solid var(--warning); }
.limit-card.danger { border-left: 4px solid var(--danger); }
.limit-card.info { border-left: 4px solid var(--blue); }
.stability-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stability-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr); gap: 14px; align-items: start; }
.stability-layout h3 { margin: 0 0 8px; font-size: 15px; }
.stability-chart { width: 100%; height: 220px; display: block; }
.compact-table th, .compact-table td { padding: 8px 10px; font-size: 12px; }
.compact-table td:nth-child(2) { white-space: nowrap; font-weight: 700; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; background: var(--blue); }
.status-dot.ok { background: var(--success); }
.status-dot.warn { background: var(--warning); }
.status-dot.danger { background: var(--danger); }
.status-dot.info { background: var(--blue); }
.chat-list { display: grid; gap: 10px; }
.chat-item { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
.chat-item:hover { border-color: #b8c7d9; box-shadow: 0 8px 20px rgba(17,35,63,.06); }
.chat-item.failed, .chat-item.retry { border-left: 4px solid var(--danger); }
.chat-item.pending, .chat-item.processing { border-left: 4px solid var(--warning); }
.chat-item.sent { border-left: 4px solid var(--success); }
.chat-item.discarded { border-left: 4px solid #98a2b3; }
.chat-avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: #e0f2fe; color: #075985; font-weight: 800; }
.chat-body { min-width: 0; }
.chat-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 3px; }
.chat-head span, .chat-meta { color: var(--muted); font-size: 12px; }
.chat-message { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-status { display: flex; justify-content: flex-end; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; font: inherit; background: #fff; }
textarea { min-height: 120px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 8px; padding: 10px 13px; cursor: pointer; font-weight: 700; color: #fff; background: var(--blue); }
.btn.secondary { background: #667085; }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn.warning { background: var(--warning); }
.btn.light { background: #e8eef6; color: var(--text); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.text-bg-success { background: #dcfce7; color: #166534; }
.text-bg-secondary { background: #eef2f7; color: #344054; }
.text-bg-info { background: #e0f2fe; color: #075985; }
.text-bg-warning { background: #fef3c7; color: #92400e; }
.text-bg-danger { background: #fee2e2; color: #991b1b; }
.text-bg-dark { background: #344054; color: #fff; }
.text-bg-light { background: #f8fafc; color: #475467; }
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--line); background: #fff; }
.alert.warning { border-color: #facc15; background: #fefce8; }
.alert.success { border-color: #86efac; background: #f0fdf4; }
.alert.danger { border-color: #fca5a5; background: #fef2f2; }
.queue-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.queue-actions h2 { margin: 0 0 6px; }
.queue-actions p { margin: 0; }
.whatsapp-control { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.whatsapp-control h2 { margin: 0 0 6px; }
.whatsapp-control p { margin: 0; }
.whatsapp-control .actions { justify-content: flex-end; }
.btn:disabled { cursor: not-allowed; opacity: .55; }
.muted { color: var(--muted); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #11233f, #1d7ed0); }
.login .panel { width: min(420px, 100%); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-brand img { width: 48px; height: 48px; border-radius: 12px; }
.login-brand strong { display: block; font-size: 20px; }
.login-brand span { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.code { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: #f8fafc; padding: 12px; border-radius: 8px; border: 1px solid var(--line); overflow: auto; }
.copy-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 14px 0 6px; }
.copy-row label { margin: 0; }
canvas { width: 100%; max-height: 260px; }
.settings-panel h2 { margin-top: 0; }
.settings-section { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.settings-section h3 { margin: 0 0 12px; font-size: 16px; }
.settings-overview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.settings-overview div { border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; padding: 12px; }
.settings-overview span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.settings-overview strong { font-size: 17px; }
.test-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.integration-grid .code { max-height: 360px; }
.whatsapp-status { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.whatsapp-status h2, .qr-panel h2 { margin-top: 0; }
.status-pill { display: inline-flex; align-items: center; min-height: 34px; padding: 7px 12px; border-radius: 999px; font-weight: 800; white-space: nowrap; }
.status-pill.ok { background: #dcfce7; color: #166534; }
.status-pill.warn { background: #fef3c7; color: #92400e; }
.qr-panel { display: grid; grid-template-columns: 320px 1fr; gap: 22px; align-items: center; }
.qr-image, .qr-placeholder { width: 320px; max-width: 100%; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr-image { display: block; padding: 12px; object-fit: contain; }
.qr-placeholder { display: grid; place-items: center; color: var(--muted); background: #f8fafc; font-weight: 800; }

@media (max-width: 1000px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .control-grid, .metric-grid, .split-grid, .limit-grid, .stability-grid, .stability-layout, .settings-overview, .test-grid, .integration-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .qr-panel { grid-template-columns: 1fr; }
    .whatsapp-status { align-items: flex-start; flex-direction: column; }
    .whatsapp-control { align-items: flex-start; flex-direction: column; }
    .whatsapp-control .actions { justify-content: flex-start; }
    .queue-actions { align-items: flex-start; flex-direction: column; }
    .chat-item { grid-template-columns: 36px minmax(0, 1fr); }
    .chat-status { grid-column: 2; justify-content: flex-start; }
    .chat-head { flex-direction: column; gap: 2px; }
    .copy-row { align-items: flex-start; flex-direction: column; }
    .main { padding: 16px; }
    table { display: block; overflow-x: auto; }
}
