/* ============================================================
   RoomzyMediator Admin UI - Professional Dark Theme
   ============================================================ */

:root {
    --sidebar-width: 240px;
    --sidebar-width-collapsed: 56px;
    --header-height: 56px;
    --bg-base: #0f1117;
    --bg-surface: #181c25;
    --bg-surface-2: #1e2232;
    --bg-surface-3: #252a3a;
    --border-color: #2a3045;
    --text-primary: #e2e8f0;
    --text-secondary: #8892aa;
    --text-muted: #5a6478;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-yellow: #f59e0b;
    --accent-purple: #a855f7;
    --accent-cyan: #06b6d4;
    --font-mono: 'Courier New', Courier, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    height: 100%;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { color: var(--accent-blue-hover); text-decoration: underline; }

/* ── Admin Shell Layout ───────────────────────────────────── */
.admin-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.admin-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
    transition: width 0.25s ease, min-width 0.25s ease;
}

.sidebar-brand {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  background: var(--accent-blue);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
}


.sidebar-brand-text {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.3px;
}

.sidebar-brand-sub {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-top: 1px;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px 16px 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    cursor: pointer;
    text-decoration: none !important;
}

.sidebar-link:hover {
    background-color: var(--bg-surface-2);
    color: var(--text-primary);
    border-left-color: var(--border-color);
}

.sidebar-link.active {
    background-color: rgba(59, 130, 246, 0.12);
    color: var(--accent-blue);
    border-left-color: var(--accent-blue);
}

.sidebar-link .nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border-color); }

/* ── Main Content Area ────────────────────────────────────── */
.admin-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.admin-topbar {
    height: var(--header-height);
    min-height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    gap: 16px;
}

.topbar-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.topbar-meta { display: flex; align-items: center; gap: 16px; font-size: 12px; color: var(--text-muted); }
.admin-content { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; }

/* ── Cards ────────────────────────────────────────────────── */
.card { background-color: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; }

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background-color: var(--bg-surface);
}

.card-header-title { font-size: 13.5px; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px; }

/* ── Stat Cards ───────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 18px;
    position: relative;
    overflow: hidden;
}

.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
.stat-card.blue::before { background: var(--accent-blue); }
.stat-card.green::before { background: var(--accent-green); }
.stat-card.red::before { background: var(--accent-red); }
.stat-card.yellow::before { background: var(--accent-yellow); }
.stat-card.purple::before { background: var(--accent-purple); }
.stat-card.cyan::before { background: var(--accent-cyan); }

.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

/* ── Tables ───────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-surface-2);
    white-space: nowrap;
}

.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border-color); color: var(--text-primary); vertical-align: middle; }
.data-table tbody tr:hover { background-color: var(--bg-surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ── Badges ───────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 4px; letter-spacing: 0.3px; white-space: nowrap; }
.badge-success { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--accent-yellow); }
.badge-info { background: rgba(59, 130, 246, 0.15); color: var(--accent-blue); }
.badge-purple { background: rgba(168, 85, 247, 0.15); color: var(--accent-purple); }
.badge-cyan { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); }
.badge-muted { background: rgba(90, 100, 120, 0.2); color: var(--text-secondary); }

/* ── Direction Dot ────────────────────────────────────────── */
.direction-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.direction-dot.from-roomzy { background: var(--accent-blue); }
.direction-dot.from-channex { background: var(--accent-purple); }
.direction-dot.to-channex { background: var(--accent-yellow); }
.direction-dot.to-roomzy { background: var(--accent-green); }

/* ── Live Feed ────────────────────────────────────────────── */
.feed-container { background-color: var(--bg-base); border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; min-height: 200px; flex: 1; display: flex; flex-direction: column; }
.feed-toolbar { display: grid; grid-template-columns: repeat(7, minmax(80px, 1fr)); align-items: center; padding: 10px 14px; background-color: var(--bg-surface-2); border-bottom: 1px solid var(--border-color); position: sticky; top: 0; z-index: 1; }
.feed-scroll { flex: 1; overflow: auto; font-family: var(--font-mono); font-size: 12.5px; padding: 0; }
.feed-inner { min-width: 560px; }

.feed-item {
    display: grid;
    grid-template-columns: repeat(7, minmax(80px, 1fr));
    gap: 0;
    padding: 7px 14px;
    border-bottom: 1px solid rgba(42, 48, 69, 0.7);
    align-items: center;
    cursor: pointer;
}

