/* Demarc Design Tokens — forwarded from tokens.css */
/* See tokens.css for the full token definitions.
   All design changes should go into tokens.css first,
   with aliases forwarded here for backward compatibility. */

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

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

/* Top Bar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-diamond {
    display: inline-block;
    width: 18px;
    height: 18px;
    color: var(--accent);
}

/* Status Indicator */
.status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
    transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.warning {
    background: var(--yellow);
    box-shadow: 0 0 6px rgba(234, 179, 8, 0.5);
}

.status-dot.error {
    background: var(--red);
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Connection Lost Banner */
.banner {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--red-dim);
    color: var(--red);
    font-size: 13px;
    text-align: center;
}

.banner.visible {
    display: flex;
}

/* Main Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

/* Card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-card-header);
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.card-body {
    padding: 20px;
}

/* Compact Cards (devices, policies, flows) */
.compact-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 8px;
}

.compact-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.compact-divider {
    height: 1px;
    background: var(--border-color);
    margin: 12px 0;
}

.compact-detail {
    font-size: 13px;
    color: var(--text-secondary);
}

.compact-detail span {
    color: var(--accent);
    font-weight: 500;
}

/* Icon containers */
.card-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.icon-devices {
    background: var(--blue-dim);
    color: var(--blue);
}

.icon-policies {
    background: var(--accent-dim);
    color: var(--accent);
}

.icon-flows {
    background: var(--green-dim);
    color: var(--green);
}

.icon-audit {
    background: var(--yellow-dim);
    color: var(--yellow);
}

/* Audit Table Card */
.audit-card {
    grid-column: 1 / -1;
}

