/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary:   #0f1923;
    --bg-secondary: #1a2736;
    --bg-card:      #1e2d3d;
    --bg-input:     #243447;
    --border:       #2a3a4e;
    --text-primary: #e2e8f0;
    --text-secondary:#94a3b8;
    --text-muted:   #64748b;
    --accent:       #6366f1;
    --accent-hover: #818cf8;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --success:      #22c55e;
    --warning:      #f59e0b;
    --danger:       #ef4444;
    --radius:       8px;
    --radius-lg:    12px;
    --shadow:       0 4px 24px rgba(0,0,0,.3);
    --transition:   .2s ease;
    --sidebar-width: 260px;
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent-hover); text-decoration: none; transition: color var(--transition); }
a:hover { color: #a5b4fc; }

img { max-width: 100%; display: block; }

/* ── Utilities ───────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .65rem 1.4rem;
    border: none; border-radius: var(--radius);
    font-family: var(--font); font-size: .9rem; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
    text-decoration: none; line-height: 1.4;
}
.btn-primary {
    background: var(--accent-gradient); color: #fff;
    box-shadow: 0 2px 12px rgba(99,102,241,.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(99,102,241,.45); color: #fff; }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-sm { padding: .4rem .9rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Form Elements ───────────────────────────────────────────────── */
.form-group { margin-bottom: 1.2rem; }
.form-label {
    display: block; margin-bottom: .4rem;
    font-size: .85rem; font-weight: 600; color: var(--text-secondary);
}
.form-control {
    width: 100%; padding: .7rem 1rem;
    background: var(--bg-input); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius);
    font-family: var(--font); font-size: .9rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-control::placeholder { color: var(--text-muted); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 1rem center; padding-right: 2.5rem; }
textarea.form-control { resize: vertical; min-height: 100px; }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 1.5rem;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.2rem; padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.card-header h2, .card-header h3 { font-size: 1.1rem; font-weight: 700; }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: .2rem .7rem;
    font-size: .75rem; font-weight: 600; border-radius: 50px;
    text-transform: uppercase; letter-spacing: .5px;
}
.badge-active  { background: rgba(34,197,94,.15); color: var(--success); }
.badge-expired { background: rgba(239,68,68,.15); color: var(--danger); }

/* ── Stat Cards ──────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 1.3rem 1.5rem;
    display: flex; align-items: center; gap: 1rem;
}
.stat-icon {
    width: 48px; height: 48px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; flex-shrink: 0;
}
.stat-icon.purple { background: rgba(99,102,241,.15); color: var(--accent); }
.stat-icon.green  { background: rgba(34,197,94,.15);  color: var(--success); }
.stat-icon.orange { background: rgba(245,158,11,.15); color: var(--warning); }
.stat-info h3 { font-size: 1.5rem; font-weight: 800; line-height: 1.2; }
.stat-info p  { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

/* ── Tables ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left; padding: .8rem 1rem;
    font-size: .78rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: .75rem 1rem; border-bottom: 1px solid var(--border);
    font-size: .88rem; vertical-align: middle;
}
tbody tr:hover { background: rgba(99,102,241,.04); }
tbody tr:last-child td { border-bottom: none; }

/* ── Auth Layout ─────────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 2rem;
    background: var(--bg-primary);
}
.auth-card {
    width: 100%; max-width: 420px;
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 2.5rem;
    box-shadow: var(--shadow);
}
.auth-card h1 {
    font-size: 1.6rem; font-weight: 800; text-align: center; margin-bottom: .4rem;
}
.auth-card .subtitle {
    text-align: center; color: var(--text-muted); font-size: .9rem; margin-bottom: 2rem;
}
.auth-logo {
    text-align: center; margin-bottom: 1.5rem;
    font-size: 2rem; font-weight: 900;
    background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Alert Messages ──────────────────────────────────────────────── */
