/* ============================================================
   AI Smart Port Detection — Industrial Monitoring Dashboard
   Dark control-room surface. Tokens per DESIGN_PROMPT.md.
   ============================================================ */

:root {
    --bg:      #0b0f1a;
    --surface: #0f1429;
    --card:    #141c30;
    --border:  #1e2a42;
    --text:    #cdd9f0;
    --dim:     #7a8aaa;
    --muted:   #3a4a68;
    --r: 6px;

    --blue:  #60a5fa;
    --green: #34d399;
    --red:   #f87171;
    --amber: #fbbf24;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Poppins', 'Segoe UI', system-ui, sans-serif;
    font-weight: 400;
    display: flex;
    flex-direction: column;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Header ---------- */
.app-header {
    height: 58px;
    flex: 0 0 58px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 16px;
    position: relative;
}

.header-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; text-decoration: none; color: inherit; cursor: pointer; }
.brand-text { display: flex; flex-direction: column; justify-content: center; }
.brand-name { font-size: 14px; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.brand-sub {
    font-size: 9px; font-weight: 600; letter-spacing: 0.8px;
    text-transform: uppercase; color: var(--dim); margin-top: 3px; white-space: nowrap;
}

/* Title block dead-centered in the header, independent of side content width */
.header-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}
.header-center .brand-name { font-size: 15px; }

