:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f6f7f3;
    --surface: #fffdf7;
    --surface-strong: #ffffff;
    --text: #172033;
    --text-muted: #637083;
    --border: #ddd8c9;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --info: #0f766e;
    --shadow: 0 10px 30px rgba(23, 32, 51, 0.07);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(circle at top left, #fff7d6 0, rgba(255,247,214,0) 34rem), var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.wide-container {
    max-width: 1180px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.app-header,
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.app-header h1,
.header h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    letter-spacing: -0.03em;
}

.header-actions,
.card-actions,
.button-row,
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.header-actions {
    justify-content: flex-end;
}

.toolbar {
    margin-bottom: 1.5rem;
}

.toolbar-note,
.user-email,
.muted {
    color: var(--text-muted);
}

.lede {
    color: var(--text-muted);
    margin-top: 0.35rem;
    max-width: 46rem;
}

.eyebrow {
    color: var(--warning);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.btn {
    display: inline-block;
    background: var(--primary);
    color: white;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 700;
    text-align: center;
    transition: 0.15s ease;
}

.btn:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

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

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

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

.btn-outline:hover {
    background: #f1efe7;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 700;
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.7rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    color: var(--text);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.alert {
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #86efac;
}

.hidden {
    display: none !important;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

th, td {
    padding: 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    font-weight: 800;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

code {
    background: #f1efe7;
    border: 1px solid var(--border);
    padding: 0.12rem 0.35rem;
    border-radius: 6px;
    color: #111827;
}

.badge {
    display: inline-block;
    padding: 0.28rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-neutral { background: #eef2f7; color: #475569; }
.badge-info { background: #ccfbf1; color: #115e59; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.router-grid {
    align-items: stretch;
}

.router-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card-title-row,
.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.card-title-row h2,
.section-heading h2 {
    margin: 0;
}

.small-copy {
    font-size: 0.875rem;
}

.kv-list {
    display: grid;
    gap: 0.65rem;
    margin: 1rem 0;
}

.kv-list.large {
    gap: 0.9rem;
}

.kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px dashed var(--border);
}

.kv-row span {
    color: var(--text-muted);
}

.card-actions {
    margin-top: auto;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    box-shadow: 0 4px 18px rgba(23, 32, 51, 0.05);
}

.stat-card span,
.stat-card small {
    display: block;
    color: var(--text-muted);
}

.stat-card strong {
    display: block;
    font-size: 1.25rem;
    margin: 0.25rem 0;
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
    gap: 1.5rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

.empty-state.compact {
    padding: 1.5rem;
    background: #fbfaf5;
    border: 1px dashed var(--border);
    border-radius: 12px;
}

.empty-state h2,
.empty-state h3 {
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.empty-icon {
    width: 3rem;
    height: 3rem;
    margin: 0 auto 1rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: #fff3bf;
    color: #92400e;
    font-weight: 900;
}

.form-panel {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.form-panel h3 {
    margin-bottom: 0.25rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.risk-warning {
    margin: 0.75rem 0 1rem;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid #fca5a5;
    background: #fef2f2;
    color: #7f1d1d;
}

.risk-warning p {
    margin-top: 0.35rem;
}

.risk-confirm {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #fecaca;
    font-weight: 700;
}

.actions-cell {
    text-align: right;
}

.health-result {
    margin-top: 1rem;
    font-size: 0.925rem;
    color: var(--text-muted);
}

.device-list {
    display: grid;
    gap: 0.75rem;
}

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

.device-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.device-actions .btn {
    padding: 0.45rem 0.7rem;
}

.text-success { color: var(--success); font-weight: 800; }
.text-danger { color: var(--danger); font-weight: 800; }

pre {
    background: #1e293b;
    color: #f8fafc;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.875rem;
}

@media (max-width: 900px) {
    .app-header,
    .header,
    .detail-layout,
    .status-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .detail-layout,
    .status-grid,
    .form-grid {
        display: grid;
    }

    .app-header,
    .header {
        flex-direction: column;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-start;
    }
}

@media (max-width: 720px) {
    .container {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }

    .responsive-table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table th,
    .responsive-table td,
    .responsive-table tr {
        display: block;
    }

    .responsive-table thead {
        display: none;
    }

    .responsive-table tr {
        padding: 0.75rem 0;
        border-bottom: 1px solid var(--border);
    }

    .responsive-table td {
        border-bottom: 0;
        padding: 0.35rem 0;
    }

    .actions-cell {
        text-align: left;
    }
}
