/* =========================================================
   WaConnect — Modern WhatsApp Business API Portal Theme
   ========================================================= */

:root {
    --wa-green: #25D366;
    --wa-green-dark: #1DA851;
    --wa-teal: #128C7E;
    --wa-dark: #0B141A;
    --bg: #F4F7F6;
    --surface: #FFFFFF;
    --surface-2: #F0F2F5;
    --border: #E6E9EC;
    --text: #1B2430;
    --text-muted: #6B7785;
    --danger: #E5484D;
    --warning: #F5A524;
    --info: #3B82F6;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.12);
    --sidebar-w: 260px;
    --topbar-h: 68px;
    --grad: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cfd6db; border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------- Auth pages ---------------------------- */

.auth-wrap {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
}

@media (max-width: 900px) {
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
}

.auth-visual {
    background: var(--grad);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 60px;
    color: #fff;
}

.auth-visual::before,
.auth-visual::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.08);
}
.auth-visual::before { width: 380px; height: 380px; top: -120px; right: -100px; }
.auth-visual::after { width: 260px; height: 260px; bottom: -80px; left: -60px; }

.auth-visual h1 {
    font-size: 34px;
    font-weight: 800;
    max-width: 420px;
    line-height: 1.3;
    z-index: 1;
}
.auth-visual p { opacity: 0.9; max-width: 380px; z-index: 1; font-size: 15px; }
.auth-visual .chat-mock {
    z-index: 1;
    margin-top: 32px;
    background: rgba(255,255,255,0.14);
    backdrop-filter: blur(6px);
    border-radius: var(--radius);
    padding: 18px;
    max-width: 340px;
}
.auth-visual .bubble {
    background: #fff;
    color: var(--text);
    padding: 10px 14px;
    border-radius: 12px 12px 12px 2px;
    font-size: 13px;
    margin-bottom: 10px;
    max-width: 80%;
    box-shadow: var(--shadow-sm);
}
.auth-visual .bubble.me {
    background: #DCF8C6;
    margin-left: auto;
    border-radius: 12px 12px 2px 12px;
}

.auth-form-side {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-card .logo .mark {
    width: 42px; height: 42px; border-radius: 12px; background: var(--grad);
    display: flex; align-items: center; justify-content: center; color: #fff; font-size: 20px;
}
.auth-card .logo span { font-weight: 800; font-size: 20px; }

.auth-card h2 { font-size: 24px; font-weight: 800; margin: 0 0 6px; }
.auth-card .sub { color: var(--text-muted); margin: 0 0 28px; font-size: 14.5px; }

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 14.5px;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--wa-green);
    box-shadow: 0 0 0 4px rgba(37, 211, 102, 0.14);
}
textarea.form-control { resize: vertical; min-height: 90px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    font-weight: 700;
    font-size: 14.5px;
    transition: transform .1s, box-shadow .15s, opacity .15s, background .15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 18px rgba(37,211,102,0.28); }
