/* ========================================
   TLCNA RMM — Dark Theme
   ======================================== */

:root {
    --bg: #0c0e12;
    --surface: #14171d;
    --surface-2: #1c2028;
    --surface-3: #242830;
    --border: #262b35;
    --border-hover: #3a4050;
    --text: #e4e7ec;
    --text-muted: #7a8294;
    --text-dim: #4a5060;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-dim: rgba(59,130,246,0.12);
    --green: #22c55e;
    --green-dim: rgba(34,197,94,0.12);
    --red: #ef4444;
    --red-dim: rgba(239,68,68,0.12);
    --amber: #f59e0b;
    --amber-dim: rgba(245,158,11,0.12);
    --purple: #8b5cf6;
    --purple-dim: rgba(139,92,246,0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --topbar-h: 56px;
    --sidebar-w: 280px;
    --font: 'Inter', -apple-system, sans-serif;
    --mono: 'JetBrains Mono', 'Menlo', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ── Login ────────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}
.login-logo { margin-bottom: 1rem; }
.login-card h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}
.login-sub {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 1.5rem;
}
.login-card form { text-align: left; }
.remember {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin: 0.75rem 0 1rem;
    cursor: pointer;
}
.error-msg {
    color: var(--red);
    font-size: 0.82rem;
    text-align: center;
    margin-top: 0.75rem;
}

/* ── Form Fields ──────────────────────────── */
.field { margin-bottom: 0.75rem; }
.field label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.field input, .field select, .field textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
}
.field input::placeholder, .field textarea::placeholder {
    color: var(--text-dim);
}
.field select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a8294' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}
.field textarea { resize: vertical; min-height: 60px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── Buttons ──────────────────────────────── */
.btn {
    font-family: var(--font);
    font-weight: 600;
    font-size: 0.82rem;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.55rem 1.1rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-hover); }
.btn-danger { background: var(--red-dim); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-success { background: var(--green-dim); color: var(--green); }
.btn-success:hover { background: var(--green); color: #fff; }
.btn-full { width: 100%; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.75rem; }
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); }

/* ── Top Bar ──────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    z-index: 100;
    gap: 0.5rem;
}
.topbar-title {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 700;
}
.topbar-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.topbar-btn:hover { color: var(--text); background: var(--surface-2); }
.topbar-actions { display: flex; gap: 0.25rem; }

/* ── Search Bar ───────────────────────────── */
.search-bar {
    position: fixed;
    top: var(--topbar-h);
    left: 0; right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
    z-index: 90;
    display: none;
}
.search-bar.visible { display: block; }
.search-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.75rem;
}
.search-wrap svg { flex-shrink: 0; color: var(--text-muted); }
.search-wrap input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    outline: none;
}
.search-wrap input::placeholder { color: var(--text-dim); }

/* ── Sidebar ──────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 190;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1rem 0.75rem;
    font-weight: 700;
    font-size: 0.95rem;
}
.sidebar-close {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.25rem;
}
.sidebar-nav { padding: 0.5rem 0.75rem; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--accent); background: var(--accent-dim); }
.nav-badge {
    margin-left: auto;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    min-width: 1.4rem;
    text-align: center;
}
.nav-item.active .nav-badge { background: var(--accent-dim); color: var(--accent); }

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 1rem;
}
.sidebar-section { padding: 0.5rem 1rem; }
.sidebar-section h3 {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}
.stat-card {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
    text-align: center;
}
.stat-val { display: block; font-size: 1.2rem; font-weight: 700; }
.stat-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-online .stat-val { color: var(--green); }
.stat-offline .stat-val { color: var(--text-muted); }
.stat-alerts .stat-val { color: var(--amber); }
.stat-total .stat-val { color: var(--accent); }

.rustdesk-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.mono-sm {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--text-muted);
}
.key-display {
    background: var(--surface-2);
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    word-break: break-all;
    transition: background 0.15s;
}
.key-display:hover { background: var(--surface-3); }

.sidebar-footer {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sidebar-user { font-size: 0.82rem; color: var(--text-muted); }
.sidebar-logout {
    font-size: 0.78rem;
    color: var(--red);
    text-decoration: none;
}
.sidebar-logout:hover { text-decoration: underline; }

/* ── Main Content ─────────────────────────── */
.main-content {
    margin-top: var(--topbar-h);
    padding: 1rem;
    min-height: calc(100vh - var(--topbar-h));
}
.view { display: none; }
.view.active { display: block; }

/* ── Device Grid ──────────────────────────── */
.device-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.device-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    cursor: pointer;
    transition: all 0.15s;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.75rem;
}
.device-card:hover { border-color: var(--border-hover); }

.status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 8px rgba(34,197,94,0.4); }
.status-dot.offline { background: var(--text-dim); }