.alert {
    padding: .8rem 1.2rem; border-radius: var(--radius);
    font-size: .88rem; margin-bottom: 1.2rem;
    border: 1px solid transparent;
}
.alert-success { background: rgba(34,197,94,.1); border-color: rgba(34,197,94,.3); color: var(--success); }
.alert-danger  { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.3); color: var(--danger); }
.alert-info    { background: rgba(99,102,241,.1); border-color: rgba(99,102,241,.3); color: var(--accent-hover); }

/* ── Portal Warning Box ─────────────────────────────────────────── */
.portal-warning {
    background: rgba(239, 68, 68, .12);
    border: 2px solid var(--danger);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    margin-bottom: 1.4rem;
    color: var(--danger);
    font-size: .9rem;
    line-height: 1.5;
}
.portal-warning strong {
    font-size: 1rem;
    display: block;
    margin-bottom: .3rem;
}

/* ── Admin Layout ────────────────────────────────────────────────── */
.admin-layout { display: flex; min-height: 100vh; }
.admin-topbar {
    display: none; /* shown on mobile */
    background: var(--bg-secondary); border-bottom: 1px solid var(--border);
    padding: .8rem 1.2rem; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 100;
}
.admin-topbar .logo { font-size: 1.1rem; font-weight: 800; background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.hamburger {
    background: none; border: none; color: var(--text-primary);
    font-size: 1.5rem; cursor: pointer; padding: .2rem;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width); background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 200; transition: transform .3s ease;
}
.sidebar-header {
    padding: 1.5rem; border-bottom: 1px solid var(--border);
}
.sidebar-header .logo {
    font-size: 1.3rem; font-weight: 900;
    background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.sidebar-header p { font-size: .75rem; color: var(--text-muted); margin-top: .2rem; }
.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.sidebar-nav a {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem 1.5rem; color: var(--text-secondary);
    font-size: .9rem; font-weight: 500; transition: all var(--transition);
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: rgba(99,102,241,.06); color: var(--text-primary); }
.sidebar-nav a.active {
    color: var(--accent-hover); border-left-color: var(--accent);
    background: rgba(99,102,241,.08);
}
.sidebar-nav a .icon { font-size: 1.1rem; width: 24px; text-align: center; }
.sidebar-footer {
    padding: 1rem 1.5rem; border-top: 1px solid var(--border);
}
.sidebar-footer a { color: var(--text-muted); font-size: .85rem; display: flex; align-items: center; gap: .5rem; }
.sidebar-footer a:hover { color: var(--danger); }

.main-content {
    flex: 1; margin-left: var(--sidebar-width);
    padding: 2rem;
    min-width: 0;
}
.main-content .page-header {
    margin-bottom: 1.5rem;
}
.main-content .page-header h1 { font-size: 1.5rem; font-weight: 800; }
.main-content .page-header p  { color: var(--text-muted); font-size: .9rem; margin-top: .2rem; }

/* ── Client Dashboard Cards ──────────────────────────────────────── */
.device-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.2rem; }
.device-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden;
}
.device-card-header {
    background: var(--accent-gradient); padding: 1rem 1.3rem;
    display: flex; justify-content: space-between; align-items: center;
}
.device-card-header h3 { color: #fff; font-size: 1rem; font-weight: 700; }
.device-card-body { padding: 1.3rem; }
.cred-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: .6rem 0; border-bottom: 1px solid var(--border);
}
.cred-row:last-child { border-bottom: none; }
.cred-label { font-size: .8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.cred-value {
    font-size: .88rem; color: var(--text-primary); font-family: 'Fira Code', monospace;
    word-break: break-all; max-width: 60%; text-align: right;
    display: flex; align-items: center; gap: .5rem;
}
.copy-btn {
    background: var(--bg-input); border: 1px solid var(--border);
    color: var(--text-muted); padding: .3rem .5rem; border-radius: 4px;
    cursor: pointer; font-size: .7rem; transition: all var(--transition);
    flex-shrink: 0;
}
.copy-btn:hover { color: var(--accent-hover); border-color: var(--accent); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }

/* ── Accordion ───────────────────────────────────────────────────── */
.accordion-item {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: .6rem; overflow: hidden;
}
.accordion-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.3rem; cursor: pointer; transition: background var(--transition);
    font-weight: 600; font-size: .95rem;
}
.accordion-header:hover { background: rgba(99,102,241,.05); }
.accordion-header .arrow { transition: transform .3s; font-size: .8rem; color: var(--text-muted); }
.accordion-item.open .accordion-header .arrow { transform: rotate(180deg); }
.accordion-body {
    max-height: 0; overflow: hidden; transition: max-height .3s ease;
}
.accordion-body-inner {
    padding: 0 1.3rem 1.2rem;
    color: var(--text-secondary); font-size: .9rem; line-height: 1.7;
}
.accordion-body-inner ol, .accordion-body-inner ul { padding-left: 1.3rem; }
.accordion-body-inner li { margin-bottom: .4rem; }
.accordion-body-inner code {
    background: var(--bg-input); padding: .15rem .4rem; border-radius: 4px;
    font-size: .82rem; color: var(--accent-hover);
}

