/* ============================================
   XEN NVR - DEEP BLUE MODERN THEME
   ============================================ */

/* Google Fonts loaded via layout <link> */

/* Design System Variables */
:root {
    /* Deep Blue Palette */
    --primary: #1565C0;
    --primary-dark: #0D47A1;
    --primary-light: #42A5F5;
    --primary-glow: rgba(21, 101, 192, 0.35);
    --accent: #00E5FF;
    --accent-glow: rgba(0, 229, 255, 0.2);

    /* Surfaces */
    --background: #060E1A;
    --surface: #0A1628;
    --surface-light: #0F1F35;
    --surface-hover: #162B45;
    --surface-elevated: #1A2D48;

    /* Borders */
    --border-color: rgba(66, 165, 245, 0.12);
    --border-hover: rgba(66, 165, 245, 0.25);
    --border-active: rgba(0, 229, 255, 0.4);

    /* Text */
    --text-primary: #E3F2FD;
    --text-secondary: #90CAF9;
    --text-muted: #546E7A;
    --text-bright: #FFFFFF;

    /* Semantic Colors */
    --success: #00E676;
    --success-bg: rgba(0, 230, 118, 0.12);
    --warning: #FFB300;
    --warning-bg: rgba(255, 179, 0, 0.12);
    --danger: #FF5252;
    --danger-bg: rgba(255, 82, 82, 0.12);
    --info: #00B0FF;
    --info-bg: rgba(0, 176, 255, 0.12);

    /* Status */
    --status-online: #00E676;
    --status-offline: #FF5252;
    --status-recording: #FF5252;

    /* Spacing */
    --navbar-height: 52px;
    --radius: 8px;
    --radius-lg: 12px;
}

/* ============================================
   RESET & BASE
   ============================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    background: var(--background);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ============================================
   NAVBAR
   ============================================ */

.nvr-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: rgba(10, 22, 40, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
}

.nvr-navbar-inner {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 20px;
    max-width: 100%;
}

.nvr-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-bright);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    margin-right: 32px;
    flex-shrink: 0;
}

.nvr-brand-icon {
    width: 24px;
    height: 24px;
    color: var(--accent);
}

.nvr-nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.nvr-nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nvr-nav-link:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.nvr-nav-link.active {
    color: var(--accent);
    background: rgba(0, 229, 255, 0.08);
}

.nvr-nav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.nvr-username {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.nvr-btn-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

.nvr-btn-logout:hover {
    color: var(--danger);
    background: var(--danger-bg);
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.nvr-main {
    padding-top: calc(var(--navbar-height) + 16px);
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 20px;
    min-height: 100vh;
}

.nvr-main-fullscreen {
    padding-top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   ALERTS
   ============================================ */

.nvr-alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.875rem;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

.nvr-alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(0, 230, 118, 0.2);
}

.nvr-alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(255, 82, 82, 0.2);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   LOGIN PAGE
   ============================================ */

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo svg {
    width: 48px;
    height: 48px;
    color: var(--accent);
    margin-bottom: 12px;
}

.login-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: -0.03em;
}

.login-logo p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================
   FORMS
   ============================================ */

.nvr-form-group {
    margin-bottom: 20px;
}

.nvr-form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.nvr-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--surface-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    outline: none;
}

.nvr-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.nvr-input::placeholder {
    color: var(--text-muted);
}

.nvr-checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.nvr-checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.nvr-checkbox-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
}

select.nvr-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2390CAF9' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ============================================
   BUTTONS
   ============================================ */

.nvr-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    text-decoration: none;
    white-space: nowrap;
}

.nvr-btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--text-bright);
    box-shadow: 0 2px 8px var(--primary-glow);
}

.nvr-btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    box-shadow: 0 4px 16px var(--primary-glow);
    transform: translateY(-1px);
    color: var(--text-bright);
}

.nvr-btn-accent {
    background: linear-gradient(135deg, #00BCD4, #0097A7);
    color: var(--text-bright);
    box-shadow: 0 2px 8px rgba(0, 188, 212, 0.3);
}

.nvr-btn-accent:hover {
    box-shadow: 0 4px 16px rgba(0, 188, 212, 0.4);
    transform: translateY(-1px);
    color: var(--text-bright);
}

.nvr-btn-danger {
    background: linear-gradient(135deg, #E53935, #C62828);
    color: var(--text-bright);
}

.nvr-btn-danger:hover {
    box-shadow: 0 4px 12px rgba(229, 57, 53, 0.3);
    transform: translateY(-1px);
    color: var(--text-bright);
}

.nvr-btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.nvr-btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.nvr-btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.nvr-btn-block {
    width: 100%;
}

/* ============================================
   CAMERA GRID (DASHBOARD)
   ============================================ */

.nvr-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.nvr-page-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-bright);
    letter-spacing: -0.02em;
}

