/* ============================================================
   WhatsApp API Admin Dashboard — Shared CSS
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ── */
:root {
    --bg:           #0d1117;
    --bg-secondary: #161b22;
    --bg-card:      rgba(22, 27, 34, 0.85);
    --bg-hover:     rgba(255,255,255,0.04);
    --border:       rgba(255,255,255,0.08);
    --border-hover: rgba(255,255,255,0.16);

    --green:        #25D366;
    --green-dark:   #128C7E;
    --green-glow:   rgba(37,211,102,0.25);
    --green-light:  #34c759;

    --text:         #e6edf3;
    --text-muted:   #8b949e;
    --text-faint:   #484f58;

    --red:          #f85149;
    --red-bg:       rgba(248,81,73,0.12);
    --yellow:       #d29922;
    --yellow-bg:    rgba(210,153,34,0.12);
    --blue:         #58a6ff;
    --blue-bg:      rgba(88,166,255,0.12);

    --radius:       12px;
    --radius-sm:    8px;
    --radius-lg:    16px;
    --shadow:       0 8px 32px rgba(0,0,0,0.4);
    --shadow-sm:    0 2px 8px rgba(0,0,0,0.3);

    --sidebar-w:    260px;
    --header-h:     64px;
    --transition:   0.2s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, textarea, select { font-family: inherit; outline: none; }

/* ════════════════════════════════════════════════════
   AUTH (LOGIN) PAGE
   ════════════════════════════════════════════════════ */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
    background: radial-gradient(ellipse at 20% 50%, rgba(37,211,102,0.08) 0%, transparent 60%),
                radial-gradient(ellipse at 80% 20%, rgba(18,140,126,0.06) 0%, transparent 50%),
                var(--bg);
}

/* Animated background blobs */
.auth-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    animation: blobFloat 8s ease-in-out infinite;
    pointer-events: none;
}
.auth-blob-1 {
    width: 400px; height: 400px;
    background: rgba(37,211,102,0.07);
    top: -100px; left: -100px;
    animation-delay: 0s;
}
.auth-blob-2 {
    width: 300px; height: 300px;
    background: rgba(18,140,126,0.05);
    bottom: -80px; right: -80px;
    animation-delay: -4s;
}
@keyframes blobFloat {
    0%, 100% { transform: translate(0,0) scale(1); }
    33%       { transform: translate(30px,-20px) scale(1.05); }
    66%       { transform: translate(-20px,10px) scale(0.95); }
}

/* Grid pattern overlay */
.auth-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
}

.auth-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.auth-card {
    background: rgba(22,27,34,0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow), 0 0 0 1px rgba(37,211,102,0.05);
    animation: cardAppear 0.5s ease;
}
@keyframes cardAppear {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
    text-align: center;
    margin-bottom: 36px;
}
.auth-logo-icon {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    box-shadow: 0 8px 24px var(--green-glow);
}
.auth-logo-icon svg { width: 36px; height: 36px; fill: white; }
.auth-logo h1 {
    font-size: 22px; font-weight: 700;
    background: linear-gradient(135deg, #fff 0%, var(--text-muted) 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.auth-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* Form */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    font-size: 13px; font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}
.input-wrapper { position: relative; }
.input-wrapper input,
.form-control {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px 16px;
    font-size: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input-wrapper input:focus,
.form-control:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px var(--green-glow);
}
.input-wrapper input::placeholder,
.form-control::placeholder { color: var(--text-faint); }
.toggle-pwd {
    position: absolute;
    right: 12px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none;
    color: var(--text-muted); font-size: 16px;
    cursor: pointer; padding: 4px;
    transition: color var(--transition);
}
.toggle-pwd:hover { color: var(--text); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    transition: opacity 0.15s;
}
.btn:hover::after { opacity: 0.05; }
.btn:active::after { opacity: 0.1; }

.btn-primary {
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    color: white;
    box-shadow: 0 4px 16px var(--green-glow);
}
.btn-primary:hover { box-shadow: 0 6px 24px rgba(37,211,102,0.4); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-danger {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid rgba(248,81,73,0.2);
}
.btn-danger:hover { background: rgba(248,81,73,0.2); }

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-hover); background: rgba(255,255,255,0.06); }

.btn-ghost {
    background: none;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-hover); }

.btn-full { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* Error/Success Messages */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-top: 16px;
    display: flex; align-items: flex-start; gap: 10px;
    animation: fadeIn 0.3s ease;
}
.alert-error  { background: var(--red-bg);    color: var(--red);   border: 1px solid rgba(248,81,73,0.2); }
.alert-success{ background: rgba(37,211,102,0.1); color: var(--green); border: 1px solid rgba(37,211,102,0.2); }
.alert-info   { background: var(--blue-bg);   color: var(--blue);  border: 1px solid rgba(88,166,255,0.2); }
.alert-warning{ background: var(--yellow-bg); color: var(--yellow);border: 1px solid rgba(210,153,34,0.2); }
.hidden { display: none !important; }

@keyframes fadeIn { from { opacity:0; transform: translateY(-6px); } to { opacity:1; transform: none; } }

/* ════════════════════════════════════════════════════
   DASHBOARD LAYOUT
   ════════════════════════════════════════════════════ */

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

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 20px 0;
    margin-bottom: 8px;
}
.sidebar-brand-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px var(--green-glow);
}
.sidebar-brand-icon svg { width: 22px; height: 22px; fill: white; }
.sidebar-brand-text h2 { font-size: 15px; font-weight: 700; color: var(--text); }
.sidebar-brand-text span { font-size: 11px; color: var(--green); font-weight: 500; }

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

