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

:root {
    --bg-primary: #0f1923;
    --bg-secondary: #1a2733;
    --bg-card: #1e2d3d;
    --text-primary: #e8edf2;
    --text-secondary: #8899aa;
    --accent-blue: #00b4d8;
    --accent-green: #00c853;
    --accent-red: #ff1744;
    --accent-orange: #ff9100;
    --accent-yellow: #ffd600;
    --border-color: #2a3f52;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ── Epiroc Branded Navigation Bar ──
   Background: #425563 (Epiroc Grey) — hardcoded, NOT a CSS variable so it
   is never overridden by any theme or branding setting.
   Source: Epiroc production CSS → .c-header { background: #425563; color: #FFF }
*/
header.epiroc-navbar {
    background: #425563;
    min-height: 56px;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Logo + brand area */
.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0;
    text-decoration: none;
}

.navbar-logo {
    height: 34px;
    width: auto;
    display: block;
    flex-shrink: 0;
}

/* Separator between logo area and app name */
.brand-divider {
    height: 36px;
    width: 0;
    border-right: 1px solid rgba(255,255,255,0.2);
    margin: 0 16px;
    flex-shrink: 0;
}

/* App name stack */
.navbar-app-name {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-title {
    font-size: 1.0rem;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    line-height: 1.2;
    letter-spacing: 0.01em;
}

.app-subtitle {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
    line-height: 1;
    letter-spacing: 0.02em;
}

/* Right side: clock + status badge */
.navbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-clock {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.6);
    font-family: 'Courier New', monospace;
    letter-spacing: 0.03em;
}

/* Connection badge on the Epiroc navbar */
header.epiroc-navbar .badge {
    border: 1px solid rgba(255,255,255,0.25);
    font-size: 0.7rem;
}

header.epiroc-navbar .badge-disconnected {
    background: rgba(255,23,68,0.85);
    color: #fff;
    border-color: rgba(255,23,68,0.6);
}

header.epiroc-navbar .badge-connected {
    background: rgba(0,200,83,0.85);
    color: #fff;
    border-color: rgba(0,200,83,0.6);
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-disconnected { background: var(--accent-red); color: white; }
.badge-connected { background: var(--accent-green); color: white; }
.badge-info { background: var(--accent-blue); color: white; }
.badge-danger { background: var(--accent-red); color: white; }
.badge-warning { background: var(--accent-orange); color: white; }

/* Scenario Bar */
.scenario-bar {
    background: linear-gradient(135deg, var(--bg-secondary), #1a2f40);
    border-bottom: 2px solid var(--accent-orange);
}

.scenario-select {
    min-width: 200px;
    font-weight: 600;
    border-color: var(--accent-orange) !important;
}

.scenario-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-left: 8px;
}

/* Control Bar */
.control-bar {
    padding: 10px 24px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
}

.control-divider {
    width: 1px;
    height: 28px;
    background: var(--border-color);
    margin: 0 6px;
}

.btn-sim {
    padding: 6px 14px;
    border: 1px solid var(--accent-blue);
    border-radius: 6px;
    background: transparent;
    color: var(--accent-blue);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
}
.btn-sim:hover:not(:disabled) { background: rgba(0,180,216,0.15); }
.btn-sim:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-sim-play {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    background: #ff9100;
    color: white;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
}
.btn-sim-play:hover:not(:disabled) { background: #e68200; }
.btn-sim-play:disabled { opacity: 0.4; cursor: not-allowed; }

.sim-select {
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.8rem;
    max-width: 180px;
}

.speed-select { max-width: 65px; }

.mode-badge {
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.mode-badge.live { background: rgba(0,200,83,0.15); color: var(--accent-green); border-color: var(--accent-green); }
.mode-badge.simulation { background: rgba(255,145,0,0.15); color: var(--accent-orange); border-color: var(--accent-orange); }

/* Simulation Progress */
.sim-progress-container {
    padding: 4px 24px 8px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sim-seek {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-primary);
    border-radius: 3px;
    outline: none;
}

.sim-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-orange);
    cursor: pointer;
}

.sim-progress-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 40px;
}

.stream-info {
    margin-left: auto;
    display: flex;
    gap: 14px;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Health Emergency Styles */
.status-dot.emergency {
    background: var(--accent-red);
    box-shadow: 0 0 12px var(--accent-red);
    animation: pulse-fast 0.5s infinite;
}

.status-dot.normal {
    background: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
}

@keyframes pulse-fast {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.3); }
}

/* Buttons */
.btn {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s;
}

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

.btn-success { background: var(--accent-green); color: white; }
.btn-success:hover:not(:disabled) { background: #00a846; }
.btn-danger { background: var(--accent-red); color: white; }
.btn-danger:hover:not(:disabled) { background: #d50032; }
.btn-primary { background: var(--accent-blue); color: white; }
.btn-primary:hover:not(:disabled) { background: #0096b7; }
.btn-sm { padding: 4px 12px; font-size: 0.75rem; }

/* Main Grid */
main {
    padding: 0;
}

.grid-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: auto auto;
    gap: 16px;
    padding: 16px 24px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

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

.card-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

.card-body {
    padding: 16px;
}

/* Video Card */
.video-card {
    grid-row: 1 / 2;
    grid-column: 1 / 2;
}

.video-container {
    position: relative;
    background: #000;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container img {
    width: 100%;
    height: auto;
    max-height: 500px;
    object-fit: contain;
}

.placeholder {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}

.placeholder svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

/* Status Card */
.status-card {
    grid-row: 1 / 2;
    grid-column: 2 / 3;
}

.status-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.status-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.status-section h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 1.1rem;
    font-weight: 600;
}

.status-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: background 0.3s;
}

.status-dot.stable { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }
.status-dot.unstable { background: var(--accent-red); box-shadow: 0 0 8px var(--accent-red); animation: pulse 1s infinite; }
.status-dot.detected { background: var(--accent-red); box-shadow: 0 0 8px var(--accent-red); animation: pulse 1s infinite; }
.status-dot.safe { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }

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

.status-detail {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.82rem;
}

.status-detail label {
    color: var(--text-secondary);
    min-width: 110px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-blue);
    border-radius: 4px;
    transition: width 0.3s, background 0.3s;
}

.progress-fill.warning { background: var(--accent-orange); }
.progress-fill.danger { background: var(--accent-red); }

/* Alerts Card */
.alerts-card {
    grid-row: 2 / 3;
    grid-column: 2 / 3;
    max-height: 350px;
}

.alerts-card .card-body {
    max-height: 280px;
    overflow-y: auto;
}

.no-alerts {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
    font-size: 0.85rem;
}

.alert-item {
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    border-left: 4px solid;
    font-size: 0.82rem;
    background: var(--bg-secondary);
}

.alert-item.critical { border-color: var(--accent-red); }
.alert-item.high { border-color: var(--accent-orange); }
.alert-item.medium { border-color: var(--accent-yellow); }
.alert-item.low { border-color: var(--accent-blue); }

.alert-item .alert-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.alert-item .alert-type {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
}

.alert-item .alert-time {
    color: var(--text-secondary);
    font-size: 0.72rem;
}

.alert-item .alert-message {
    color: var(--text-secondary);
}

/* Events Card */
.events-card {
    grid-row: 2 / 3;
    grid-column: 1 / 2;
    max-height: 350px;
}

.events-card .card-body {
    padding: 0;
    max-height: 290px;
    overflow-y: auto;
}

.events-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.events-table th {
    background: var(--bg-secondary);
    padding: 8px 12px;
    text-align: left;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.events-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
}

.events-table tr:hover {
    background: rgba(0, 180, 216, 0.05);
}

.no-data {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px !important;
}

/* Severity labels in table */
.severity-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
}