.header-right { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.header-date { font-size: 11px; color: var(--dim); }
.company-logo {
    height: 30px; width: auto; display: block; flex: 0 0 auto;
}

.live-badge {
    display: flex; align-items: center; gap: 6px;
    font-size: 10px; font-weight: 700; letter-spacing: 1px;
    text-transform: uppercase; color: var(--red);
}
.live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
    animation: blink 1.4s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- Active Alerts (right side-panel section) ---------- */
.alerts-section.has-critical {
    background: rgba(248, 113, 113, 0.07);
    border-bottom-color: var(--red);
}
.alerts-list {
    display: flex; flex-direction: column; gap: 8px;
    max-height: 240px; overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.alert-empty { font-size: 11px; color: var(--muted); }
.alert-chip {
    display: flex; flex-direction: column; gap: 2px;
    padding: 8px 10px; border-radius: 6px;
    background: var(--card); border-left: 3px solid var(--border);
}
.alert-chip.sev-critical { border-left-color: var(--red); }
.alert-chip.sev-warning  { border-left-color: var(--amber); }
.alert-chip.sev-info     { border-left-color: var(--blue); }
.chip-name { font-size: 11px; font-weight: 600; color: var(--text); }
.alert-chip.sev-critical .chip-name { color: var(--red); }
.alert-chip.sev-warning .chip-name { color: var(--amber); }
.alert-chip.sev-info .chip-name { color: var(--blue); }
.chip-meta { font-size: 9px; color: var(--dim); font-variant-numeric: tabular-nums; }
.chip-appr { color: var(--amber); font-weight: 700; }
.chip-stop { color: var(--red); font-weight: 700; font-size: 9px; }

/* ---------- Buttons ---------- */
.btn {
    font-family: inherit;
    font-size: 10px; font-weight: 700; letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #fff; border: none; cursor: pointer;
    padding: 8px 14px; border-radius: var(--r);
    transition: filter 0.15s, transform 0.15s, box-shadow 0.15s;
}
.btn-primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.35);
}
.btn:hover { filter: brightness(1.15); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(37,99,235,0.5); }
.btn:active { transform: none; filter: none; }
.btn-ghost {
    background: transparent; border: 1px solid var(--border); color: var(--dim);
    box-shadow: none;
}
.btn-ghost:hover { box-shadow: none; color: var(--text); border-color: var(--blue); }
.btn-green { background: linear-gradient(135deg, #059669, #047857); box-shadow: 0 2px 10px rgba(5,150,105,0.35); }

/* ---------- Body layout ---------- */
.app-body { flex: 1; display: flex; min-height: 0; }

/* ---------- Footer ---------- */
.app-footer {
    flex: 0 0 auto; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface); border-top: 1px solid var(--border);
    font-size: 10px; letter-spacing: 0.4px; color: var(--muted);
}

.main-panel { flex: 1; padding: 16px; display: flex; flex-direction: column; min-width: 0; }
.controls { display: flex; gap: 8px; align-items: stretch; margin-bottom: 12px; flex-wrap: wrap; }
#upload-form { flex: 0 1 auto; display: flex; gap: 8px; align-items: center; }
.controls .btn { white-space: nowrap; display: inline-flex; align-items: center; }
/* Native file input is hidden; the <label> acts as the Browse button. */
.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* Selected-file name: fixed width, clips long names with an ellipsis. */
.file-name {
    flex: 0 0 auto; width: 180px; max-width: 180px;
    font-size: 11px; color: var(--dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-name.has-file { color: var(--text); }

/* Area that centers the (smaller) feed both horizontally and vertically. */
.feed-area {
    flex: 1; min-height: 0;
    display: flex; align-items: center; justify-content: center;
}
.feed-wrap {
    /* Fill the feed area so its edges align with the controls row above;
       the video is letterboxed inside via object-fit: contain. */
    width: 100%; height: 100%;
    border: 1px solid var(--border); border-radius: var(--r);
    background: #000; display: flex; align-items: center; justify-content: center;
    overflow: hidden; position: relative;
}
.feed-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; display: none; }
.feed-placeholder { color: var(--muted); font-size: 12px; letter-spacing: 0.5px; text-align: center; padding: 2rem; }

/* ---------- Side panel ---------- */
.side-panel {
    width: 312px; flex: 0 0 312px;
    border-left: 1px solid var(--border);
    background: var(--surface);
    display: flex; flex-direction: column; min-height: 0;
}
.side-scroll {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.side-scroll::-webkit-scrollbar { width: 8px; }
.side-scroll::-webkit-scrollbar-thumb {
    background: var(--border); border-radius: 4px;
}
.side-scroll::-webkit-scrollbar-thumb:hover { background: var(--dim); }
.panel-section { border-bottom: 1px solid var(--border); padding: 16px; }
.section-title {
    font-size: 9px; font-weight: 700; letter-spacing: 1.2px;
    text-transform: uppercase; color: var(--dim); margin: 0 0 12px;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

/* Stat row */
.stat-row { display: flex; border-bottom: 1px solid var(--border); }
.stat-cell {
    flex: 1; text-align: center; padding: 14px 6px;
    border-right: 1px solid var(--border); transition: background 0.15s;
}
.stat-cell:last-child { border-right: none; }
.stat-cell:hover { background: var(--card); }
.stat-num { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; line-height: 1; }
.stat-num.blue { color: var(--blue); }
.stat-num.red { color: var(--red); }
.stat-num.green { color: var(--green); }
.stat-num.amber { color: var(--amber); }
.stat-label {
    font-size: 9px; font-weight: 600; letter-spacing: 1px;
    text-transform: uppercase; color: var(--dim); margin-top: 6px;
}

/* Radial gauge */
.gauge-section { display: flex; flex-direction: column; align-items: center; }
.gauge {
    width: 108px; height: 108px; border-radius: 50%;
    position: relative; display: flex; align-items: center; justify-content: center;
    background:
        conic-gradient(from 0deg, var(--red) 0deg, var(--amber) 120deg, var(--green) 240deg, var(--green) 360deg);
    animation: ring-glow 3.5s ease-in-out infinite;
}
.gauge::before {
    content: ""; position: absolute; inset: 0; border-radius: 50%;
    /* Reveal the ring for 0deg→--clip (the filled %); cover the remainder. */
    background: conic-gradient(transparent 0deg, transparent var(--clip, 0deg), var(--surface) var(--clip, 0deg), var(--surface) 360deg);
}
.gauge-hole {
    width: 80px; height: 80px; border-radius: 50%;
    background: var(--bg); position: relative; z-index: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gauge-pct { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; line-height: 1; }
.gauge-cap { font-size: 8px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--dim); margin-top: 3px; }
@keyframes ring-glow {
    0%, 100% { filter: drop-shadow(0 0 3px rgba(52,211,153,0.2)); }
    50% { filter: drop-shadow(0 0 10px rgba(52,211,153,0.45)); }
}

/* Item summary list */
.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
    display: flex; align-items: center; gap: 8px; font-size: 12px;
}
.item-icon {
    width: 22px; height: 22px; flex: 0 0 22px; border-radius: 5px;
    background: rgba(96, 165, 250, 0.10); color: var(--blue);
    display: flex; align-items: center; justify-content: center;
}
.item-name { flex: 1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
    font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px;
    font-variant-numeric: tabular-nums;
}
.badge.green { background: rgba(52,211,153,0.08); border: 1px solid rgba(52,211,153,0.20); color: var(--green); }
.badge.red   { background: rgba(248,113,113,0.08); border: 1px solid rgba(248,113,113,0.20); color: var(--red); }

/* Machine context grid */
.context-grid { display: flex; gap: 6px; }
.ctx-cell {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--r); padding: 8px 4px;
}
.ctx-val { font-size: 18px; font-weight: 700; color: var(--blue); letter-spacing: -0.5px; }
.ctx-lbl { font-size: 8px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--dim); margin-top: 4px; text-align: center; }

/* Alerts list */
.alert-item {
    font-size: 12px; padding: 8px 0; border-bottom: 1px solid var(--border);
    border-left: 3px solid var(--red); padding-left: 8px;
}
.alert-item:last-child { border-bottom: none; }
.alert-item.sev-critical { border-left-color: var(--red); }
.alert-item.sev-warning  { border-left-color: var(--amber); }
.alert-item.sev-info     { border-left-color: var(--blue); }
.alert-head { display: flex; align-items: center; justify-content: space-between; }
.alert-name { color: var(--red); font-weight: 600; }
.alert-item.sev-warning .alert-name { color: var(--amber); }
.alert-item.sev-info .alert-name { color: var(--blue); }
.sev-badge {
    font-size: 8px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
    padding: 2px 6px; border-radius: 8px;
}
.sev-badge.critical { background: rgba(248,113,113,0.12); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
.sev-badge.warning  { background: rgba(251,191,36,0.12); color: var(--amber); border: 1px solid rgba(251,191,36,0.3); }
.sev-badge.info     { background: rgba(96,165,250,0.12); color: var(--blue); border: 1px solid rgba(96,165,250,0.3); }
.alert-meta {
    display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 5px;
    font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums;
}
.alert-sub { margin-top: 2px; justify-content: space-between; opacity: 0.8; }
.track-id { font-size: 9px; font-weight: 600; color: var(--muted); }
/* "Approaching screw" prediction chip. */
.approach-chip {
    font-size: 9px; font-weight: 700; letter-spacing: 0.4px;
    color: var(--amber); background: rgba(251,191,36,0.12);
    border: 1px solid rgba(251,191,36,0.30); border-radius: 8px;
    padding: 1px 6px;
}
/* Prominent call-to-action for stop-range (Critical) hazards. */
.alert-flag {
    margin-top: 5px; font-size: 9px; font-weight: 700; letter-spacing: 0.5px;
    text-transform: uppercase; color: var(--red);
    background: rgba(248,113,113,0.10); border: 1px solid rgba(248,113,113,0.30);
    border-radius: 4px; padding: 3px 6px; display: inline-block;
}
/* Live alert count in the section title. */
.count-badge {
    font-size: 9px; font-weight: 700; vertical-align: middle;
    min-width: 16px; text-align: center; padding: 1px 6px; border-radius: 9px;
    background: var(--surface); color: var(--dim); border: 1px solid var(--border);
}
.count-badge.critical {
    background: rgba(248,113,113,0.15); color: var(--red);
    border-color: rgba(248,113,113,0.4);
    animation: alert-pulse 1.2s ease-in-out infinite;
}
@keyframes alert-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
.empty { color: var(--muted); font-size: 11px; }

/* Detection history */
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.history-item {
    display: flex; align-items: center; gap: 8px; font-size: 11px;
    padding: 6px 0; border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; }
.history-dot.red { background: var(--red); }
.history-dot.green { background: var(--green); }
.history-label { flex: 1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-conf { color: var(--dim); font-variant-numeric: tabular-nums; }
.history-time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Panel footer */
.panel-footer {
    flex: 0 0 auto; border-top: 1px solid var(--border);
    background: var(--surface); padding: 10px 16px; text-align: right;
    font-size: 10px; color: var(--muted);
}

/* ---------- Responsive: stack on tablets / phones ---------- */
@media (max-width: 900px) {
    html, body { overflow: auto; height: auto; }
    body { min-height: 100vh; }
    .app-body { flex-direction: column; }
    .main-panel { min-height: 60vh; }
    .feed-wrap { width: 100%; height: 100%; max-width: 100%; max-height: 100%; }
    .side-panel {
        width: 100%; flex: 1 1 auto;
        border-left: none; border-top: 1px solid var(--border);
    }
}

@media (max-width: 560px) {
    .app-header { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
    .header-date { display: none; }
    .controls { gap: 6px; }
    #upload-form { flex: 1 1 100%; min-width: 0; flex-wrap: wrap; }
    .file-name { flex: 1 1 100%; width: auto; max-width: 100%; }
    .controls .btn { flex: 1 1 auto; }
}

/* ===================== Landing page ===================== */
.landing-body { overflow: auto; }
.landing {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 0 24px 48px; gap: 44px;
}

/* ---- Hero ---- */
.hero {
    width: 100%; max-width: 900px; text-align: center;
    padding: 56px 24px 8px; position: relative;
}
/* soft radial glow behind the hero */
.hero::before {
    content: ""; position: absolute; inset: 0; z-index: -1;
    background: radial-gradient(60% 120% at 50% 0%, rgba(37,99,235,0.18), transparent 70%);
    pointer-events: none;
}
.hero-badge {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
    color: var(--blue); background: rgba(96,165,250,0.10);
    border: 1px solid rgba(96,165,250,0.30); border-radius: 999px; padding: 5px 12px;
}
.hero-dot {
    width: 7px; height: 7px; border-radius: 50%; background: var(--blue);
    box-shadow: 0 0 8px var(--blue); animation: blink 1.6s infinite;
}
.hero-title {
    font-size: 38px; font-weight: 700; line-height: 1.12; letter-spacing: -1px;
    margin: 20px 0 16px;
    background: linear-gradient(180deg, #eaf1ff, #9db6e6);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-desc {
    font-size: 15px; line-height: 1.7; color: var(--dim);
    max-width: 680px; margin: 0 auto;
}
.hero-desc strong { color: var(--text); font-weight: 600; }

/* ---- Spec chips ---- */
.spec-row {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: 30px;
}
.spec {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    min-width: 120px; padding: 16px 20px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    transition: transform 0.18s, border-color 0.18s;
}
.spec:hover { transform: translateY(-3px); border-color: var(--blue); }
.spec-val {
    font-size: 24px; font-weight: 700; letter-spacing: -0.5px; color: var(--blue);
    font-variant-numeric: tabular-nums;
}
.spec-lbl {
    font-size: 9px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; color: var(--dim);
}

/* ---- Picker ---- */
.picker { width: 100%; max-width: 1080px; text-align: center; }
.picker-title { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; margin: 0 0 6px; }
.picker-sub { font-size: 13px; line-height: 1.6; color: var(--dim); margin: 0 0 26px; }
.picker-sub a { color: var(--blue); text-decoration: none; }
.picker-sub a:hover { text-decoration: underline; }

.video-grid {
    width: 100%; max-width: 1080px;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px;
}
.video-card {
    text-decoration: none; color: inherit;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    overflow: hidden; display: flex; flex-direction: column;
    transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}
.video-card:hover {
    transform: translateY(-4px); border-color: var(--blue);
    box-shadow: 0 12px 32px rgba(0,0,0,0.35);
}
.video-thumb {
    position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden;
}
.video-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-index {
    position: absolute; top: 8px; left: 8px;
    font-size: 9px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
    color: #fff; background: rgba(0,0,0,0.55); padding: 3px 8px; border-radius: 6px;
}
.video-play {
    position: absolute; inset: 0; margin: auto; width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: #fff;
    background: rgba(37,99,235,0.85); border-radius: 50%;
    box-shadow: 0 4px 16px rgba(37,99,235,0.5);
    transition: transform 0.18s, opacity 0.18s; opacity: 0.92;
}
.video-card:hover .video-play { transform: scale(1.12); opacity: 0; }
.video-meta {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 14px;
}
.video-name {
    font-size: 13px; font-weight: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.video-cta { font-size: 11px; font-weight: 700; color: var(--blue); white-space: nowrap; }
.landing-empty { text-align: center; color: var(--dim); font-size: 13px; display: grid; gap: 16px; justify-items: center; }
.landing-empty code { color: var(--text); }
.landing-actions { margin-top: 4px; }

@media (max-width: 560px) {
    .hero { padding-top: 36px; }
    .hero-title { font-size: 27px; }
    .hero-desc { font-size: 13px; }
    .spec { min-width: 84px; padding: 12px 14px; flex: 1 1 40%; }
    .spec-val { font-size: 20px; }
}