.table-wrap {
    overflow-x: auto;
    max-height: 200px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    position: sticky;
    top: 0;
    background: var(--bg-card-header);
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

tbody td {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    white-space: nowrap;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.event-type {
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--accent);
    font-size: 12px;
}

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

/* Flow Table */
.flow-section {
    grid-column: 1 / -1;
}

.flow-table-wrap {
    overflow-x: auto;
    max-height: 350px;
    overflow-y: auto;
}

.flow-table td.verdict-allow {
    color: var(--green);
}

.flow-table td.verdict-deny {
    color: var(--red);
}

.flow-table td.verdict-learn {
    color: var(--yellow);
}

/* Badge Styling for Status */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.badge-status-applied, .badge-applied, td.status-applied span {
    color: var(--green);
    background: var(--green-dim);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-status-partial, .badge-partial, td.status-partial span {
    color: var(--yellow);
    background: var(--yellow-dim);
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.badge-status-failed, .badge-failed, td.status-failed span {
    color: var(--red);
    background: var(--red-dim);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-status-skipped, .badge-skipped, td.status-skipped span {
    color: var(--text-secondary);
    background: rgba(136, 146, 168, 0.1);
    border: 1px solid rgba(136, 146, 168, 0.2);
}

.badge-status-unknown, .badge-unknown, td.status-unknown span {
    color: var(--text-muted);
    background: rgba(90, 101, 128, 0.1);
    border: 1px solid rgba(90, 101, 128, 0.2);
}

.text-muted {
    color: var(--text-muted);
    font-size: 11px;
}

/* Bundle Status Section */
.bundle-status-section {
    grid-column: 1 / -1;
}

.cap-summary {
    font-size: 12px;
    line-height: 1.4;
    max-width: 300px;
}

.device-summary {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
}

.device-summary span {
    color: var(--accent);
    font-weight: 500;
}

/* Empty States */
.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Section header */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.section-count {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ==================== Shell Layout — mobile/tablet responsive ==================== */

/* tablet: <= 1024px — sidebar becomes top/header nav, shell becomes single column */
@media (max-width: 1024px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Shift main content to accommodate sidebar; keep existing layout until mobile breakpoint */
    .shell main {
        width: calc(100vw - 260px);
        margin-left: 260px;
        padding: 16px;
    }

    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid var(--ds-border-subtle);
        padding: var(--space-4);
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        gap: var(--space-4);
    }

    .sidebar-brand {
        margin-bottom: 0;
        padding-right: var(--space-4);
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
    }

    .sidebar-nav a,
    .sidebar-nav button {
        white-space: nowrap;
    }
}

/* mobile: <= 640px — full responsive layout for phones */
@media (max-width: 640px) {
    /* Cards grid collapses to single column */
    .cards-grid {
        grid-template-columns: 1fr;
    }

    /* Shell main column, no sidebar offset */
    .shell {
        display: block;
    }

    .shell main {
        margin-left: 0;
        width: 100vw;
        padding: 16px;
    }

    /* Sidebar fully horizontal header nav on mobile */
    .sidebar {
        padding: var(--space-3) var(--space-2);
    }

    .sidebar-brand {
        display: none;
    }

    .sidebar-nav a,
    .sidebar-nav button {
        /* mobile: ensure 44px minimum touch targets */
        min-height: 44px;
        padding: 10px 10px;
        font-size: 13px;
        flex: 1 1 auto;
        justify-content: center;
        gap: 4px;
    }

    .sidebar-nav .nav-icon {
        width: 16px;
        height: 16px;
    }

    /* Action buttons wrap/stack on mobile */
    .top > .actions,
    .section-header > div[style*="flex"],
    .auth-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .top > .actions {
        flex: 1 1 100%;
        margin-top: 8px;
    }

    .btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    /* Endpoint client grid collapses to single column on mobile */
    [data-section="endpoint"] [style*="grid-template-columns:1fr 1fr"],
    .card[data-section="endpoint"],
    #endpoint-grid-wrapper {
        grid-template-columns: 1fr !important;
    }

    /* Mobile endpoint 2-column KV grid stays where it fits */
    #ep-kv {
        grid-template-columns: 1fr !important;
    }

    /* EPA action buttons row */
    [data-section="endpoint"] [style*="grid-template-columns:repeat(3,1fr)"] {
        grid-template-columns: 1fr !important;
    }

    /* Tables: horizontal scroll, no overflow */
    .table-wrap,
    .flow-table-wrap,
    #bundle-status-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    table,
    .table-wrap table,
    .flow-table-wrap table {
        min-width: 100%;
        width: auto;
    }

    /* Mobile: wrap/scroll monospace values (hashes, IDs, UUIDs) instead of overflowing */
    tbody td,
    .event-type,
    .event-time,
    .mono,
    code,
    [style*="font-family:var(--font-mono)"],
    [style*="font-family: 'SF Mono'"],
    [style*="font-family: 'Fira Code'"],
    pre,
    #ep-terminal {
        white-space: normal !important;
        word-break: break-all;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Card body padding adjustment on mobile */
    .card-body {
        padding: 14px;
    }

    .card-header {
        padding: 12px 14px;
    }

    .compact-value {
        font-size: 28px;
    }

    /* Empty state padding */
    .empty-state {
        padding: 24px;
    }

    /* Toast positioning for mobile */
    .toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
        transform: translateY(100px);
    }

    .toast.visible {
        transform: translateY(0);
    }

    /* Modal full-width on mobile */
    .modal {
        max-width: 100%;
        margin: 0 8px;
        padding: var(--space-4);
    }

    /* Flow bar visualization adapts to narrow screens */
    .flowbar {
        height: 60px;
    }
}

/* ==================== Sidebar Component ==================== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    background: var(--ds-bg-secondary);
    border-right: 1px solid var(--ds-border-subtle);
    display: flex;
    flex-direction: column;
    padding: var(--space-6) var(--space-4);
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-8);
}

.sidebar-mark {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(90deg, var(--ds-accent) 0 50%, var(--ds-border-subtle) 50%);
    box-shadow: 0 0 0 1px rgba(255,255,255,.06);
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
}

.sidebar-brand-text strong {
    font-size: 18px;
    font-weight: 700;
    color: var(--ds-text-primary);
    letter-spacing: 0.2px;
}

.sidebar-brand-text span {
    font-size: 11px;
    color: var(--ds-text-secondary);
    line-height: 1.2;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-nav a,
.sidebar-nav button {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--ds-text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover,
.sidebar-nav button:hover {
    background: var(--ds-bg-elevated);
    color: var(--ds-text-primary);
}

.sidebar-nav a.active,
.sidebar-nav button[aria-current="page"] {
    background: var(--ds-bg-elevated);
    color: var(--ds-text-primary);
    font-weight: 600;
}

.sidebar-nav a:focus-visible,
.sidebar-nav button:focus-visible {
    outline: 2px solid var(--ds-accent);
    outline-offset: -2px;
}

.sidebar-nav .nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-nav a.active .nav-icon,
.sidebar-nav button[aria-current="page"] .nav-icon {
    opacity: 1;
}

/* ==================== Shell Layout (Sidebar + Main) ==================== */
.shell {
    display: block;
    min-height: 100vh;
}

.shell main {
    margin-left: 260px;
    width: calc(100vw - 260px);
    padding: var(--space-6);
}

/* ==================== Action Buttons ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--ds-border-default);
    background: var(--ds-bg-input);
    color: var(--ds-text-primary);
    border-radius: var(--radius-md);
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
    background: var(--ds-bg-elevated);
    border-color: var(--ds-text-muted);
}

.btn:focus-visible {
    outline: 2px solid var(--ds-accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--ds-accent);
    color: var(--ds-accent-on-dark);
    border-color: var(--ds-accent);
}

.btn-primary:hover {
    background: #e09535;
    border-color: #e09535;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

/* ==================== Improved Badge with Dot Indicator ==================== */
.badge .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
    vertical-align: middle;
}

