: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 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; }
}

/* PoulyNet WhatsApp Cloud Platform v2 */
:root {
    --navy: #071a2f;
    --navy-2: #0b2745;
    --blue: #1769e0;
    --cyan: #2dd4bf;
    --wa: #18b96b;
    --bg: #f3f6fa;
    --text: #10233b;
    --muted: #64748b;
    --line: #dbe4ee;
    --surface: rgba(255,255,255,.94);
    --shadow: 0 14px 38px rgba(15,35,60,.08);
}

body {
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 92% 2%, rgba(45,212,191,.11), transparent 25rem),
        linear-gradient(180deg, #f8fafc 0, var(--bg) 420px);
}

.app { grid-template-columns: 268px minmax(0, 1fr); }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 26px 18px;
    background:
        radial-gradient(circle at 10% 0, rgba(45,212,191,.22), transparent 17rem),
        linear-gradient(165deg, var(--navy-2), var(--navy) 58%);
    box-shadow: 14px 0 42px rgba(7,26,47,.13);
}
.brand { gap: 13px; margin: 0 4px 28px; font-size: 15px; }
.brand img { width: 43px; height: 43px; padding: 7px; border-radius: 13px; background: rgba(255,255,255,.96); box-shadow: 0 8px 20px rgba(0,0,0,.18); }
.brand span, .brand strong, .brand small { display: block; }
.brand small { margin-top: 5px; color: #9cc1de; font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.brand small b { margin-left: 4px; padding: 2px 6px; border-radius: 999px; color: #062c22; background: var(--cyan); }
.nav { display: grid; gap: 4px; }
.nav a { position: relative; margin: 0; padding: 11px 13px; border: 1px solid transparent; border-radius: 10px; font-size: 14px; font-weight: 650; transition: .18s ease; }
.nav a:hover { transform: translateX(2px); background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; border-color: rgba(94,234,212,.24); background: linear-gradient(90deg, rgba(24,185,107,.25), rgba(23,105,224,.18)); box-shadow: inset 3px 0 var(--cyan); }

.main { min-width: 0; padding: 30px 34px 48px; }
.topbar { min-height: 58px; margin-bottom: 24px; }
.page-heading .eyebrow { display: block; margin-bottom: 4px; color: var(--blue); font-size: 10px; font-weight: 850; letter-spacing: .16em; text-transform: uppercase; }
.topbar h1 { font-size: clamp(24px, 2.3vw, 32px); letter-spacing: -.035em; }
.top-user { padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.75); font-size: 13px; }
.panel, .card, .control-item, .metric-card { border-color: rgba(203,213,225,.76); border-radius: 15px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.panel { padding: 22px; margin-bottom: 20px; }
.panel > h2:first-child { margin-top: 0; letter-spacing: -.02em; }
.metric-card { position: relative; overflow: hidden; min-height: 140px; border-top: 0 !important; }
.metric-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--blue); }
.metric-card.success::before, .metric-card.ok::before { background: var(--wa); }
.metric-card.warn::before { background: #f59e0b; }
.metric-card.danger::before { background: var(--danger); }
.metric-card strong { letter-spacing: -.05em; }
.control-item, .limit-card, .chat-item { border-radius: 12px; }
input, select, textarea { min-height: 43px; border-color: #cbd5e1; border-radius: 10px; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(23,105,224,.12); }
.btn { min-height: 40px; border-radius: 10px; padding: 10px 15px; box-shadow: 0 7px 15px rgba(23,105,224,.16); transition: transform .15s ease, filter .15s ease; }
.btn:hover { transform: translateY(-1px); filter: brightness(1.04); }
.btn.success { background: var(--wa); }
th { color: #52647b; background: #f7f9fc; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #f8fbff; }
.badge, .status-pill { letter-spacing: .015em; }

.login { position: relative; overflow: hidden; background: linear-gradient(135deg, #06182c 0%, #0c3156 58%, #0b6e67 120%); }
.login::before, .login::after { content: ""; position: absolute; border-radius: 50%; filter: blur(2px); }
.login::before { width: 420px; height: 420px; top: -190px; right: -90px; background: rgba(45,212,191,.16); }
.login::after { width: 350px; height: 350px; bottom: -220px; left: -80px; background: rgba(23,105,224,.23); }
.login .panel { z-index: 1; width: min(450px, 100%); padding: 34px; border: 1px solid rgba(255,255,255,.5); border-radius: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.version-chip { display: inline-flex; margin-bottom: 22px; padding: 6px 9px; border-radius: 999px; color: #075c44; background: #d9fff1; font-size: 10px; font-weight: 900; letter-spacing: .1em; }
.login-brand { margin-bottom: 26px; }
.login-brand img { width: 56px; height: 56px; padding: 9px; border: 1px solid var(--line); }
.login-brand strong { font-size: 22px; letter-spacing: -.03em; }
.login-submit { width: 100%; margin-top: 8px; background: linear-gradient(90deg, var(--blue), #075fcf); }

@media (max-width: 1000px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; padding: 17px; }
    .brand { margin-bottom: 15px; }
    .nav { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .nav a { text-align: center; padding: 9px 7px; font-size: 12px; }
    .nav a.active { box-shadow: inset 0 -3px var(--cyan); }
    .main { padding: 20px 16px 36px; }
}

@media (max-width: 560px) {
    .nav { display: flex; overflow-x: auto; padding-bottom: 5px; }
    .nav a { min-width: max-content; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .login .panel { padding: 25px 21px; border-radius: 18px; }
}
