/* ============================================
   SMS PANEL PRO - Complete Stylesheet
   Dark/Light Mode + Responsive
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---- Dark Theme (Default) ---- */
:root, [data-theme="dark"] {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2035;
    --bg-card-hover: #1f2847;
    --bg-input: #0f1629;
    --border-color: #1e2a42;
    --border-accent: #2d3a55;
    --text-primary: #e2e8f0;
    --text-secondary: #8892a4;
    --text-muted: #4a5568;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.15);
    --success: #10b981; --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b; --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;  --danger-bg: rgba(239, 68, 68, 0.1);
    --info: #06b6d4;    --info-bg: rgba(6, 182, 212, 0.1);
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

/* ---- Light Theme ---- */
[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f8f9fa;
    --bg-input: #f0f2f5;
    --border-color: #e2e8f0;
    --border-accent: #cbd5e1;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #a0aec0;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.1);
    --success: #059669; --success-bg: rgba(5, 150, 105, 0.08);
    --warning: #d97706; --warning-bg: rgba(217, 119, 6, 0.08);
    --danger: #dc2626;  --danger-bg: rgba(220, 38, 38, 0.08);
    --info: #0891b2;    --info-bg: rgba(8, 145, 178, 0.08);
    --shadow: 0 1px 10px rgba(0,0,0,0.08);
}

/* ---- Common Vars ---- */
:root {
    --sidebar-width: 260px;
    --header-height: 60px;
    --radius: 10px;
    --radius-sm: 6px;
    --transition: all 0.2s ease;
    --font-body: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: var(--font-body); background: var(--bg-primary); color: var(--text-primary); line-height: 1.6; overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-hover); }

/* ---- Layout ---- */
.app-wrapper { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width); background: var(--bg-secondary); border-right: 1px solid var(--border-color);
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 200; display: flex; flex-direction: column; transition: transform 0.3s ease;
}
.sidebar-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; gap: 12px; }
.sidebar-logo { width: 36px; height: 36px; background: linear-gradient(135deg, var(--accent), #8b5cf6); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; color: #fff; flex-shrink: 0; }
.sidebar-brand { font-weight: 700; font-size: 17px; letter-spacing: -0.3px; flex: 1; }
.sidebar-brand small { display: block; font-size: 10px; color: var(--text-muted); font-weight: 400; letter-spacing: 1px; text-transform: uppercase; }
.sidebar-close { display: none; background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; padding: 4px; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section { margin-bottom: 20px; }
.nav-section-title { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-muted); padding: 0 12px; margin-bottom: 6px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 9px 14px; border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px; font-weight: 500; transition: var(--transition); }
.nav-item:hover { background: var(--accent-glow); color: var(--text-primary); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); font-weight: 600; border-left: 3px solid var(--accent); }
.nav-item i { width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border-color); }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user-avatar { width: 34px; height: 34px; background: linear-gradient(135deg, var(--accent), #8b5cf6); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; color: #fff; flex-shrink: 0; }
.sidebar-user-info { overflow: hidden; }
.sidebar-user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--text-muted); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 150; }
.sidebar-overlay.show { display: block; }

/* ---- Main Content ---- */
.main-content { flex: 1; margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }
.top-header { height: var(--header-height); padding: 0 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-color); background: var(--bg-secondary); position: sticky; top: 0; z-index: 50; }
.page-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-balance { background: var(--bg-card); padding: 6px 14px; border-radius: var(--radius-sm); font-size: 12px; color: var(--text-secondary); border: 1px solid var(--border-color); }
.header-balance strong { color: var(--success); font-family: var(--font-mono); }
.sidebar-toggle { display: none; }
.content-area { padding: 24px; flex: 1; }
.page-footer {
    text-align: center;
    padding: 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    margin-top: auto;
}