/* ── Search & Filters ────────────────────────────────────────────── */
.search-bar {
    display: flex; gap: .8rem; margin-bottom: 1.2rem; flex-wrap: wrap;
}
.search-bar .form-control { max-width: 320px; }

/* ── Overlay for mobile sidebar ──────────────────────────────────── */
.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 150;
}

/* ── Mobile Top Nav Bar ─────────────────────────────────────────── */
.mobile-top-nav {
    display: none;
    gap: .5rem;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: .7rem .6rem;
}
.mobile-top-nav a {
    display: flex; flex-direction: column; align-items: center; gap: .3rem;
    flex: 1; min-width: 0;
    padding: .6rem .4rem .5rem;
    color: var(--text-muted); font-size: .7rem; font-weight: 600;
    text-decoration: none; transition: all var(--transition);
    white-space: nowrap;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
}
.mobile-top-nav a .mnav-icon {
    font-size: 1.4rem; line-height: 1;
}
.mobile-top-nav a.active {
    color: var(--accent-hover);
    border-color: var(--accent);
    background: rgba(99,102,241,.1);
    box-shadow: 0 0 8px rgba(99,102,241,.2);
}
.mobile-top-nav a:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .admin-topbar { display: flex; }
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .main-content { margin-left: 0; padding: 1.2rem; }
    .mobile-top-nav { display: flex; }
    .stats-grid { grid-template-columns: 1fr; }
    .device-cards { grid-template-columns: 1fr; }
    .search-bar .form-control { max-width: 100%; }
    .auth-card { padding: 1.8rem; }
    table { font-size: .82rem; }
    thead th, tbody td { padding: .6rem .5rem; }
}

@media (max-width: 480px) {
    html { font-size: 14px; }
    .cred-row { flex-direction: column; align-items: flex-start; gap: .3rem; }
    .cred-value { max-width: 100%; text-align: left; }
}

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

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.6); z-index: 1000;
    align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 2rem; width: 100%; max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: .8rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ── Tooltip ─────────────────────────────────────────────────────── */
.tooltip-wrap { position: relative; }
.tooltip {
    position: absolute; bottom: 125%; left: 50%; transform: translateX(-50%);
    background: #1e293b; color: #fff; padding: .3rem .6rem;
    border-radius: 4px; font-size: .7rem; white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity .2s;
}
.tooltip-wrap:hover .tooltip { opacity: 1; }

/* ── Language Switcher ──────────────────────────────────────────── */
.lang-switcher { display: inline-flex; align-items: center; }
.lang-select {
    background: var(--bg-input); color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: .3rem .5rem; padding-right: 1.5rem;
    font-family: var(--font); font-size: .78rem;
    cursor: pointer; outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .4rem center;
}
.lang-select:focus { border-color: var(--accent); }
.sidebar-footer .lang-switcher { display: block; margin-bottom: .6rem; }
.admin-topbar .lang-switcher { margin-right: .5rem; }
.auth-lang { position: absolute; top: 1rem; right: 1rem; z-index: 10; }
.auth-wrapper { position: relative; }