.severity-critical { background: rgba(255,23,68,0.2); color: var(--accent-red); }
.severity-high { background: rgba(255,145,0,0.2); color: var(--accent-orange); }
.severity-medium { background: rgba(255,214,0,0.2); color: var(--accent-yellow); }
.severity-low { background: rgba(0,180,216,0.2); color: var(--accent-blue); }

/* Training Card */
.training-card {
    margin: 0 24px 24px;
}

.training-form {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.form-group input,
.form-group select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.form-group input[type="file"] {
    padding: 4px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Reference Image Card */
.reference-card {
    margin: 0 24px 24px;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 16px;
    line-height: 1.5;
}

.form-group-wide {
    flex: 1;
    min-width: 300px;
}

.form-group textarea {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    width: 100%;
}

.reference-result {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.reference-result h3 {
    font-size: 0.95rem;
    color: var(--accent-blue);
    margin-bottom: 12px;
}

.ref-preview {
    margin-bottom: 12px;
}

.ref-preview img {
    max-width: 300px;
    max-height: 200px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.reference-result pre {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    color: var(--text-primary);
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 500px;
    overflow-y: auto;
    line-height: 1.5;
}

.btn-loading {
    opacity: 0.7;
    pointer-events: none;
}

/* ── Monitoring Definitions ── */
.definitions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 0 24px 24px;
}

.def-card {
    border: 1px solid var(--border-color);
}

.def-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.def-header.oil { border-bottom: 2px solid #4fc3f7; }
.def-header.operator { border-bottom: 2px solid var(--accent-green); }
.def-header.deviation { border-bottom: 2px solid var(--accent-orange); }
.def-header.alert { border-bottom: 2px solid var(--accent-red); }

.def-icon {
    font-size: 1.3rem;
}

.def-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.def-card h4 {
    font-size: 0.8rem;
    color: var(--accent-blue);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 12px 0 8px;
}

.def-list {
    list-style: none;
    padding: 0;
    margin: 0 0 8px;
}

.def-list li {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 4px 0 4px 16px;
    position: relative;
    line-height: 1.4;
}

.def-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 10px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-blue);
}

.def-list.tech li::before {
    background: var(--accent-green);
    border-radius: 0;
    width: 6px;
    height: 6px;
}

.def-list li strong {
    color: var(--text-primary);
}

/* Classification Grid */
.class-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.class-item {
    padding: 10px;
    border-radius: 6px;
    border-left: 3px solid;
    background: var(--bg-secondary);
    font-size: 0.8rem;
}

.class-item strong {
    display: block;
    margin-bottom: 4px;
    font-size: 0.82rem;
}

.class-item p {
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
}

.class-item.stable {
    border-color: var(--accent-green);
}

.class-item.stable strong {
    color: var(--accent-green);
}

.class-item.unstable {
    border-color: var(--accent-red);
}

.class-item.unstable strong {
    color: var(--accent-red);
}

/* Deviation Types */
.dev-types {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.dev-item {
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.78rem;
}

.dev-item strong {
    display: block;
    color: var(--accent-orange);
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.dev-item p {
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.3;
}

/* Severity Grid */
.severity-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.sev-badge {
    padding: 2px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    text-align: center;
}

.sev-low { background: rgba(0,180,216,0.2); color: var(--accent-blue); }
.sev-medium { background: rgba(255,214,0,0.2); color: var(--accent-yellow); }
.sev-high { background: rgba(255,145,0,0.2); color: var(--accent-orange); }
.sev-critical { background: rgba(255,23,68,0.2); color: var(--accent-red); }

/* Alert Lifecycle */
.lifecycle {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 14px;
}

.lc-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.lc-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
}

.lc-arrow {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .grid-container {
        grid-template-columns: 1fr;
    }
    .video-card, .status-card, .alerts-card, .events-card {
        grid-column: 1 / -1;
        grid-row: auto;
    }
    .definitions-grid {
        grid-template-columns: 1fr;
    }
    .class-grid, .dev-types {
        grid-template-columns: 1fr;
    }
}