.btn-primary:hover { opacity: 0.92; }
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { background: #e5e9ec; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-icon { padding: 8px; border-radius: 10px; background: var(--surface-2); }
.btn-icon:hover { background: #e3e7ea; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-foot { text-align: center; margin-top: 22px; font-size: 14px; color: var(--text-muted); }
.auth-foot a { color: var(--wa-teal); font-weight: 700; }

.alert {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-success { background: #E9FBF0; color: #0F7A3D; border: 1px solid #BEEED0; }
.alert-error { background: #FDEEEE; color: #C0272B; border: 1px solid #F6C6C7; }
.alert-info { background: #EAF3FF; color: #1D5FC2; border: 1px solid #C9E0FF; }

/* ------------------------------ App shell ------------------------------ */

.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--wa-dark);
    color: #E9EEF1;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform .25s ease;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 22px 18px;
}
.sidebar .brand .mark {
    width: 38px; height: 38px; border-radius: 11px; background: var(--grad);
    display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.sidebar .brand span { font-weight: 800; font-size: 18px; color: #fff; }

.sidebar nav { flex: 1; padding: 10px 14px; overflow-y: auto; }
.sidebar .nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6B7785; padding: 16px 12px 8px; }
.sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 14.5px;
    font-weight: 600;
    color: #C7D0D6;
    margin-bottom: 3px;
    transition: background .15s, color .15s;
}
.sidebar .nav-item i, .sidebar .nav-item .ico { width: 19px; text-align: center; font-size: 15px; }
.sidebar .nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar .nav-item.active { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(37,211,102,0.28); }
.sidebar .nav-item .badge-count {
    margin-left: auto; background: rgba(255,255,255,0.15); font-size: 11px; padding: 1px 7px; border-radius: 20px;
}

.sidebar .user-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--grad); color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.sidebar .user-box .name { font-size: 13.5px; font-weight: 700; color: #fff; }
.sidebar .user-box .role { font-size: 11.5px; color: #8A96A0; }
.sidebar .user-box a.logout { margin-left: auto; color: #8A96A0; font-size: 16px; }
.sidebar .user-box a.logout:hover { color: #fff; }

.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 26px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar h1 { font-size: 19px; font-weight: 800; margin: 0; }
.topbar .actions { display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; color: var(--text); }

.status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12.5px; font-weight: 700; padding: 6px 12px; border-radius: 20px;
}
.status-pill.on { background: #E9FBF0; color: #0F7A3D; }
.status-pill.off { background: #FDEEEE; color: #C0272B; }
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.content { padding: 26px; flex: 1; }

/* ------------------------------- Cards -------------------------------- */

.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px; }
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 15.5px; font-weight: 800; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
    margin-bottom: 22px;
}
@media (max-width: 1100px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .stats-grid { grid-template-columns: 1fr; } }

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.stat-card .ico {
    width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: #fff; margin-bottom: 14px;
}
.stat-card .val { font-size: 26px; font-weight: 800; }
.stat-card .lbl { font-size: 13px; color: var(--text-muted); font-weight: 600; margin-top: 2px; }
.stat-card .trend { font-size: 12px; font-weight: 700; margin-top: 10px; display: inline-flex; gap: 4px; align-items: center; }
.trend.up { color: #0F7A3D; }
.trend.down { color: #C0272B; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ------------------------------- Tables -------------------------------- */

table.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); padding: 12px 22px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 14px 22px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #FAFBFC; }

.chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 700;
}
.chip-green { background: #E9FBF0; color: #0F7A3D; }
.chip-gray { background: #EEF1F3; color: #5A6673; }
.chip-red { background: #FDEEEE; color: #C0272B; }
.chip-blue { background: #EAF3FF; color: #1D5FC2; }
.chip-yellow { background: #FEF6E7; color: #97650E; }

.table-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 18px 22px; flex-wrap: wrap;
}
.search-box { position: relative; flex: 1; min-width: 220px; max-width: 340px; }
.search-box i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; }
.search-box input { padding-left: 36px; }

.row-actions { display: flex; gap: 8px; }
.row-actions button, .row-actions a { border: none; background: var(--surface-2); width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 13px; }
.row-actions button:hover, .row-actions a:hover { background: #e3e7ea; color: var(--text); }
.row-actions .del:hover { background: #FDEEEE; color: var(--danger); }

/* ------------------------------- Modal -------------------------------- */

.modal-overlay {
    position: fixed; inset: 0; background: rgba(11,20,26,0.5); display: none;
    align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 480px;
    box-shadow: var(--shadow-lg); max-height: 90vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16.5px; font-weight: 800; }
.modal-head .close-modal { background: none; border: none; font-size: 20px; color: var(--text-muted); }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ------------------------------- Toasts -------------------------------- */

#toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: var(--surface); border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow-lg);
    display: flex; align-items: center; gap: 10px; min-width: 260px; border-left: 4px solid var(--wa-green);
    animation: slideIn .25s ease;
    font-size: 13.5px; font-weight: 600;
}
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------------------------- Conversations ---------------------------- */

.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - var(--topbar-h) - 52px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; } }

.chat-list { border-right: 1px solid var(--border); overflow-y: auto; }
.chat-list-item {
    display: flex; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); align-items: center;
}
.chat-list-item:hover, .chat-list-item.active { background: var(--surface-2); cursor: pointer; }
.chat-list-item .meta { flex: 1; min-width: 0; }
.chat-list-item .meta .top { display: flex; justify-content: space-between; }
.chat-list-item .name { font-weight: 700; font-size: 14px; }
.chat-list-item .time { font-size: 11px; color: var(--text-muted); }
.chat-list-item .preview { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; }
.chat-pane-head { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px;
    background: #E5EFEA url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ccircle cx='30' cy='30' r='1' fill='%23ffffff' fill-opacity='0.4'/%3E%3C/svg%3E");
    display: flex; flex-direction: column; gap: 10px;
}
.msg-bubble { max-width: 65%; padding: 10px 14px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-sm); line-height: 1.45; }
.msg-bubble.in { background: #fff; border-radius: 12px 12px 12px 2px; align-self: flex-start; }
.msg-bubble.out { background: #DCF8C6; border-radius: 12px 12px 2px 12px; align-self: flex-end; }
.msg-bubble .meta-line { font-size: 10.5px; color: var(--text-muted); margin-top: 5px; text-align: right; }

.chat-input-bar { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); }
.chat-input-bar input { flex: 1; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); text-align: center; padding: 40px; }
.empty-state .ico { font-size: 46px; margin-bottom: 14px; opacity: .5; }

/* ------------------------------ Misc UI -------------------------------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 22px; }
.tab-btn { padding: 14px 6px; margin-right: 22px; font-weight: 700; font-size: 14px; color: var(--text-muted); border-bottom: 2.5px solid transparent; }
.tab-btn.active { color: var(--wa-teal); border-color: var(--wa-green); }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-toggle { position: absolute; cursor: pointer; inset: 0; background: #cfd6db; border-radius: 24px; transition: .2s; }
.slider-toggle::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .2s; }
input:checked + .slider-toggle { background: var(--wa-green); }
input:checked + .slider-toggle::before { transform: translateX(18px); }

.helper-text { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }

.page-actions { display: flex; gap: 10px; }

.template-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; background: var(--surface-2); }
.template-card .name { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.template-card .body-text { font-size: 13px; color: var(--text-muted); background: #fff; border-radius: 8px; padding: 10px; border: 1px solid var(--border); }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
