:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #fbbf24;
    --error-color: #ef4444;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --surface-elevated: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --accent-color: #6366f1;
    --navbar-bg: #ffffff;
    --card-bg: #ffffff;
    --input-bg: #ffffff;
}

[data-theme="dark"] {
    --primary-color: #3b82f6;
    --secondary-color: #94a3b8;
    --success-color: #22c55e;
    --warning-color: #fbbf24;
    --error-color: #f87171;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-elevated: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --accent-color: #818cf8;
    --navbar-bg: #1e293b;
    --card-bg: #1e293b;
    --input-bg: #0f172a;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
}

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

@media (min-width: 1800px) {
    .container {
        max-width: 1800px;
    }
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.main-content {
    width: auto;
    padding: 2rem 1.5rem;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.main-content:has(.flex-fill) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.footer {
    flex-shrink: 0;
}

.main-content:has(.flex-fill) > .container {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.main-content:has(.flex-fill) > .container > div:has(.flex-fill) {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.flex-fill {
    flex: 1;
    min-height: 0;
}

.flex-fill:not(.page-two-col):not(.page-two-col--wide-left):not(.page-two-col--wide-right) {
    display: flex;
    flex-direction: column;
}

.flex-fill.page-two-col,
.flex-fill.page-two-col--wide-left,
.flex-fill.page-two-col--wide-right {
    align-items: stretch;
}

.flex-fill > .section,
.flex-fill > .card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.flex-fill > .table-container,
.flex-fill > .card-body,
.flex-fill > .section > .table-container,
.flex-fill.section > .table-container,
.flex-fill.card > .card-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.dashboard {
    padding: 0;
}

.navbar { display: none; }

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
}

.dashboard-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    min-width: 0;
}

.dashboard-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.tier-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: white;
    border-radius: 0.5rem;
    font-weight: 600;
    box-shadow: var(--shadow);
}

.tier-icon {
    font-size: 1.25rem;
}

.tier-text {
    font-size: 0.875rem;
}

.time-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.time-filter label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.time-select {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: var(--surface-color);
    color: var(--text-primary);
    font-size: 0.875rem;
    min-width: 120px;
}

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

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface-color);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
}

.status-dot.status-running {
    background: var(--success-color);
    animation: pulse 2s infinite;
}

.status-dot.status-stopped {
    background: var(--error-color);
}

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

.status-text {
    font-weight: 500;
    color: var(--text-primary);
}

