*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #222632;
    --border: #2a2e3b;
    --text: #e1e4eb;
    --text-muted: #8b8fa3;
    --accent: #6c8cff;
    --accent-dim: #4a66cc;
    --green: #3dd68c;
    --red: #f06b6b;
    --orange: #f0a04b;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

header h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.badge {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--border);
    color: var(--text-muted);
}

.badge.online {
    background: rgba(61, 214, 140, 0.15);
    color: var(--green);
}

.badge.offline {
    background: rgba(240, 107, 107, 0.15);
    color: var(--red);
}

nav {
    display: flex;
    gap: 4px;
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s;
}

.nav-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.nav-btn.active {
    background: var(--accent-dim);
    color: #fff;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Panel */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}

.panel h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* Device List (overview) */
.device-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.device-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    min-width: 220px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.device-icon {
    font-size: 24px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: var(--surface-hover);
}

.device-info {
    flex: 1;
}

.device-name {
    font-weight: 600;
    font-size: 14px;
}

.device-meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 14px;
}

.toolbar input::placeholder {
    color: var(--text-muted);
}

.toolbar input:focus,
.toolbar select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.data-table td {
    padding: 10px 14px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.data-table tbody tr:hover {
    background: var(--surface-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Operation badges */
.op-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.op-create { background: rgba(61, 214, 140, 0.15); color: var(--green); }
.op-modify { background: rgba(108, 140, 255, 0.15); color: var(--accent); }
.op-delete { background: rgba(240, 107, 107, 0.15); color: var(--red); }
.op-move   { background: rgba(240, 160, 75, 0.15); color: var(--orange); }

.os-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}

/* Buttons */
.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
}

.btn-primary:hover {
    background: var(--accent-dim);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-sm:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    min-width: 400px;
    max-width: 90vw;
}

.modal-wide {
    min-width: 700px;
}

.modal-content h3 {
    font-size: 18px;
    margin-bottom: 16px;
}

.modal-content label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.modal-content input,
.modal-content select {
    display: block;
    width: 100%;
    margin-top: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 14px;
}

.modal-content input:focus,
.modal-content select:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.modal-actions button:not(.btn-primary) {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
}

.token-display {
    margin: 12px 0;
}

.token-display code {
    display: block;
    margin-top: 6px;
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    word-break: break-all;
    user-select: all;
}

/* Activity feed */
.activity-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-time {
    color: var(--text-muted);
    font-size: 12px;
    min-width: 140px;
}

.activity-path {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--accent);
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Hash display */
.hash-short {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

/* Login */
.login-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.login-screen.hidden { display: none; }

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 360px;
    text-align: center;
}
.login-box h1 { font-size: 24px; margin-bottom: 4px; }
.login-box input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    text-align: center;
}
.login-box input:focus { outline: none; border-color: var(--accent); }

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 12px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-content,
    .modal-wide {
        min-width: auto;
        width: 95vw;
    }

    .data-table {
        font-size: 12px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 10px;
    }
}