/* ---- Notifications ---- */
.notif-wrapper { position: relative; }
.notif-btn { position: relative; }
.notif-badge { position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.notif-panel { display: none; position: absolute; top: calc(100% + 8px); right: 0; width: 340px; max-height: 420px; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; z-index: 200; }
.notif-panel.show { display: block; }
.notif-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border-color); font-size: 13px; }
.notif-panel-body { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border-color); cursor: pointer; transition: var(--transition); }
.notif-item:hover { background: var(--bg-card-hover); }
.notif-item.unread { background: var(--accent-glow); }
.notif-icon { font-size: 16px; margin-top: 2px; }
.notif-info { color: var(--info); }
.notif-success { color: var(--success); }
.notif-warning { color: var(--warning); }
.notif-danger { color: var(--danger); }
.notif-content { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: 12px; }
.notif-msg { font-size: 11px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-time { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.notif-empty { padding: 40px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---- Cards ---- */
.card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); overflow: hidden; }
.card-header { padding: 16px 22px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 22px; }
.card-footer { padding: 14px 22px; border-top: 1px solid var(--border-color); }

/* ---- Stats Grid ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 20px; position: relative; overflow: hidden; }
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.stat-card.blue::before { background: var(--accent); }
.stat-card.green::before { background: var(--success); }
.stat-card.red::before { background: var(--danger); }
.stat-card.orange::before { background: var(--warning); }
.stat-card.cyan::before { background: var(--info); }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; font-family: var(--font-mono); letter-spacing: -1px; }
.stat-change { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.stat-icon { position: absolute; top: 18px; right: 18px; font-size: 20px; opacity: 0.3; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: 1px solid transparent; border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 13px; font-weight: 500; cursor: pointer; transition: var(--transition); white-space: nowrap; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; color: var(--text-secondary); border-color: var(--border-color); }
.btn-outline:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 14px; }
.btn-block { width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.theme-toggle { font-size: 14px; }
.lang-switch .btn { font-size: 12px; letter-spacing: 0.3px; }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-bottom: 6px; }
.form-control { width: 100%; padding: 10px 14px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-primary); font-family: var(--font-body); font-size: 13px; transition: var(--transition); }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: auto; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-hint code { background: var(--bg-input); padding: 1px 5px; border-radius: 3px; font-family: var(--font-mono); font-size: 11px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.input-group { display: flex; gap: 6px; }
.input-group .form-control { flex: 1; }
.char-counter { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 6px; }

/* ---- Tables ---- */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); border-bottom: 1px solid var(--border-color); white-space: nowrap; }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); }
tbody tr:hover { background: var(--bg-card-hover); }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 50px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-secondary { background: rgba(100,116,139,0.1); color: var(--text-secondary); }
.badge-dark { background: rgba(0,0,0,0.2); color: var(--text-muted); }

/* ---- Alerts ---- */
.alert { padding: 12px 18px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(16,185,129,0.2); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(6,182,212,0.2); }

/* ---- Modals ---- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 300; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.show { display: flex; }
.modal { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { padding: 16px 22px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 24px; cursor: pointer; line-height: 1; }
.modal-body { padding: 22px; }

/* ---- Login Page ---- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--bg-primary); }
.login-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 36px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 22px; font-weight: 700; margin-top: 12px; }
.login-logo p { color: var(--text-muted); font-size: 13px; }
.login-logo .sidebar-logo { margin: 0 auto; }

/* ---- Validation Result ---- */
.validation-result { background: var(--bg-input); border-radius: var(--radius-sm); padding: 16px; margin-top: 12px; }
.validation-result.valid { border-left: 3px solid var(--success); }
.validation-result.invalid { border-left: 3px solid var(--danger); }
.validation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.validation-item label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; display: block; }
.validation-item span { font-size: 13px; font-weight: 500; }

/* ---- Pagination ---- */
.pagination { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.pagination a { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); font-size: 12px; color: var(--text-secondary); border: 1px solid var(--border-color); }
.pagination a:hover { background: var(--bg-card-hover); }
.pagination a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- Empty State ---- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state i { font-size: 40px; opacity: 0.3; margin-bottom: 12px; display: block; }
.empty-state h3 { font-size: 16px; margin-bottom: 6px; color: var(--text-secondary); }
.empty-state p { font-size: 13px; }

/* ---- Animations ---- */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fa-spin { animation: fa-spin 1s linear infinite; }
@keyframes fa-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ============================================
   RESPONSIVE TABLES (Card view on mobile)
   ============================================ */