.device-info { min-width: 0; }
.device-name {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.device-meta {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-actions {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
}
.connect-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.75rem;
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.connect-btn:hover { background: var(--accent-hover); }
.connect-btn.rustdesk { background: var(--purple); }
.connect-btn.rustdesk:hover { background: #7c3aed; }

/* Device type badges */
.type-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.4rem;
    vertical-align: middle;
}
.type-desktop { background: var(--accent-dim); color: var(--accent); }
.type-laptop { background: var(--green-dim); color: var(--green); }
.type-server { background: var(--purple-dim); color: var(--purple); }
.type-other { background: var(--surface-3); color: var(--text-muted); }

/* ── Metrics Row (in device card) ─────────── */
.device-metrics {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.35rem;
}
.metric {
    font-size: 0.68rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.metric-bar {
    width: 40px;
    height: 4px;
    background: var(--surface-3);
    border-radius: 2px;
    overflow: hidden;
}
.metric-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}
.metric-fill.green { background: var(--green); }
.metric-fill.amber { background: var(--amber); }
.metric-fill.red { background: var(--red); }

/* ── Alert List ───────────────────────────── */
.alert-list { display: flex; flex-direction: column; gap: 0.5rem; }
.alert-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.alert-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.alert-icon.disk { background: var(--amber-dim); color: var(--amber); }
.alert-icon.memory { background: var(--red-dim); color: var(--red); }
.alert-icon.offline { background: var(--surface-3); color: var(--text-muted); }
.alert-icon.cpu { background: var(--purple-dim); color: var(--purple); }
.alert-info { flex: 1; min-width: 0; }
.alert-device { font-weight: 600; font-size: 0.88rem; }
.alert-msg { font-size: 0.78rem; color: var(--text-muted); }
.alert-time { font-size: 0.7rem; color: var(--text-dim); font-family: var(--mono); }

/* ── SOS Panel ────────────────────────────── */
.sos-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    max-width: 480px;
    margin: 2rem auto;
}
.sos-panel h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.sos-panel p { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1rem; }
.sos-row {
    display: flex;
    gap: 0.5rem;
    max-width: 300px;
    margin: 0 auto;
}
.sos-input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem;
    color: var(--text);
    font-family: var(--mono);
    font-size: 1.1rem;
    letter-spacing: 0.15em;
    text-align: center;
    outline: none;
}
.sos-input:focus { border-color: var(--accent); }
.sos-sub { font-size: 0.72rem; margin-top: 1rem; }
.sos-sub a { color: var(--accent); text-decoration: none; }
.sos-sub a:hover { text-decoration: underline; }

/* -- Deploy Panel -- */
.deploy-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 560px;
    margin: 1rem auto;
}
.deploy-panel h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.deploy-panel > p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.25rem; }
.deploy-code {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.15s;
    position: relative;
    text-align: center;
}
.deploy-code:hover { border-color: var(--accent); }
.deploy-code code {
    font-family: var(--mono);
    font-size: 0.95rem;
    color: var(--accent);
}
.copy-hint {
    display: block;
    font-size: 0.68rem;
    color: var(--text-dim);
    margin-top: 0.35rem;
}
.deploy-steps {
    margin-top: 1.5rem;
}
.deploy-steps h3 {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}
.deploy-steps ol {
    padding-left: 1.25rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.8;
}
.deploy-info {
    margin-top: 1.5rem;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 1rem;
}
.deploy-info h3 {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}
.deploy-detail {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    font-size: 0.82rem;
}
.deploy-detail span { color: var(--text-muted); }
.deploy-detail code {
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--text);
    word-break: break-all;
}

/* ── Modal ────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 300;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.modal-sheet {
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}
.modal-sm { max-width: 480px; }
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.modal-handle {
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px auto 0;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 700; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.25rem;
}
.modal-body { padding: 1.25rem; }

/* ── Device Detail (modal body) ───────────── */
.detail-section { margin-bottom: 1.25rem; }
.detail-section h3 {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.detail-item {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
}
.detail-label {
    font-size: 0.68rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.detail-value {
    font-size: 0.88rem;
    font-weight: 500;
    margin-top: 0.15rem;
}
.detail-value.mono { font-family: var(--mono); font-size: 0.8rem; }

.detail-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Metric bars in detail */
.detail-metric {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
}
.detail-metric-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 0.35rem;
}
.detail-metric-header span:first-child { color: var(--text-muted); }
.detail-metric-header span:last-child { font-weight: 600; font-family: var(--mono); }
.detail-bar {
    width: 100%;
    height: 6px;
    background: var(--surface-3);
    border-radius: 3px;
    overflow: hidden;
}
.detail-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* ── Toast ─────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 1rem;
    font-size: 0.82rem;
    font-weight: 500;
    animation: toastIn 0.25s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Loading ──────────────────────────────── */
.loading-spinner {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin: 0 auto 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}
.empty-state p { margin-bottom: 0.5rem; font-size: 0.85rem; }

/* ── Responsive ───────────────────────────── */
@media (min-width: 768px) {
    .device-grid {
        grid-template-columns: 1fr;
    }
    .modal-overlay {
        align-items: center;
    }
    .modal-sheet {
        border-radius: 16px;
        margin: 2rem;
    }
    .modal-handle { display: none; }
}

@media (min-width: 1024px) {
    .sidebar {
        transform: translateX(0);
        top: var(--topbar-h);
    }
    .sidebar-close { display: none; }
    .sidebar-overlay { display: none !important; }
    #sidebar-toggle { display: none; }
    .topbar { left: var(--sidebar-w); }
    .search-bar { left: var(--sidebar-w); }
    .main-content {
        margin-left: var(--sidebar-w);
        padding: 1.25rem 1.5rem;
    }
    .device-grid {
        grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    }
}

@media (min-width: 1400px) {
    .device-grid {
        grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    }
}