.auto-refresh-note {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

.sensor-widgets-section {
    background: var(--surface-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

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

.section-header-inline h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

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

.sensor-widget {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--background-color);
    border-radius: 0.5rem;
    border-left: 3px solid var(--primary-color);
    transition: transform 0.2s, box-shadow 0.2s;
}

.sensor-widget:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.sensor-widget.alert {
    border-left-color: var(--error-color);
    background: var(--surface-elevated);
}

.sensor-icon {
    font-size: 2rem;
    line-height: 1;
}

.sensor-info {
    flex: 1;
}

.sensor-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.sensor-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.dns-widget-section {
    background: var(--surface-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.dns-widget {
    border-radius: 8px;
}

.dns-widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
}

.dns-widget-stat {
    text-align: center;
}

.dns-widget-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dns-widget-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.alert-type {
    background: var(--background-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.severity {
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: white !important;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.severity-low { background: #64748b !important; }
.severity-medium { background: #f59e0b !important; }
.severity-high { background: #f97316 !important; }
.severity-critical { background: #ef4444 !important; }
.severity-warning { background: #fbbf24 !important; }
.severity-info { background: #64748b !important; }

.time-cell {
    font-family: 'SF Mono', Monaco, monospace;
    color: var(--text-secondary);
}

.ip-cell {
    font-family: 'SF Mono', Monaco, monospace;
    font-weight: 500;
}

.count-cell {
    font-weight: 600;
    text-align: right;
}

.description-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.activity-bar {
    width: 100px;
    height: 8px;
    background: var(--background-color);
    border-radius: 4px;
    overflow: hidden;
}

.activity-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
}

.action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    background: var(--background-color);
    border-radius: 0.5rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s;
    cursor: pointer;
}

.action-card:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

.action-card:hover .action-icon img {
    filter: brightness(0) invert(1);
}

.action-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.action-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.action-desc {
    font-size: 0.875rem;
    opacity: 0.8;
    text-align: center;
}

.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 1.5rem;
    padding: 1.5rem;
}

.chart-panel {
    background: var(--background-color);
    border-radius: 0.5rem;
    padding: 1rem;
}

.chart-panel h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.d3-chart {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-empty {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 2rem;
}

.chart-controls {
    display: flex;
    gap: 0.5rem;
}

.d3-chart svg {
    font-family: inherit;
}

.d3-chart .bar:hover {
    opacity: 1;
    fill: var(--primary-color);
}

.d3-chart .alert-dot:hover {
    r: 8;
    stroke-width: 3;
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1rem;
    }

    .dashboard-header,
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .page-actions,
    .dashboard-controls {
        width: 100%;
        justify-content: flex-start;
    }

    .action-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .charts-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .chart-panel {
        padding: 0.75rem;
    }

    .d3-chart {
        min-height: 150px;
    }
}

body.kiosk-mode .dashboard,
body.kiosk-mode .alerts-page,
body.kiosk-mode .devices-page,
body.kiosk-mode .logs-page,
body.kiosk-mode .settings-page,
body.kiosk-mode .reports-page,
body.kiosk-mode .modules-page {
    max-width: 100% !important;
    padding-left: 2rem;
    padding-right: 2rem;
}

body.kiosk-mode .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 2rem;
}

body.kiosk-mode .stat-card {
    padding: 2rem;
}

body.kiosk-mode .alerts-page .stat-card,
body.kiosk-mode .logs-page .stat-card {
    padding: 2rem;
    transform: none;
}

body.kiosk-mode .alerts-page .section,
body.kiosk-mode .logs-page .section {
    width: 100%;
    padding-top: 0.5rem;
}

body.kiosk-mode .alerts-page .stats-grid,
body.kiosk-mode .logs-page .stats-grid {
    padding: 0 0.5rem;
    margin-top: 1rem;
}

body.kiosk-mode .stat-label {
    white-space: nowrap;
}

body.kiosk-mode .stat-value {
    font-size: 3rem;
    font-weight: 700;
}

body.kiosk-mode .stat-label {
    font-size: 1.1rem;
}

body.kiosk-mode footer {
    display: none;
}

body.kiosk-mode .chart-panel {
    grid-column: 1 / -1;
}

body.kiosk-mode::before {
    content: 'KIOSK MODE - Press ESC to exit';
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 1000;
    opacity: 0.8;
    animation: fadeInOut 3s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.9; }
}

body.touch-device .btn,
body.touch-device button {
    min-width: 44px;
    min-height: 44px;
    padding: 0.75rem 1.25rem;
}

body.touch-device .btn:active,
body.touch-device .card:active,
body.touch-device .stat-card:active {
    transform: scale(0.98);
    opacity: 0.9;
    transition: all 0.1s ease;
}

body.touch-device .toggle-switch {
    min-width: 60px;
    min-height: 34px;
}

body.touch-device .toggle-slider {
    width: 60px;
    height: 34px;
}

body.touch-device .toggle-slider:before {
    height: 26px;
    width: 26px;
}

@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .card:hover,
    .stat-card:hover {
        transform: none;
        box-shadow: var(--shadow);
    }

    .btn:active,
    .card:active {
        transform: scale(0.98);
    }
}

body.touch-device .sensor-widget {
    min-height: 100px;
    padding: 1.25rem;
}

body.touch-device .alert-card {
    padding: 1.25rem;
    margin-bottom: 1rem;
}

body.touch-device .modal-close {
    min-width: 48px;
    min-height: 48px;
    font-size: 2rem;
}

body.touch-device .stat-card,
body.touch-device .sensor-widget {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body.touch-device .alert-description,
body.touch-device .module-description,
body.touch-device p {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

@media (max-width: 768px) {
    body.kiosk-mode .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    body.kiosk-mode .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    body.kiosk-mode .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    body.kiosk-mode .stat-card {
        padding: 0.75rem;
    }

    body.kiosk-mode .stat-value {
        font-size: 2rem !important;
        line-height: 1.2;
    }

    body.kiosk-mode .stat-label {
        font-size: 0.85rem !important;
        white-space: normal;
    }

    body.kiosk-mode::before {
        font-size: 0.65rem;
        padding: 0.375rem 0.75rem;
        bottom: 0.5rem;
        right: 0.5rem;
    }
}

@media (max-width: 600px) {
    body.kiosk-mode .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    body.kiosk-mode .stat-card {
        padding: 0.5rem 0.75rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    body.kiosk-mode .stat-value {
        font-size: 1.75rem !important;
    }

    body.kiosk-mode .stat-label {
        font-size: 0.8rem !important;
    }

    body.kiosk-mode::before {
        display: none;
    }
}

@media (orientation: landscape) and (max-height: 768px) {
    body.kiosk-mode .stat-card {
        padding: 1rem;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    body.kiosk-mode .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
    }

    body.kiosk-mode .stat-card {
        padding: 0.5rem;
    }

    body.kiosk-mode .stat-value {
        font-size: 1.5rem !important;
        line-height: 1.1;
    }

    body.kiosk-mode .stat-label {
        font-size: 0.7rem !important;
        line-height: 1.2;
    }

    body.kiosk-mode::before {
        display: none;
    }

    body.kiosk-mode .container {
        padding: 0.75rem;
    }

    body.kiosk-mode .section-title {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
}