.rtable-mobile {
    display: none;
}
.rtable-mobile .rtable-card {
    border-bottom: 1px solid var(--border-color);
}
.rtable-mobile .rtable-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 10px;
    cursor: pointer;
    transition: var(--transition);
}
.rtable-mobile .rtable-header:active {
    background: var(--bg-card-hover);
}
.rtable-mobile .rtable-toggle {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--success-bg);
    color: var(--success);
    border: none;
    font-size: 18px;
    font-weight: 400;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: var(--transition);
}
.rtable-mobile .rtable-toggle.open {
    background: var(--danger-bg);
    color: var(--danger);
}
.rtable-mobile .rtable-summary {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.rtable-mobile .rtable-summary-cell {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 500;
}
.rtable-mobile .rtable-summary-cell:first-child {
    flex-shrink: 0;
}
.rtable-mobile .rtable-detail {
    display: none;
    padding: 0 16px 14px 54px;
}
.rtable-mobile .rtable-detail.show {
    display: block;
}
.rtable-mobile .rtable-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}
.rtable-mobile .rtable-detail-row:last-child {
    border-bottom: none;
}
.rtable-mobile .rtable-detail-label {
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 11px;
    flex-shrink: 0;
    padding-right: 12px;
}
.rtable-mobile .rtable-detail-value {
    text-align: right;
    font-size: 13px;
    max-width: 65%;
    word-break: break-word;
}
.rtable-mobile .rtable-empty {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================
   RESPONSIVE MOBILE
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close {
        display: block;
    }
    .sidebar-toggle {
        display: flex !important;
    }
    .main-content {
        margin-left: 0;
    }
    .top-header {
        padding: 0 12px;
        height: 52px;
    }
    .page-title {
        font-size: 15px;
    }
    .header-actions {
        gap: 4px;
    }
    .header-balance {
        display: none;
    }
    .content-area {
        padding: 12px;
    }

    /* Stats responsive - compact rows */
    .stats-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
    }
    .stat-card {
        padding: 10px 14px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .stat-card::before {
        right: auto;
        width: 3px;
        height: 100%;
        top: 0;
        bottom: 0;
    }
    .stat-value {
        font-size: 18px;
        order: 2;
    }
    .stat-label {
        font-size: 11px;
        margin-bottom: 0;
        order: 1;
    }
    .stat-icon {
        display: none;
    }
    .stat-change {
        display: none;
    }

    /* Form rows stack */
    .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    /* Grid layouts stack (NOT stats-grid) */
    [style*="grid-template-columns"]:not(.stats-grid) {
        display: grid !important;
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns"]:not(.stats-grid) > * {
        margin-bottom: 12px;
    }

    /* Cards smaller */
    .card {
        border-radius: 8px;
    }
    .card-body {
        padding: 14px;
    }
    .card-header {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .card-title {
        font-size: 14px;
    }

    /* Responsive tables: show card view, hide original */
    .rtable-mobile {
        display: block !important;
    }
    .rtable-desktop {
        display: none !important;
    }
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* API docs code blocks */
    .api-code-block pre,
    pre {
        font-size: 11px !important;
        white-space: pre-wrap !important;
        word-break: break-all !important;
    }
    code {
        font-size: 11px !important;
        word-break: break-all;
    }

    /* Notifications panel */
    .notif-panel {
        position: fixed;
        top: 52px;
        right: 0; left: 0;
        width: 100%;
        max-height: calc(100vh - 52px);
        border-radius: 0;
    }

    /* Buttons */
    .btn-group {
        flex-direction: column;
    }
    .btn-lg {
        width: 100%;
        justify-content: center;
    }

    /* Action bars */
    [style*="display:flex"][style*="justify-content:space-between"],
    [style*="display: flex"][style*="justify-content: space-between"] {
        flex-direction: column !important;
        gap: 10px !important;
        align-items: stretch !important;
    }

    /* Code blocks */
    code, pre {
        font-size: 11px !important;
        word-break: break-all;
    }

    /* Modals */
    .modal {
        max-width: 100%;
        margin: 0;
        border-radius: 12px 12px 0 0;
        max-height: 85vh;
    }
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    /* Login */
    .login-card {
        padding: 24px 20px;
    }
    .login-logo h1 {
        font-size: 19px;
    }

    /* Badge */
    .badge {
        font-size: 10px;
        padding: 2px 7px;
    }

    /* Filter tabs/buttons horizontal scroll */
    .filter-tabs {
        display: flex;
        overflow-x: auto;
        gap: 6px;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }
    .filter-tabs .btn {
        flex-shrink: 0;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .stat-value {
        font-size: 16px;
    }
    .stat-label {
        font-size: 10px;
    }
}

/* ---- SweetAlert2 Custom Theme ---- */
.swal2-popup {
    font-family: var(--font-body) !important;
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}
.swal2-title { color: var(--text-primary) !important; }
.swal2-html-container { color: var(--text-secondary) !important; }