.feed-time { display: flex; align-items: center; gap: 5px; color: var(--text-secondary); font-size: 11.5px; overflow: hidden; white-space: nowrap; }
.feed-status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.feed-status-dot.success { background: var(--accent-green); }
.feed-status-dot.failed { background: var(--accent-red); }
.feed-status-dot.ignored { background: var(--text-muted); }
.feed-event { font-weight: 600; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-instance { color: var(--text-secondary); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-property { color: var(--accent-cyan); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-summary { color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-duration { color: var(--text-secondary); text-align: right; font-size: 11px; }
.feed-status { text-align: right; }

.feed-pulse { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-green); animation: pulse 2s infinite; margin-right: 6px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.feed-paused .feed-pulse { background: var(--accent-yellow); animation: none; opacity: 0.7; }

/* ── Forms & Inputs ───────────────────────────────────────── */
.form-control, .form-select { background-color: var(--bg-surface-2); border: 1px solid var(--border-color); color: var(--text-primary); border-radius: 6px; padding: 8px 12px; font-size: 13.5px; transition: border-color 0.15s; width: 100%; }
.form-control:focus, .form-select:focus { outline: none; border-color: var(--accent-blue); background-color: var(--bg-surface-3); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); color: var(--text-primary); }
.form-control::placeholder { color: var(--text-muted); }
.form-select option { background-color: var(--bg-surface-2); color: var(--text-primary); }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; display: block; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; border: 1px solid transparent; cursor: pointer; transition: background 0.15s, border-color 0.15s, opacity 0.15s; text-decoration: none; white-space: nowrap; }
.btn-primary { background-color: var(--accent-blue); color: white; border-color: var(--accent-blue); }
.btn-primary:hover { background-color: var(--accent-blue-hover); border-color: var(--accent-blue-hover); color: white; text-decoration: none; }
.btn-secondary { background-color: var(--bg-surface-3); color: var(--text-primary); border-color: var(--border-color); }
.btn-secondary:hover { background-color: var(--bg-surface-2); color: var(--text-primary); text-decoration: none; }
.btn-danger { background-color: rgba(239, 68, 68, 0.1); color: var(--accent-red); border-color: rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background-color: var(--accent-red); color: white; border-color: var(--accent-red); text-decoration: none; }
.btn-success { background-color: rgba(34, 197, 94, 0.1); color: var(--accent-green); border-color: rgba(34, 197, 94, 0.3); }
.btn-success:hover { background-color: var(--accent-green); color: white; border-color: var(--accent-green); text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ── Alerts ───────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 13.5px; border: 1px solid transparent; display: flex; align-items: flex-start; gap: 10px; }
.alert-danger { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); color: #fca5a5; }
.alert-warning { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.3); color: #fcd34d; }
.alert-success { background: rgba(34, 197, 94, 0.1); border-color: rgba(34, 197, 94, 0.3); color: #86efac; }
.alert-info { background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.3); color: #93c5fd; }

/* ── Accordion ────────────────────────────────────────────── */
.accordion-item { border: 1px solid var(--border-color); border-radius: 6px; margin-bottom: 8px; overflow: hidden; }
.accordion-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background-color: var(--bg-surface-2); cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text-primary); border: none; width: 100%; text-align: left; transition: background 0.15s; }
.accordion-header:hover { background-color: var(--bg-surface-3); }
.accordion-body { border-top: 1px solid var(--border-color); background-color: var(--bg-surface); }
.mapping-level-2 { padding-left: 24px; }
.mapping-level-3 { padding-left: 48px; }

/* ── Login Page ───────────────────────────────────────────── */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background-color: var(--bg-base); background-image: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(59, 130, 246, 0.08), transparent); }
.login-card { background-color: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 12px; padding: 40px; width: 380px; max-width: 95vw; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo-icon { display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; background: linear-gradient(135deg, var(--accent-blue), #6366f1); border-radius: 12px; margin-bottom: 16px; font-size: 24px; }
.login-logo-title { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.login-logo-sub { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

/* ── Utilities ────────────────────────────────────────────── */
.text-primary-color { color: var(--text-primary) !important; }
.text-secondary-color { color: var(--text-secondary) !important; }
.text-muted-color { color: var(--text-muted) !important; }
.text-success { color: var(--accent-green) !important; }
.text-danger { color: var(--accent-red) !important; }
.text-warning { color: var(--accent-yellow) !important; }
.text-info { color: var(--accent-blue) !important; }
.text-mono { font-family: var(--font-mono) !important; font-size: 0.9em; }

.page-header { margin-bottom: 24px; }
.page-header-title { font-size: 20px; font-weight: 700; color: var(--text-primary); margin: 0 0 4px; }
.page-header-sub { font-size: 13px; color: var(--text-muted); margin: 0; }

/* ── Health status indicator ─────────────────────────────── */
.health-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.health-dot.healthy { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.health-dot.degraded { background: var(--accent-yellow); box-shadow: 0 0 6px var(--accent-yellow); }
.health-dot.unhealthy { background: var(--accent-red); box-shadow: 0 0 6px var(--accent-red); }
.health-dot.unknown { background: var(--text-muted); }

/* ── Event Detail Modal ───────────────────────────────────── */
.event-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: modalFadeIn 0.15s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.event-modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    width: 100%;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideUp 0.15s ease;
}

@keyframes modalSlideUp {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.event-modal-body { overflow-y: auto; padding: 18px; }

/* Pinned modal footer: stays visible while the body scrolls a long payload. */
.event-modal-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    padding: 14px 18px;
    background: var(--bg-surface-2);
    border-radius: 0 0 10px 10px;
}

.event-payload-pre {
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 14px;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    overflow: auto;
    max-height: 360px;
    white-space: pre;
    margin: 0;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

#blazor-error-ui {
    background: rgba(239, 68, 68, 0.9);
    padding: 12px 20px;
    border-radius: 6px;
    color: white;
    font-size: 13px;
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9999;
    display: none;
}

/* ── Sidebar: collapsed (icon-only on desktop) ──────────────── */
.admin-sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
}

.admin-sidebar.collapsed .sidebar-brand {
    justify-content: center;
    padding: 18px 0;
    gap: 0;
}

.admin-sidebar.collapsed .sidebar-brand-text,
.admin-sidebar.collapsed .sidebar-brand-sub,
.admin-sidebar.collapsed .sidebar-section-label,
.admin-sidebar.collapsed .nav-label,
.admin-sidebar.collapsed .sidebar-footer {
    display: none;
}

.admin-sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 10px 0;
}

.admin-sidebar.collapsed .nav-icon {
    font-size: 18px;
    width: auto;
}

/* ── Sidebar backdrop (mobile overlay) ─────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 150;
    cursor: pointer;
}

/* ── Feed page: fills remaining viewport height ─────────────── */
.feed-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* ── Outbox page: fills remaining viewport height ───────────── */
/* Mirrors .feed-page. .admin-content is a flex column, so without a
   flex-aware wrapper the tall rows table crushes the stat-grid and
   filters down to a sliver. The fixed-height bands stay pinned and the
   rows card owns the only scroll region. */
.outbox-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.outbox-page .stat-grid,
.outbox-page .outbox-filters,
.outbox-page .outbox-maintenance,
.outbox-page > .page-header,
.outbox-page > .alert {
    flex-shrink: 0;
}

/* The rows card is the single scroll surface. flex:1 + min-height:0 lets it
   absorb leftover height; the inner wrapper scrolls so the sticky header works. */
.outbox-rows-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.outbox-rows-card .card-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.outbox-rows-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

/* Pin the header while the body scrolls. .data-table th already paints an
   opaque background so rows never bleed through underneath. */
.outbox-rows-scroll .data-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

/* ── Light theme overrides ──────────────────────────────────── */
[data-theme="light"] {
    --bg-base: #f0f2f7;
    --bg-surface: #ffffff;
    --bg-surface-2: #f5f7fb;
    --bg-surface-3: #ebedf3;
    --border-color: #d1d9e6;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
}

[data-theme="light"] .login-wrapper {
    background-image: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(59, 130, 246, 0.06), transparent);
}

[data-theme="light"] .event-payload-pre { color: var(--text-secondary); }

/* ── Theme toggle button ────────────────────────────────────── */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    background-color: var(--bg-surface-3);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-size: 15px;
}

.btn-icon:hover {
    background-color: var(--bg-surface-2);
    color: var(--text-primary);
}

/* ── Mobile responsive ──────────────────────────────────────── */
@media (max-width: 767px) {
    /* Sidebar becomes a full-width drawer — always off-canvas by default */
    .admin-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
    }

    /* Show sidebar when NOT in collapsed state */
    .admin-sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    /* Show backdrop when sidebar is open on mobile */
    .sidebar-backdrop.show { display: block; }

    /* Topbar adjustments */
    .topbar-title { font-size: 13px; }
    .admin-topbar { padding: 0 12px; gap: 8px; }
    .admin-content { padding: 16px; }

    /* Stack stat cards in 2 columns on mobile */
    .stat-grid { grid-template-columns: repeat(2, 1fr); }

    /* Stack the 2-col dashboard panels vertically */
    .dashboard-panels { display: flex !important; flex-direction: column !important; }

    /* Feed: drop Summary column on mobile (6 cols, 480px min) */
    .feed-inner { min-width: 480px; }
    .feed-toolbar,
    .feed-item {
        grid-template-columns: repeat(6, minmax(80px, 1fr));
    }
    .feed-toolbar span:nth-child(6),
    .feed-summary { display: none; }
}
