:root {
    --bg: #f0f2f5;
    --panel: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --primary: #25d366;
    --primary-dark: #1da851;
    --accent: #128c7e;
    --sidebar-bg: #1a1a2e;
    --sidebar-text: #c8d6e5;
    --sidebar-active: rgba(37, 211, 102, 0.15);
    --sidebar-hover: rgba(255,255,255,0.05);
    --sidebar-w: 240px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { padding: 16px; text-align: center; }

/* ===== Sidebar ===== */
.has-sidebar { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 50;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand-icon { font-size: 22px; }
.brand-name { font-weight: 700; font-size: 15px; color: #fff; }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section { margin-bottom: 8px; }
.nav-label {
    display: block; padding: 8px 20px 4px; font-size: 10px; text-transform: uppercase;
    letter-spacing: 1px; color: rgba(255,255,255,0.35); font-weight: 600;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 20px; font-size: 13px; color: var(--sidebar-text);
    border-radius: 0; transition: background .15s;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--sidebar-active); color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 14px; width: 16px; text-align: center; }
.ni { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.brand-svg { width: 18px; height: 18px; stroke: var(--primary); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 12px 16px;
}
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
    color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; }
.user-name { font-size: 13px; color: #fff; font-weight: 600; }
.user-role { font-size: 11px; color: rgba(255,255,255,0.45); }
.logout-link { font-size: 12px; opacity: .7; }
.logout-link:hover { opacity: 1; }

/* ===== Main content area ===== */
.has-sidebar .app-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
}

/* ===== Buttons ===== */
.btn-primary {
    background: var(--primary); color: #fff; border: none;
    padding: 10px 18px; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
    background: transparent; border: 1px solid var(--border); color: var(--text);
    padding: 7px 14px; border-radius: 8px; cursor: pointer;
}

/* ===== Auth ===== */
.auth-main { display: grid; place-items: center; min-height: 100vh; }
.auth-card {
    background: var(--panel); padding: 36px; border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0,0,0,.08); width: 360px;
}
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card form { margin-top: 20px; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 500; }
input, textarea, select {
    border: 1px solid var(--border); border-radius: 8px; padding: 10px;
    font-size: 14px; font-family: inherit; width: 100%; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.alert.error { background: #fee2e2; color: #b91c1c; }
.alert.ok { background: #dcfce7; color: #15803d; }

/* ===== Layout pages ===== */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 18px; }
.panel h3 { margin: 18px 0 10px; }
.panel form { display: grid; gap: 12px; max-width: 560px; }
h2 { margin-bottom: 14px; }

/* ===== Inbox ===== */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }
.conv-list { background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; }
.conv-search { padding: 12px; position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--border); }
.conv-item { display: flex; gap: 12px; padding: 12px; border-bottom: 1px solid var(--border); }
.conv-item:hover, .conv-item.active { background: #f0fdf4; }
.conv-avatar {
    width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff;
    display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; }
.conv-name { font-weight: 600; }
.conv-time { font-size: 11px; color: var(--muted); }
.conv-bottom { display: flex; justify-content: space-between; align-items: center; }
.conv-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--primary); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.tag { display: inline-block; margin-top: 4px; font-size: 10px; padding: 2px 8px; border-radius: 10px;
    background: color-mix(in srgb, var(--c) 15%, white); color: var(--c); font-weight: 600; }

/* ===== Chat ===== */
.chat-panel { display: flex; flex-direction: column; background: #efeae2; }
.chat-empty { display: grid; place-items: center; height: 100%; color: var(--muted); }
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--border); }
.chat-head-actions { display: flex; gap: 10px; align-items: center; }
.chat-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble { max-width: 70%; padding: 8px 12px; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); position: relative; line-height: 1.4; }
.msg.out .bubble { background: #d9fdd3; }
.msg-time { display: block; font-size: 10px; color: var(--muted); text-align: right; margin-top: 2px; }
.chat-input { display: flex; gap: 10px; padding: 12px; background: var(--panel); border-top: 1px solid var(--border); }
.chat-input textarea { resize: none; flex: 1; }

/* ===== Kanban ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 700; display: block; }
.stat-label { color: var(--muted); font-size: 12px; }
.kanban { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.kanban-col { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.kanban-head { padding: 10px 12px; font-weight: 700; border-top: 3px solid var(--c); display: flex; justify-content: space-between; }
.kanban-head .count { background: var(--bg); border-radius: 10px; padding: 0 8px; font-size: 12px; }
.kanban-cards { padding: 10px; display: grid; gap: 8px; min-height: 60px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: grid; gap: 2px; }
.card:hover { border-color: var(--primary); }
.attr { font-size: 11px; color: var(--accent); }

/* ===== Contact ===== */
.back { display: inline-block; margin-bottom: 14px; color: var(--accent); }
.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.kv td:first-child { color: var(--muted); width: 40%; }
.timeline { list-style: none; margin-top: 14px; display: grid; gap: 10px; }
.timeline li { background: #f8fafc; padding: 10px; border-radius: 8px; }
.hint { background: #f0fdf4; border: 1px dashed var(--primary); border-radius: 8px; padding: 12px; word-break: break-all; }
.hint code { font-size: 12px; }
.template-list { list-style: none; display: grid; gap: 8px; margin-bottom: 16px; }
.template-list li { background: #f8fafc; padding: 10px; border-radius: 8px; }

/* ===== Quick replies ===== */
.quick-replies { position: relative; }
.qr-toggle { background: #fff; border: 1px solid var(--border); border-radius: 8px; width: 42px; cursor: pointer; font-size: 18px; }
.qr-toggle:hover { background: var(--bg); }
.qr-menu { display: none; position: absolute; bottom: 50px; left: 0; width: 240px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); overflow: hidden; z-index: 10; }
.qr-menu.open { display: block; }
.qr-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.qr-item:hover { background: #f0fdf4; }

/* ===== Settings / Users ===== */
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.users-table th { text-align: left; padding: 6px 0; color: var(--muted); font-size: 12px; }
.users-table td { vertical-align: middle; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .inline { display: flex; gap: 6px; align-items: center; margin: 0; }
.row-actions input[type=password] { width: 130px; padding: 6px 8px; }
.btn-ghost.danger { color: #b91c1c; border-color: #fecaca; }
.btn-ghost.danger:hover { background: #fee2e2; }

/* ===== Auth link ===== */
.auth-link { text-align: center; margin-top: 16px; font-size: 13px; }
.auth-link a { color: var(--accent); font-weight: 600; }
.auth-link a:hover { text-decoration: underline; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .sidebar { width: 60px; }
    .sidebar .brand-name, .sidebar .nav-label, .sidebar .user-meta, .sidebar .logout-link span:not(.nav-icon) { display: none; }
    .sidebar .nav-item { justify-content: center; padding: 12px; }
    .has-sidebar .app-main { margin-left: 60px; }
    .inbox { grid-template-columns: 1fr; }
    .stats, .kanban { grid-template-columns: 1fr 1fr; }
    .contact-grid { grid-template-columns: 1fr; }
}


/* ===== Media ===== */
.media-grid { display: grid; gap: 12px; }
.media-item { display: flex; align-items: center; gap: 14px; padding: 10px; background: #f8fafc; border-radius: 10px; }
.media-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.media-icon { width: 56px; height: 56px; display: grid; place-items: center; background: var(--bg); border-radius: 8px; font-size: 24px; }
.media-info { flex: 1; min-width: 0; }
.media-name { display: block; font-weight: 600; font-size: 13px; }
.media-actions { display: flex; gap: 6px; }

/* ===== Template cards ===== */
.template-cards { display: grid; gap: 10px; }
.template-card { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.template-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

/* ===== Billing ===== */
.billing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.plan-badge { display: inline-block; font-size: 18px; font-weight: 700; margin-bottom: 10px; padding: 6px 16px; border-radius: 8px; background: color-mix(in srgb, var(--primary) 15%, white); color: var(--primary); }
.plans-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.plan-card { border: 1px solid var(--border); border-radius: 12px; padding: 20px; text-align: center; }
.plan-card.current { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, white); }
.plan-card h4 { font-size: 18px; margin-bottom: 6px; }
.plan-price { font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.plan-price span { font-size: 13px; font-weight: 400; color: var(--muted); }
.plan-card ul { list-style: none; text-align: left; font-size: 13px; margin-bottom: 14px; }
.plan-card ul li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.plan-card ul li::before { content: "✓ "; color: var(--primary); font-weight: 700; }

@media (max-width: 900px) {
    .billing-grid, .plans-grid { grid-template-columns: 1fr; }
}


/* ===== WhatsApp connection page ===== */
.wa-status-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.wa-account-info { display: flex; align-items: center; gap: 14px; }
.wa-avatar { width: 48px; height: 48px; background: #25d366; border-radius: 50%; display: grid; place-items: center; font-size: 22px; }
.wa-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.wa-info-card { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.wa-info-card h4 { margin-bottom: 8px; }
.wa-phone { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.wa-tags { display: flex; gap: 6px; margin-bottom: 10px; }
.wa-connect-prompt { padding: 30px; text-align: center; background: #f8fafc; border-radius: 10px; }
.link { color: var(--accent); text-decoration: underline; }
@media (max-width: 900px) { .wa-info-grid { grid-template-columns: 1fr; } }


/* ===== Automation page (kirim.chat style) ===== */
.automation-page .page { max-width: 1200px; }
.auto-layout { display: grid; grid-template-columns: 200px 1fr; gap: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; min-height: 500px; }
.auto-sidebar { border-right: 1px solid var(--border); padding: 12px 0; }
.auto-nav { display: flex; align-items: center; gap: 10px; padding: 11px 18px; font-size: 13px; color: var(--text); }
.auto-nav:hover { background: var(--bg); }
.auto-nav.active { background: rgba(37,211,102,.08); color: var(--primary); font-weight: 600; border-left: 3px solid var(--primary); }
.auto-content { padding: 24px; }
.auto-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.auto-info { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; margin-bottom: 18px; }
.auto-info code { background: #e2e8f0; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

/* QR cards (template/keyword items) */
.qr-card { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; }
.qr-card-left { min-width: 140px; }
.qr-shortcut { display: inline-block; background: #10b981; color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 4px; font-weight: 600; margin-bottom: 4px; }
.qr-card-body { flex: 1; color: var(--muted); font-size: 13px; }
.qr-card-actions { display: flex; gap: 6px; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; border-radius: 6px; }
.icon-btn:hover { background: #fee2e2; }

/* Tags list */
.tags-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.tag-item { display: flex; align-items: center; gap: 6px; background: #f8fafc; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); }

@media (max-width: 768px) {
    .auto-layout { grid-template-columns: 1fr; }
    .auto-sidebar { display: flex; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 0; }
    .auto-nav { white-space: nowrap; border-left: none !important; }
    .auto-nav.active { border-bottom: 2px solid var(--primary); border-left: none !important; }
}
