/* ============ CSS Variables & Reset ============ */
:root {
    --bg-primary: #080C14;
    --bg-secondary: #0F1724;
    --bg-card: rgba(30, 41, 59, 0.3);
    --bg-card-hover: rgba(30, 41, 59, 0.5);
    --bg-sidebar: #0B1120;
    --border: #1E293B;
    --accent: #2DD4BF;
    --accent-dark: #0D9488;
    --accent-gradient: linear-gradient(135deg, #0D9488, #06B6D4);
    --text-primary: #E2E8F0;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --text-dim: #475569;
    --text-dark: #334155;
    --success: #22C55E;
    --warning: #F59E0B;
    --danger: #EF4444;
    --purple: #818CF8;
    --font: 'Inter', -apple-system, 'PingFang SC', 'Noto Sans SC', sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: var(--font); }
input, select { font-family: var(--font); }

/* ============ Utility ============ */
.hidden { display: none !important; }

/* ============ Login Page ============ */
.login-container {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--bg-sidebar) 0%, var(--bg-secondary) 50%, #0D1A2D 100%);
    position: relative; overflow: hidden;
}
.login-container::before {
    content: ''; position: absolute; width: 500px; height: 500px; border-radius: 50%;
    background: radial-gradient(circle, rgba(13,148,136,0.08) 0%, transparent 70%);
    top: -100px; right: -100px;
}
.login-card {
    width: 400px; max-width: 90vw; padding: 48px 40px; border-radius: 24px;
    background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(20px);
    border: 1px solid rgba(45, 212, 191, 0.1); z-index: 1;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo {
    width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 16px;
    background: var(--accent-gradient); display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 32px rgba(13, 148, 136, 0.3);
}
.login-logo svg { width: 28px; height: 28px; }
.login-title { text-align: center; font-size: 28px; font-weight: 700; color: #fff; }
.login-subtitle { text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 36px; }
.login-error {
    display: none; padding: 10px 16px; border-radius: var(--radius-sm); margin-bottom: 16px;
    background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger); font-size: 13px;
}
.login-error.show { display: block; }

/* ============ Form Elements ============ */
.input-group { width: 100%; margin-bottom: 16px; position: relative; }
.input-group svg {
    position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
    width: 18px; height: 18px; color: var(--text-dim); pointer-events: none;
}
.input-field {
    width: 100%; padding: 14px 16px 14px 48px; border-radius: var(--radius);
    border: 1px solid var(--border); background: rgba(15, 23, 42, 0.8);
    color: var(--text-primary); font-size: 15px; outline: none; transition: border-color 0.3s;
}
.input-field:focus { border-color: var(--accent); }
.input-field::placeholder { color: var(--text-dim); }
.btn-primary {
    width: 100%; padding: 14px; border-radius: var(--radius); border: none;
    background: var(--accent-gradient); color: #fff;
    font-size: 16px; font-weight: 600; transition: opacity 0.3s;
    box-shadow: 0 4px 20px rgba(13, 148, 136, 0.3);
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

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

/* Sidebar */
.sidebar {
    width: 240px; background: var(--bg-sidebar); border-right: 1px solid var(--border);
    padding: 20px 0; flex-shrink: 0; display: flex; flex-direction: column;
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    transition: transform 0.3s;
}
.sidebar-logo { padding: 0 20px 24px; display: flex; align-items: center; gap: 10px; }
.sidebar-logo .mini-logo {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    background: var(--accent-gradient); display: flex; align-items: center; justify-content: center;
}
.sidebar-logo .mini-logo svg { width: 16px; height: 16px; }
.sidebar-logo span { font-size: 18px; font-weight: 700; color: #fff; }
.sidebar-badge {
    margin: 0 20px 16px; display: inline-block;
    font-size: 11px; color: var(--warning); background: rgba(245,158,11,0.1);
    padding: 3px 10px; border-radius: 20px; width: fit-content;
}
.sidebar-nav { flex: 1; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px; padding: 12px 20px;
    color: var(--text-muted); font-size: 14px; transition: all 0.2s;
    border-right: 3px solid transparent;
}
.sidebar-nav a:hover { color: var(--text-primary); background: var(--bg-card); }
.sidebar-nav a.active { color: var(--accent); background: rgba(13, 148, 136, 0.1); border-right-color: var(--accent); }
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-user {
    padding: 16px 20px; border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, #6366F1, #8B5CF6);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; color: #fff; flex-shrink: 0;
}
.sidebar-user .info { flex: 1; min-width: 0; }
.sidebar-user .info .name { font-size: 13px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .info .role { font-size: 11px; color: var(--text-muted); }
.sidebar-user .logout-btn {
    background: none; border: none; color: var(--text-muted); padding: 4px;
    transition: color 0.2s;
}
.sidebar-user .logout-btn:hover { color: var(--danger); }
.sidebar-user .logout-btn svg { width: 16px; height: 16px; }

/* Main */
.main-content { flex: 1; padding: 24px; margin-left: 240px; min-height: 100vh; }
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.top-bar h2 { font-size: 20px; color: #fff; }
.top-bar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.search-box {
    padding: 8px 16px 8px 36px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-sidebar);
    color: var(--text-primary); font-size: 13px; width: 240px; outline: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23475569' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 10-1.397 1.398h-.001l3.85 3.85a1 1 0 001.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 110-10 5 5 0 010 10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: 12px center;
    transition: border-color 0.3s;
}
.search-box:focus { border-color: var(--accent); }
.filter-select {
    padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--bg-sidebar); color: var(--text-secondary); font-size: 13px; outline: none;
}

/* ============ SMS List ============ */
.sms-list { display: flex; flex-direction: column; gap: 8px; }
.sms-item {
    padding: 16px 20px; border-radius: var(--radius); background: var(--bg-card);
    border: 1px solid var(--border); transition: all 0.2s; cursor: default;
}
.sms-item:hover { border-color: rgba(45, 212, 191, 0.2); background: var(--bg-card-hover); }
.sms-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sms-sender { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.sms-time { font-size: 12px; color: var(--text-dim); }
.sms-content { font-size: 13px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 8px; word-break: break-all; }
.sms-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.sms-tag {
    font-size: 11px; padding: 3px 10px; border-radius: 20px;
    background: rgba(13, 148, 136, 0.1); color: var(--accent); border: 1px solid rgba(13, 148, 136, 0.2);
}
.sms-tag.device { background: rgba(99, 102, 241, 0.1); color: var(--purple); border-color: rgba(99, 102, 241, 0.2); }

/* ============ Devices List ============ */
.device-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.device-card {
    padding: 20px; border-radius: var(--radius-lg); background: var(--bg-card);
    border: 1px solid var(--border);
}
.device-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.device-card-name { font-size: 16px; font-weight: 600; color: #fff; }
.device-status {
    display: flex; align-items: center; gap: 6px; font-size: 12px;
    padding: 4px 10px; border-radius: 20px;
}
.device-status.online { color: var(--success); background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.2); }
.device-status.offline { color: var(--text-muted); background: rgba(100, 116, 139, 0.1); border: 1px solid rgba(100, 116, 139, 0.2); }
.device-status .dot { width: 6px; height: 6px; border-radius: 50%; }
.device-status.online .dot { background: var(--success); animation: pulse 2s infinite; }
.device-status.offline .dot { background: var(--text-muted); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.device-sim { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.device-sim .sim-badge {
    font-size: 12px; padding: 4px 12px; border-radius: var(--radius-sm);
    background: rgba(99, 102, 241, 0.1); border: 1px solid rgba(99, 102, 241, 0.15);
    color: var(--purple);
}
.device-meta { font-size: 12px; color: var(--text-muted); }

/* ============ Admin Stats ============ */
.admin-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.admin-stat {
    padding: 20px; border-radius: var(--radius-lg); background: var(--bg-card);
    border: 1px solid var(--border);
}
.admin-stat .stat-icon {
    width: 40px; height: 40px; border-radius: 10px; display: flex;
    align-items: center; justify-content: center; margin-bottom: 12px; font-size: 18px;
}
.admin-stat:nth-child(1) .stat-icon { background: rgba(99, 102, 241, 0.15); }
.admin-stat:nth-child(2) .stat-icon { background: rgba(13, 148, 136, 0.15); }
.admin-stat:nth-child(3) .stat-icon { background: rgba(245, 158, 11, 0.15); }
.admin-stat:nth-child(4) .stat-icon { background: rgba(34, 197, 94, 0.15); }
.admin-stat .stat-val { font-size: 28px; font-weight: 700; color: #fff; }
.admin-stat .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ============ Data Table ============ */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; padding: 12px 16px; font-size: 12px; color: var(--text-muted);
    font-weight: 500; text-transform: uppercase; letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 14px 16px; font-size: 14px; color: #CBD5E1;
    border-bottom: 1px solid rgba(30, 41, 59, 0.5);
}
.data-table tr:hover td { background: var(--bg-card); }
.table-badge {
    font-size: 11px; padding: 2px 8px; border-radius: 20px;
    background: rgba(34, 197, 94, 0.1); color: var(--success);
}
.table-badge.admin { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.table-actions { display: flex; gap: 8px; }
.table-actions button {
    padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border);
    background: transparent; color: var(--text-secondary); font-size: 12px;
    transition: all 0.2s;
}
.table-actions button:hover { border-color: var(--accent); color: var(--accent); }
.table-actions button.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-add {
    padding: 8px 20px; border-radius: var(--radius-sm); border: none;
    background: var(--accent-gradient); color: #fff;
    font-size: 13px; font-weight: 500;
}

/* ============ Modal ============ */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal {
    width: 440px; max-width: 90vw; padding: 32px; border-radius: 20px;
    background: var(--bg-secondary); border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.modal h3 { font-size: 18px; color: #fff; margin-bottom: 20px; }
.modal .input-group { margin-bottom: 16px; }
.modal .input-group label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.modal .input-group input, .modal .input-group select {
    width: 100%; padding: 10px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-sidebar);
    color: var(--text-primary); font-size: 14px; outline: none;
}
.modal .input-group input:focus, .modal .input-group select:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }
.modal-actions .btn-cancel {
    padding: 10px 20px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: transparent; color: var(--text-secondary); font-size: 14px;
}
.modal-actions .btn-confirm {
    padding: 10px 20px; border-radius: var(--radius-sm); border: none;
    background: var(--accent-gradient); color: #fff; font-size: 14px; font-weight: 500;
}

/* ============ Pagination ============ */
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 24px; }
.pagination button {
    padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border);
    background: transparent; color: var(--text-secondary); font-size: 13px;
    transition: all 0.2s;
}
.pagination button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--text-muted); }

/* ============ Empty State ============ */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state .title { font-size: 16px; color: var(--text-secondary); margin-bottom: 8px; }

/* ============ Loading ============ */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }
.spinner {
    width: 24px; height: 24px; border: 2px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Mobile Hamburger ============ */
.hamburger-btn {
    display: none; background: none; border: none; color: var(--text-secondary);
    padding: 8px; font-size: 20px;
}
.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .main-content { margin-left: 0; }
    .hamburger-btn { display: block; }
    .search-box { width: 100%; }
    .top-bar-right { width: 100%; }
    .admin-stats { grid-template-columns: repeat(2, 1fr); }
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 10px 8px; }
    .device-cards { grid-template-columns: 1fr; }
}