.badge-enforce .status-dot {
    background: var(--ds-status-ok);
    box-shadow: 0 0 4px rgba(47,179,109,.5);
}

.badge-audit .status-dot {
    background: var(--ds-status-warn);
    box-shadow: 0 0 4px rgba(255,210,122,.5);
}

.badge-learn .status-dot {
    background: var(--ds-status-info);
    box-shadow: 0 0 4px rgba(126,177,240,.5);
}

/* ==================== Event Cards ==================== */
.event-card {
    display: flex;
    gap: var(--space-3);
    padding: 12px 0;
    border-bottom: 1px solid var(--ds-border-subtle);
}

.event-card:last-child {
    border-bottom: none;
}

.event-time {
    font-size: 12px;
    color: var(--ds-text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
    min-width: 60px;
}

.event-content {
    flex: 1;
}

.event-content strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ds-text-primary);
    margin-bottom: 2px;
}

.event-content p {
    font-size: 12px;
    color: var(--ds-text-secondary);
    line-height: 1.4;
}

/* ==================== Flow Bar Visualization ==================== */
.flowbar {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 100px;
    padding: 0 4px;
}

.flowbar .bar {
    flex: 1;
    border-radius: 2px 2px 0 0;
    min-width: 4px;
    transition: height 0.3s;
}

.flowbar .bar.allow {
    background: var(--ds-status-ok);
    opacity: 0.7;
}

.flowbar .bar.deny {
    background: var(--ds-status-error);
    opacity: 0.7;
}

.flowbar .bar.learn {
    background: var(--ds-status-warn);
    opacity: 0.7;
}

.flowbar + .legend {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-2);
    font-size: 11px;
    color: var(--ds-text-secondary);
}

.legend span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend .swatch {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    display: inline-block;
}

.legend .swatch.allow { background: var(--ds-status-ok); }
.legend .swatch.deny { background: var(--ds-status-error); }
.legend .swatch.learn { background: var(--ds-status-warn); }

/* ==================== Policy Cards ==================== */
.policy-card {
    padding: 14px;
    background: var(--ds-bg-card);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-3);
}

.policy-card:last-child {
    margin-bottom: 0;
}

.policy-card h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--ds-text-primary);
    margin-bottom: 4px;
}

.policy-card p {
    font-size: 12px;
    color: var(--ds-text-secondary);
    line-height: 1.4;
}

.policy-prio {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--ds-text-muted);
    text-align: right;
}

/* ==================== Modal Overlay ==================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: var(--ds-bg-card);
    border: 1px solid var(--ds-border-default);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.45);
    padding: var(--space-6);
    max-width: 440px;
    width: 100%;
    color: var(--ds-text-primary);
}

.modal h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: var(--space-4);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-5);
}

/* ==================== QR Code Placeholder ==================== */
.qr-placeholder {
    width: 140px;
    height: 140px;
    border: 1px dashed var(--ds-border-default);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: var(--space-4) auto;
    color: var(--ds-text-muted);
    font-size: 11px;
}

/* ==================== Toast / Notification ==================== */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--ds-bg-card);
    border: 1px solid var(--ds-border-default);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    font-size: 13px;
    color: var(--ds-text-primary);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 300;
    transform: translateY(100px);
    opacity: 0;
    transition: transform 0.25s, opacity 0.25s;
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.toast.success { border-left: 3px solid var(--ds-status-ok); }
.toast.error { border-left: 3px solid var(--ds-status-error); }
.toast.info { border-left: 3px solid var(--ds-status-info); }

/* ==================== Eyebrow Label ==================== */
.eyebrow {
    color: var(--ds-text-secondary);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* ==================== Workspace Layout ==================== */
.workspace {
    padding: 0 0 0 var(--space-6);
}

/* ==================== Reduced Motion ==================== */
@media (prefers-reduced-motion: reduce) {
    .status-dot.error,
    .spinner,
    .toast {
        animation: none;
        transition: none;
    }
}

