:root {
    --ink: #1f2a33;
    --muted: #5f6b75;
    --line: #d8dee3;
    --paper: #ffffff;
    --page: #f4f6f8;
    --accent: #1f5fa8;
    --accent-dark: #174a84;
    --danger: #b3261e;
    --good: #1e7a46;
    --good-bg: #e8f5ee;
    --bad-bg: #fcebea;
    --ooc: #d9822b;
    --soda: #5b2a12;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: Arial, sans-serif;
    color: var(--ink);
    background: var(--page);
    line-height: 1.45;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 16px;
}

h1 { font-size: 24px; margin: 0; }
h2 { font-size: 19px; margin: 0 0 10px; }

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 20px;
    margin-bottom: 12px;
}

.team-badge {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    font-size: 15px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 14px;
}

.card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px 20px;
    margin-bottom: 16px;
}
.card.narrow { max-width: 620px; }

.facts { margin: 8px 0; padding-left: 22px; }
.facts li { margin: 3px 0; }
.hint { color: var(--muted); font-size: 14px; }
.steps li { margin: 6px 0; }
.steps.small { padding-left: 20px; margin: 0 0 14px; font-size: 15px; }
.lot-check {
    background: #f6f8fa;
    border: 1px dashed #b9c2ca;
    border-radius: 6px;
    padding: 8px 12px;
    margin: 0 0 14px;
    font-size: 15px;
}
.msg { min-height: 1.2em; margin: 8px 0 0; font-size: 15px; }
.msg.bad { color: var(--danger); }

