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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242734;
    --border: #2e3244;
    --text: #e1e4ed;
    --text-dim: #8b90a0;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
    --radius-lg: 12px;
}

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

/* ── Login ──────────────────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-subtitle { color: var(--text-dim); margin-bottom: 1.5rem; font-size: 0.9rem; }

/* ── Fields ─────────────────────────────────────────── */
.field { margin-bottom: 1rem; text-align: left; }
.field label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.field input, .field select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}
.field input:focus { border-color: var(--primary); }
.field input[readonly] { opacity: 0.6; cursor: default; }

.error-msg {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* ── Buttons ────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-apply { background: var(--success); color: #fff; }
.btn-apply:hover:not(:disabled) { opacity: 0.85; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.1rem; }
.topbar-actions { display: flex; gap: 0.5rem; }

/* ── Tabs ───────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
}
.tab {
    padding: 0.7rem 1.2rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-content { display: none; padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
.tab-content.active { display: block; }

/* ── Form Grid ──────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1.5rem;
}
.form-grid .field.full { grid-column: 1 / -1; }
.form-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

/* ── Section Header ─────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.section-header h2 { font-size: 1.15rem; }

.snap-create { display: flex; gap: 0.5rem; }
.snap-create input {
    padding: 0.4rem 0.7rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    width: 240px;
}

/* ── Data Table ─────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.data-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    color: var(--text-dim);
    font-weight: 500;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface2); }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-on { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-off { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

.actions-cell { display: flex; gap: 0.3rem; flex-wrap: wrap; }

/* ── Modal ──────────────────────────────────────────── */
.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: var(--radius-lg);
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.modal-header h3 { font-size: 1.1rem; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.4rem;
    cursor: pointer;
}

/* ── Copy Row ───────────────────────────────────────── */
.copy-row { display: flex; gap: 0.4rem; }
.copy-row input { flex: 1; }
.keys-display { display: flex; flex-direction: column; gap: 0.75rem; }

/* ── Commands Modal ─────────────────────────────────── */
.modal-wide { max-width: 680px; }
.cmds-grid { display: flex; flex-direction: column; gap: 1rem; }
.cmd-section h4 {
    font-size: 0.82rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
}
.cmd-block {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}
.cmd-block pre {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.82rem;
    color: var(--success);
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.6;
    margin: 0;
    overflow-x: auto;
}
.cmd-block .btn { flex-shrink: 0; margin-top: 0.3rem; }
.cmd-row { display: flex; gap: 1rem; }
.cmd-half { flex: 1; }

/* ── Topbar Navigation ──────────────────────────────── */
.topbar-left { display: flex; align-items: center; gap: 1.5rem; }
.topbar-nav { display: flex; gap: 0.5rem; }
.nav-link {
    color: var(--text-dim);
    text-decoration: none;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: var(--primary); color: #fff; }

/* ── Badges ─────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-ok { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warn { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-err { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-muted { background: var(--surface2); color: var(--text-dim); }

/* ── Apply Result ───────────────────────────────────── */
.apply-result { font-size: 0.88rem; line-height: 1.6; }
.apply-result h4 { margin: 0.8rem 0 0.3rem; color: var(--text); }
.apply-result ul { padding-left: 1.2rem; }
.apply-result li { margin-bottom: 0.3rem; }
.text-err { color: var(--danger); }

/* ── Toast ──────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 1.2rem;
    font-size: 0.88rem;
    z-index: 200;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    transition: opacity 0.3s;
}
.toast[hidden] { display: none; }
.toast.toast-ok { border-left: 3px solid var(--success); }
.toast.toast-err { border-left: 3px solid var(--danger); }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; gap: 0.5rem; }
    .data-table { font-size: 0.8rem; }
    .actions-cell { flex-direction: column; }
    .snap-create { flex-direction: column; }
    .snap-create input { width: 100%; }
}