.sidebar-section-label {
    font-size: 10px; font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase; letter-spacing: 0.1em;
    padding: 0 20px;
    margin-bottom: 4px;
}

.sidebar-nav { flex: 1; padding: 0 12px; overflow-y: auto; }

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 400;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 2px;
    user-select: none;
    border: 1px solid transparent;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border); }
.nav-item.active {
    background: rgba(37,211,102,0.1);
    color: var(--green);
    border-color: rgba(37,211,102,0.2);
    font-weight: 500;
}
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item .nav-badge {
    margin-left: auto;
    background: var(--green);
    color: white;
    font-size: 10px; font-weight: 600;
    padding: 1px 6px;
    border-radius: 20px;
    min-width: 18px; text-align: center;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Header ── */
.top-header {
    height: var(--header-h);
    background: rgba(13,17,23,0.8);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center;
    padding: 0 32px;
    gap: 16px;
}
.header-title { font-size: 18px; font-weight: 600; flex: 1; }
.header-subtitle { font-size: 12px; color: var(--text-muted); font-weight: 400; display: block; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.server-status {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 14px;
    background: rgba(37,211,102,0.08);
    border: 1px solid rgba(37,211,102,0.2);
    border-radius: 20px;
    font-size: 12px; font-weight: 500;
    color: var(--green);
}
.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37,211,102,0.4); }
    50%       { box-shadow: 0 0 0 5px rgba(37,211,102,0); }
}

/* ── Page Content ── */
.page-body { padding: 32px; flex: 1; }

/* Sections */
.page-section { display: none; }
.page-section.active { display: block; animation: fadeIn 0.3s ease; }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
    overflow: hidden;
}
.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-body { padding: 24px; }
.card-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.1);
}

/* ── Stats Grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex; align-items: center; gap: 16px;
    transition: border-color var(--transition), transform var(--transition);
    backdrop-filter: blur(12px);
}
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon.green  { background: rgba(37,211,102,0.12); }
.stat-icon.red    { background: rgba(248,81,73,0.12); }
.stat-icon.blue   { background: rgba(88,166,255,0.12); }
.stat-icon.yellow { background: rgba(210,153,34,0.12); }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* ── Layout Grids ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── Users Table ── */
.table-wrapper { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead tr {
    border-bottom: 1px solid var(--border);
}
thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px; font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.08em;
    white-space: nowrap;
}
tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
td { padding: 14px 16px; vertical-align: middle; }

/* Status Badges */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px; font-weight: 600;
    white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-connected { background: rgba(37,211,102,0.12); color: var(--green); }
.badge-disconnected { background: var(--red-bg); color: var(--red); }
.badge-qr { background: var(--yellow-bg); color: var(--yellow); }
.badge-connecting { background: var(--blue-bg); color: var(--blue); }

/* API Key cell */
.api-key-cell {
    display: flex; align-items: center; gap: 8px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-muted);
}
.api-key-text {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Form layouts ── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}
select.form-control option { background: #1c2128; }

/* ── QR Code ── */
.qr-wrapper {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 32px;
    gap: 16px;
    min-height: 280px;
}
.qr-img-box {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.qr-img-box img { display: block; width: 220px; height: 220px; }
.qr-placeholder {
    width: 220px; height: 220px;
    background: rgba(255,255,255,0.04);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px;
    color: var(--text-muted); font-size: 13px;
}
.qr-hint { font-size: 12px; color: var(--text-muted); text-align: center; max-width: 240px; }

/* ── Toast Notifications ── */
#toast-container {
    position: fixed;
    top: 20px; right: 20px;
    z-index: 9999;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
    font-size: 13px; font-weight: 500;
    min-width: 280px; max-width: 400px;
    animation: toastIn 0.3s ease;
    border: 1px solid;
}
.toast.out { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn  { from { opacity:0; transform: translateX(40px); } to { opacity:1; transform: none; } }
@keyframes toastOut { from { opacity:1; transform: none; } to { opacity:0; transform: translateX(40px); } }
.toast-success { background: rgba(15,30,20,0.95); border-color: rgba(37,211,102,0.3); color: var(--green); }
.toast-error   { background: rgba(30,15,15,0.95); border-color: rgba(248,81,73,0.3);  color: var(--red); }
.toast-info    { background: rgba(15,20,30,0.95); border-color: rgba(88,166,255,0.3); color: var(--blue); }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-msg { flex: 1; color: var(--text); line-height: 1.4; }

/* ── Loading Spinner ── */
.spinner {
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    display: flex; align-items: center; justify-content: center;
    padding: 40px;
    color: var(--text-muted); font-size: 13px;
    gap: 12px;
}

/* ── Empty State ── */
.empty-state {
    padding: 60px 24px;
    text-align: center;
    color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-desc { font-size: 13px; line-height: 1.6; }

/* ── Sidebar Toggle (mobile) ── */
.sidebar-toggle {
    display: none;
    background: none; border: none;
    color: var(--text); font-size: 22px;
    cursor: pointer; padding: 4px;
}

/* ── Actions column ── */
.actions-cell { display: flex; gap: 6px; align-items: center; }

/* ── Section header ── */
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px;
}
.section-title { font-size: 22px; font-weight: 700; }
.section-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Mobile ── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 32px rgba(0,0,0,0.5);
    }
    .main-content { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .page-body { padding: 20px 16px; }
    .top-header { padding: 0 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 480px) { .stats-grid { grid-template-columns: 1fr; } }