button {
    font: inherit;
    font-size: 15px;
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid #b9c2ca;
    background: #f7f9fa;
    color: var(--ink);
    cursor: pointer;
}
button:hover { background: #edf1f4; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover:not(:disabled) { background: #8f1e18; }
.link-button {
    border: none;
    background: none;
    color: var(--accent);
    padding: 0;
    text-decoration: underline;
}
.link-button:hover { background: none; }

input[type="text"] {
    font: inherit;
    font-size: 16px;
    padding: 7px 10px;
    border: 1px solid #b9c2ca;
    border-radius: 6px;
}
.team-form { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 4px; }
.team-form input { width: min(320px, 100%); }
.next-row { margin: 0 0 24px; }
button.wide { width: 100%; }

/* ----- Timeline ----- */

.timeline-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 14px 6px;
    margin-bottom: 12px;
}
.timeline-label { font-size: 13px; color: var(--muted); padding-top: 3px; }
.timeline {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    list-style: none;
    margin: 0;
    padding: 0;
}
.timeline li { position: relative; }
.timeline li::before {
    content: "";
    position: absolute;
    top: 10px;
    left: -50%;
    width: 100%;
    height: 3px;
    background: var(--line);
    z-index: 0;
}
.timeline li:first-child::before { display: none; }
.timeline li.done::before,
.timeline li.today::before { background: #7d8992; }
.timeline button {
    position: relative;
    z-index: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 0;
    border: none;
    background: none;
    font-size: 12px;
    color: var(--muted);
}
.timeline button:disabled { opacity: 1; cursor: default; }
.timeline .dot {
    width: 15px;
    height: 15px;
    margin-top: 4px;
    border-radius: 50%;
    border: 2px solid #b9c2ca;
    background: var(--paper);
}
.timeline li.done .dot { background: #7d8992; border-color: #7d8992; }
.timeline li.stopped .dot { border-radius: 3px; background: var(--ink); border-color: var(--ink); }
.timeline li.today .dot {
    width: 23px;
    height: 23px;
    margin-top: 0;
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px #cfe0f3;
}
.timeline li.today .num { color: var(--accent); font-weight: bold; }
.timeline li.alarm .dot { background: var(--danger); border-color: var(--danger); }
.timeline li.ooc .dot { background: var(--ooc); border-color: var(--ooc); }
.timeline li.fixed .dot { background: var(--good); border-color: var(--good); }
.timeline li.viewing:not(.today) .dot { box-shadow: 0 0 0 3px #f3d7a1; }
.timeline li.viewing .num { color: var(--ink); font-weight: bold; }
.timeline li:not(.future) button:hover .dot { transform: scale(1.15); }

/* ----- The plant floor ----- */

.plant-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 14px;
    align-items: start;
}

.main-area { position: relative; height: 610px; }

.chart-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
}
.chart-title { font-weight: bold; font-size: 16px; }
#chart { flex: 1 1 auto; min-height: 0; width: 100%; }

.inspect {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 350px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border: 2px solid var(--accent);
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 12px 32px rgba(31, 42, 51, 0.3);
    z-index: 5;
}
.inspect-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.inspect.moving .inspect-head { cursor: grabbing; }
.head-grip {
    flex: none;
    width: 10px;
    height: 20px;
    background-image: radial-gradient(circle, var(--muted) 1.3px, transparent 1.6px);
    background-size: 5px 5px;
}
.inspect-head #inspect-title { font-weight: bold; font-size: 16px; min-width: 128px; text-align: center; white-space: nowrap; }
.inspect-head button { padding: 4px 10px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.inspect-head .close { margin-left: auto; }
#station {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    touch-action: none;
    user-select: none;
    cursor: ns-resize;
}
.station-note { color: var(--muted); font-size: 13px; text-align: center; margin-top: 4px; }

.side { display: flex; flex-direction: column; gap: 14px; }

.conveyor-wrap,
.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
}
.conveyor-title { font-weight: bold; font-size: 15px; margin-bottom: 4px; }
.conveyor { display: flex; justify-content: space-between; gap: 2px; }
.belt {
    height: 10px;
    margin: -4px 0 6px;
    border-radius: 5px;
    background: repeating-linear-gradient(90deg, #8d969e 0 18px, #737c85 18px 22px);
}
.bottle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 4px 6px 3px;
    background: none;
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.2;
}
.bottle:hover { background: #f1f4f6; }
.bottle.selected { border-color: var(--accent); background: #eef4fb; }
.bottle svg { width: 36px; height: 90px; }
.bottle .tick { color: var(--good); font-weight: bold; }

.panel p { margin: 0 0 12px; font-size: 15px; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.buttons.stacked { flex-direction: column; }
.buttons.stacked button { width: 100%; }
.mean-form { display: flex; gap: 8px; margin: 6px 0 0; }
.mean-form input { width: 130px; }
.panel .msg { margin: 4px 0 0; font-size: 14px; min-height: 0; }
.plotted { margin-top: 4px; }

/* the setup guide */
.step-count {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 2px;
}
.facts-box {
    background: #f6f8fa;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 14px;
    text-align: center;
    margin: 0 0 12px;
}
.tune { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.tune button { padding: 3px 10px; font-size: 13px; }
.panel .tip { margin: 6px 0 12px; font-size: 13px; }
.msg-box { border-radius: 6px; padding: 8px 10px; font-size: 14px; margin: 0 0 12px; }
.msg-box.good { background: var(--good-bg); color: #14532d; }
.msg-box.bad { background: var(--bad-bg); color: #7f1d1d; }
.reading { padding-left: 18px; font-size: 15px; margin: 0 0 14px; }
.reading li { margin: 6px 0; }

.story { border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.story.bad { background: var(--bad-bg); }
.story.note { background: #eef2f6; }
.batch { font-weight: normal; font-size: 13px; color: var(--muted); margin-left: 4px; }
.story p:last-child { margin-bottom: 0; }

/* ----- Drawings ----- */

.glass { fill: #dde9ee; stroke: #8fa6b2; stroke-width: 1.5; }
.soda { fill: var(--soda); }
.label { fill: #d63c2f; }
.label-text { fill: #fff; font-size: 9px; font-weight: bold; letter-spacing: 1px; }
.cap { fill: #c9a227; }

.station-bg { fill: #e9eef1; }
.card-bg { fill: #fffdf6; stroke: #b9b39a; }
.card-head { font-size: 13px; font-weight: bold; fill: #4b4a3f; }
.tick-major { stroke: #2b2b2b; stroke-width: 1.4; }
.tick-minor { stroke: #2b2b2b; stroke-width: 1; }
.tick-label { font-size: 13px; fill: #2b2b2b; }
.glass-wall { fill: #b7cbd4; opacity: 0.85; }
.glass-inside { fill: #f4f9fb; opacity: 0.7; }
.surface { fill: none; stroke: #b06a3c; stroke-width: 1.6; }
.bubble { fill: none; stroke: #e7c3a6; stroke-width: 0.8; opacity: 0.7; }
.reflection { fill: #ffffff; opacity: 0.35; }
.hairline .hit { stroke: transparent; stroke-width: 18; }
.hairline .rule { stroke: #d62728; stroke-width: 1.2; }
.hairline .grip { fill: #d62728; }
.hairline .grip-label { font-size: 12px; fill: #d62728; }

.grid { stroke: #eceff2; }
.axis { font-size: 13px; fill: var(--muted); }
.axis.today { fill: var(--accent); font-weight: bold; }
.axis-title { font-size: 14px; fill: var(--ink); }
.limit { stroke: var(--danger); stroke-dasharray: 7 5; stroke-width: 1.6; }
.limit-label { font-size: 13px; fill: var(--danger); }
.center { stroke: #8a959e; stroke-width: 1.3; }
.center-label { font-size: 13px; fill: var(--muted); }
.mine-line { stroke: var(--ink); stroke-width: 1.6; }
.mine-pt { fill: var(--ink); }
.mine-pt.latest { fill: var(--accent); stroke: #cfe0f3; stroke-width: 4; paint-order: stroke; }
.mine-pt.out { fill: var(--danger); }
.truth-line { stroke: var(--ooc); stroke-width: 1.2; stroke-dasharray: 3 3; }
.truth-pt { fill: var(--paper); stroke: var(--ooc); stroke-width: 2; }
/* lines the group drags into place during setup */
.dline:focus { outline: none; }
.dline .hit { stroke: transparent; stroke-width: 18; }
.dline.draggable { cursor: ns-resize; }
.dline.dl-center .vis { stroke: #8a959e; stroke-width: 1.3; }
.dline.dl-limit .vis { stroke: var(--danger); stroke-dasharray: 7 5; stroke-width: 1.6; }
.dline.dl-se .vis { stroke: #3d7cc9; stroke-width: 1.2; }
.dline.draggable .vis { stroke-width: 2.4; }
.dline.dl-center.draggable .vis { stroke: #5f6b75; }
.dline.selected .vis { stroke-width: 3.2; }
.dline .pill { fill: #fff; stroke-width: 1.5; }
.dline.dl-center .pill { stroke: #5f6b75; }
.dline.dl-limit .pill { stroke: var(--danger); }
.dline.dl-se .pill { stroke: #3d7cc9; }
.dline.selected .pill { fill: #fff7e0; stroke-width: 2.5; }
.pill-text { font-size: 13px; font-weight: bold; }
.dline.dl-center .pill-text { fill: #3f4a53; }
.dline.dl-limit .pill-text { fill: var(--danger); }
.dline.dl-se .pill-text { fill: #2c64a8; }
.se-band { fill: #3d7cc9; opacity: 0.1; }
.se-band.open { opacity: 0.18; }
.band-label { font-size: 12px; fill: #2c64a8; }
.drag-hint { font-size: 13px; font-weight: bold; fill: #5f6b75; }

.ooc { fill: #fbe9d7; }
.ooc-label { font-size: 13px; fill: #a5571a; }
.mark { font-size: 12px; font-weight: bold; }
.mark.fa { fill: var(--danger); }
.mark.stop { fill: var(--good); }
.mark.stopped { fill: var(--muted); }

/* ----- The report ----- */

.cost-table { border-collapse: collapse; width: 100%; max-width: 640px; }
.cost-table td { border-bottom: 1px solid var(--line); padding: 7px 0; vertical-align: top; }
.cost-table td:last-child { text-align: right; white-space: nowrap; padding-left: 16px; }
.cost-table td.plus { color: var(--good); }
.cost-table td.minus { color: var(--danger); }
.cost-table .detail { display: block; color: var(--muted); font-size: 13px; }
.cost-table tr.group th {
    text-align: left;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 14px 0 2px;
    border-bottom: 1px solid var(--line);
}
.cost-table tr:first-child th { padding-top: 0; }
.cost-table tr.total td { font-weight: bold; color: var(--ink); border-bottom: none; border-top: 2px solid var(--ink); }

#report-chart { width: 100%; max-width: 860px; height: auto; display: block; margin: 6px auto 0; }
.legend { font-size: 14px; color: var(--muted); text-align: center; }
.legend .key {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    margin: 0 4px 0 14px;
    vertical-align: -1px;
}
.legend .key.mine { background: var(--ink); }
.legend .key.truth { border: 2px solid var(--ooc); background: var(--paper); }
.legend .key.ooc { border-radius: 2px; background: #fbe9d7; border: 1px solid #f0c9a0; }

.report-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 30px; }

@media (max-width: 860px) {
    .plant-grid { grid-template-columns: 1fr; }
    .main-area { height: auto; }
    #chart { flex: none; height: auto; }
    .side { order: -1; }
    .inspect {
        position: fixed;
        inset: 8px;
        width: auto;
        z-index: 20;
    }
    .inspect-head { cursor: auto; }
    .head-grip { display: none; }
    .timeline-label { display: none; }
    .timeline button { font-size: 10px; }
    .timeline .dot { width: 11px; height: 11px; margin-top: 6px; }
    .timeline li.today .dot { width: 17px; height: 17px; margin-top: 3px; }
}