.nvr-camera-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--surface);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.nvr-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
}

/* Optimize grid based on camera count */
.nvr-grid[data-cameras="1"] { grid-template-columns: 1fr; }
.nvr-grid[data-cameras="2"] { grid-template-columns: repeat(2, 1fr); }
.nvr-grid[data-cameras="3"],
.nvr-grid[data-cameras="4"] { grid-template-columns: repeat(2, 1fr); }

.nvr-camera-tile {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    aspect-ratio: 16 / 9;
}

.nvr-camera-tile:hover {
    border-color: var(--border-active);
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.1);
    transform: scale(1.01);
}

.nvr-camera-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.nvr-camera-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 14px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
}

.nvr-camera-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-bright);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.nvr-camera-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nvr-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.nvr-status-dot.online {
    background: var(--status-online);
    box-shadow: 0 0 8px var(--status-online);
    animation: pulse-green 2s infinite;
}

.nvr-status-dot.recording {
    background: var(--status-recording);
    box-shadow: 0 0 8px var(--status-recording);
    animation: pulse-red 1.5s infinite;
}

.nvr-status-dot.offline {
    background: var(--text-muted);
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--status-recording); }
    50% { opacity: 0.7; box-shadow: 0 0 12px var(--status-recording); }
}

/* Camera empty state */
.nvr-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.nvr-empty-state svg {
    width: 64px;
    height: 64px;
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.5;
}

.nvr-empty-state h2 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.nvr-empty-state p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ============================================
   FULLSCREEN CAMERA VIEW
   ============================================ */

.nvr-fullscreen-view {
    position: relative;
    width: 100%;
    height: calc(100vh - var(--navbar-height) - 32px);
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.nvr-fullscreen-view video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.nvr-fullscreen-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px 20px;
    background: linear-gradient(rgba(0, 0, 0, 0.7), transparent);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.nvr-fullscreen-view:hover .nvr-fullscreen-header {
    opacity: 1;
}

.nvr-fullscreen-back {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-bright);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}

.nvr-fullscreen-back:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-bright);
}

/* ============================================
   PLAYBACK & TIMELINE
   ============================================ */

.nvr-playback-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--navbar-height) - 32px);
    gap: 0;
}

.nvr-playback-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 12px 0;
    flex-shrink: 0;
}

.nvr-playback-video {
    flex: 1;
    background: #000;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    overflow: hidden;
    min-height: 0;
    position: relative;
}

.nvr-playback-video video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.nvr-playback-no-video {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.nvr-timeline-container {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    padding: 12px 16px;
    flex-shrink: 0;
}

.nvr-timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.nvr-timeline-time {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.nvr-timeline-zoom {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.nvr-timeline-canvas-wrap {
    position: relative;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
}

#timelineCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ============================================
   ADMIN PAGES
   ============================================ */

.nvr-admin-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.nvr-admin-nav a {
    padding: 8px 16px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.nvr-admin-nav a:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.nvr-admin-nav a.active {
    color: var(--accent);
    background: rgba(0, 229, 255, 0.08);
}

.nvr-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 16px;
}

.nvr-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.nvr-card-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-bright);
}

.nvr-table {
    width: 100%;
    border-collapse: collapse;
}

.nvr-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.nvr-table td {
    padding: 12px 14px;
    font-size: 0.875rem;
    border-bottom: 1px solid rgba(66, 165, 245, 0.06);
    color: var(--text-primary);
}

.nvr-table tr:hover td {
    background: var(--surface-hover);
}

.nvr-table .nvr-url-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.nvr-table-actions {
    display: flex;
    gap: 6px;
}

/* ============================================
   FORM CARD (Add/Edit Camera)
   ============================================ */

.nvr-form-card {
    max-width: 600px;
    margin: 0 auto;
}

.nvr-form-card h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 24px;
}

.nvr-form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.nvr-form-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

/* ============================================
   VALIDATION
   ============================================ */

.text-danger,
.field-validation-error {
    color: var(--danger) !important;
    font-size: 0.8rem;
}

.validation-summary-errors ul {
    list-style: none;
    padding: 0;
}

.validation-summary-errors ul li {
    color: var(--danger);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.input-validation-error {
    border-color: var(--danger) !important;
}

/* ============================================
   SCROLLBAR
   ============================================ */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-hover);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .nvr-nav-links {
        display: none;
    }

    .nvr-grid {
        grid-template-columns: 1fr;
    }

    .nvr-page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

/* ============================================
   UTILITIES
   ============================================ */

.nvr-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nvr-badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.nvr-badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.nvr-badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.nvr-badge-info {
    background: var(--info-bg);
    color: var(--info);
}

.nvr-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 20px 0;
}