:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --accent: #EA6641;
    --accent-hover: #d4573a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --border: #2a2a4a;
}

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

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

.layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}

/* --- Sidebar --- */

.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.sidebar-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 4px;
}

.sidebar-header .version {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.nav-group-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    padding: 16px 20px 4px;
}

.nav-list {
    list-style: none;
    flex: 1;
}

.nav-list a {
    display: block;
    padding: 8px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.nav-list a:hover {
    background: rgba(234, 102, 65, 0.08);
    color: var(--text-primary);
}

.nav-list a.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: rgba(234, 102, 65, 0.12);
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
}

.status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    flex-shrink: 0;
}

.status-dot.connected {
    background: var(--success);
}

.status-label {
    color: var(--text-secondary);
}

/* --- Main content --- */

.content {
    padding: 24px 32px;
    min-height: 100vh;
    min-width: 0;
    overflow-x: hidden;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-primary);
}

/* --- Cards --- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-status {
    font-size: 0.8rem;
    font-weight: 500;
    padding: 2px 10px;
    border-radius: 12px;
}

.card-status.disconnected {
    background: rgba(244, 67, 54, 0.15);
    color: var(--danger);
}

.card-status.connected {
    background: rgba(76, 175, 80, 0.15);
    color: var(--success);
}

.card-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* --- Info table --- */

.info-table {
    width: 100%;
    border-collapse: collapse;
}

.info-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.info-table td:first-child {
    color: var(--text-secondary);
    width: 140px;
}

/* --- Quick actions --- */

.action-grid {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
}

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

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

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

/* --- Activity feed --- */

.activity-feed {
    list-style: none;
}

.activity-feed li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* --- Stub page --- */

.stub-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    text-align: center;
}

.stub-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.4;
}

.stub-title {
    font-size: 1.2rem;
    margin-bottom: 8px;
}

.stub-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* --- Form inputs --- */

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="url"],
textarea {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    width: 100%;
    outline: none;
    transition: border-color 0.15s;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(234, 102, 65, 0.15);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

textarea {
    min-height: 80px;
    resize: vertical;
}

/* --- Select --- */

select {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 32px 8px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a0a0a0'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.15s;
}

select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* --- Checkbox & Radio --- */

input[type="checkbox"],
input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* --- Form groups --- */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.form-row > input,
.form-row > select {
    flex: 1;
}

/* --- Data table --- */

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.83rem;
    border-bottom: 1px solid var(--border);
}

th {
    background: rgba(15, 52, 96, 0.5);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 1;
}

tbody tr {
    transition: background 0.1s;
}

tbody tr:hover {
    background: rgba(234, 102, 65, 0.05);
}

td.mono, th.mono {
    font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
    font-size: 0.8rem;
}

/* --- Toggle switch --- */

.toggle {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 22px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle .slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 22px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle .slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle input:checked + .slider {
    background: var(--accent);
}

.toggle input:checked + .slider::before {
    transform: translateX(20px);
}

/* --- Badges --- */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success { background: rgba(76, 175, 80, 0.15); color: var(--success); }
.badge-warning { background: rgba(255, 152, 0, 0.15); color: var(--warning); }
.badge-danger { background: rgba(244, 67, 54, 0.15); color: var(--danger); }
.badge-info { background: rgba(33, 150, 243, 0.15); color: #2196f3; }
.badge-muted { background: rgba(160, 160, 160, 0.12); color: var(--text-secondary); }

/* --- Tabs --- */

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    gap: 0;
}

.tab {
    padding: 10px 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-panel {
    display: none;
}

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

/* --- Modal / Dialog --- */

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
    min-width: 360px;
    max-width: 560px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal-body {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* --- Button variants --- */

.btn-sm {
    padding: 5px 12px;
    font-size: 0.78rem;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #d32f2f;
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #388e3c;
}

.btn-warning {
    background: var(--warning);
    color: #1a1a2e;
}

.btn-warning:hover {
    background: #f57c00;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 14px;
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Progress bar --- */

.progress {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-bar.success { background: var(--success); }
.progress-bar.danger { background: var(--danger); }

/* --- Code / Log block --- */

.log-block,
pre,
code {
    font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
    font-size: 0.8rem;
}

.log-block {
    background: #0d0d1a;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px 16px;
    max-height: 300px;
    overflow-y: auto;
    color: #8fbc8f;
    line-height: 1.6;
}

pre {
    background: #0d0d1a;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px 16px;
    overflow-x: auto;
    color: var(--text-primary);
}

code {
    background: rgba(15, 52, 96, 0.5);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--accent);
}

pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* --- Accordion / Collapsible --- */

.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(15, 52, 96, 0.3);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    transition: background 0.15s;
    margin-bottom: 2px;
}

.accordion-header:hover {
    background: rgba(15, 52, 96, 0.5);
}

.accordion-body {
    padding: 16px;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    margin-bottom: 8px;
}

/* --- Section / Panel --- */

.section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
}

.panel-header {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* --- Inline list row --- */

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.list-row:last-child {
    border-bottom: none;
}

.list-row-label {
    color: var(--text-primary);
}

.list-row-value {
    color: var(--text-secondary);
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    font-size: 0.8rem;
}

.list-row-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* --- Hex viewer --- */

.hex-viewer {
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    font-size: 0.75rem;
    background: #0d0d1a;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    overflow: auto;
    max-height: 400px;
    line-height: 1.7;
    color: #8fbc8f;
}

.hex-viewer .offset { color: var(--text-secondary); }
.hex-viewer .highlight { color: var(--danger); font-weight: 600; }
.hex-viewer .ascii { color: #6a9fb5; }

/* --- Drag-and-drop zone --- */

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.active {
    border-color: var(--accent);
    background: rgba(234, 102, 65, 0.05);
}

/* --- Utility --- */

.text-muted { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-mono { font-family: "SF Mono", "Fira Code", Consolas, monospace; font-size: 0.8rem; }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.hidden { display: none; }

/* --- Toast --- */

#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #fff;
    pointer-events: auto;
    animation: toast-in 0.25s ease;
    max-width: 360px;
}

.toast.info { background: #2196f3; }
.toast.success { background: var(--success); }
.toast.warning { background: var(--warning); color: #1a1a2e; }
.toast.error { background: var(--danger); }

.toast.removing {
    animation: toast-out 0.2s ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* --- Responsive --- */

@media (max-width: 768px) {
    .layout {
        grid-template-columns: 60px 1fr;
    }
    .sidebar {
        width: 60px;
    }
    .sidebar-header h1 {
        font-size: 1rem;
        letter-spacing: 0;
    }
    .sidebar-header .version,
    .nav-group-label,
    .status-label {
        display: none;
    }
    .nav-list a {
        padding: 10px;
        text-align: center;
        font-size: 0;
        border-left: none;
        border-bottom: 2px solid transparent;
    }
    .nav-list a::first-letter {
        font-size: 0.9rem;
    }
    .nav-list a.active {
        border-bottom-color: var(--accent);
        border-left-color: transparent;
    }
    .content {
        padding: 16px;
    }
}

/* --- Striped table rows --- */

tbody tr:nth-child(odd) {
    background: rgba(15, 52, 96, 0.18);
}

tbody tr:hover {
    background: rgba(234, 102, 65, 0.05);
}

/* --- Task table scroll wrapper --- */

.task-table-scroll {
    max-height: 420px;
    overflow-y: auto;
}

/* --- Action modal --- */

.action-modal {
    max-width: 720px;
}

.action-entry {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.action-entry:last-child {
    border-bottom: none;
}

.action-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
