/* ==========================================================
   PCB Milling Tools — app shell
   Layered on top of diyaudiolab-styles.css. Link that FIRST.

   This file holds the chrome these three tools share and that
   the design system doesn't cover: the three-column working
   layout, the canvas frame, the drop zones, the G-code and
   console code areas, and a denser control scale for a
   machine-control UI that has to fit on one screen.

   It introduces NO new colours. Every value below is a
   design-system token (var(--...)); the only literal hexes are
   in the canvas colour tables inside each page's <script>,
   which is the sanctioned place to mirror a token.
   ========================================================== */

/* ==========================================================
   Page frame
   ========================================================== */

body.app {
    max-width: 1440px;
    margin: 16px auto;
    padding: 12px;
}

.container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 28px 24px;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}
.app-header h1 { margin: 0; }
/* Inside a tool the title is a label on a working screen, not a page
   heading, so it steps down with the rest of the dense scale. */
body.app .app-header h1 { font-size: 24px; }
.app-header .toolbar-gap { flex: 1; }


/* ==========================================================
   Working layout — sidebar / preview / output
   ========================================================== */

.app-layout {
    display: grid;
    grid-template-columns: 300px 700px 1fr;
    grid-template-rows: 780px;
    gap: 20px;
}

.sidebar { min-width: 0; overflow-y: auto; }

.preview-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.output-panel {
    min-width: 0;
    min-height: 0;
    max-height: 780px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (max-width: 1400px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }
    .output-panel { max-height: none; }
}

/* ==========================================================
   Dense scale
   A CNC control panel has to fit a lot of labelled numbers on
   one screen, so the working area steps the system's type and
   spacing down one notch. Colour, weight and shape are
   untouched; only size and rhythm change.
   ========================================================== */

.app-layout .section-header {
    font-size: 14px;
    margin: 16px 0 10px;
    padding-bottom: 6px;
}
.app-layout .section-header:first-child { margin-top: 0; }

.app-layout label {
    font-size: 13px;
    margin-bottom: 4px;
}
.app-layout .label-detail { font-size: 12px; }

.app-layout input,
.app-layout select,
.app-layout textarea {
    font-size: 14px;
    padding: 7px 9px;
}

.app-layout .input-group { margin-bottom: 12px; }
.app-layout .input-row { gap: 10px; }

/* ==========================================================
   Buttons — size modifiers only; the variants come from the
   design system (.btn-primary / .btn-secondary / .btn-tertiary)
   ========================================================== */

.btn-sm {
    font-size: 13px;
    padding: 6px 12px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* Machine-critical actions. Not decoration: a feed hold and a
   soft reset are status controls on a machine that is moving,
   so they take the system's warning and error tokens rather
   than the interactive blue. Every one is also labelled — the
   colour is never the only thing saying what the button does. */
.btn-warning {
    background: var(--warning);
    border-color: var(--warning);
    color: #fff;
}
.btn-warning:hover { background: var(--dal-amber-600); filter: brightness(0.92); }

.btn-danger {
    background: var(--error);
    border-color: var(--error);
    color: #fff;
}
.btn-danger:hover { filter: brightness(0.92); }

.btn-warning:disabled,
.btn-danger:disabled {
    background: var(--disabled-bg);
    border-color: transparent;
    color: var(--disabled-text);
    filter: none;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
/* flex-basis auto, not 0: the buttons size to their labels and wrap to a new
   line when the column is narrow, rather than overflowing it. */
.btn-row .btn { flex: 1 1 auto; min-width: 0; justify-content: center; white-space: nowrap; }

/* ==========================================================
   Toolbars under the canvas
   ========================================================== */

.view-controls {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

/* A layer toggle is an immediate on/off with no Apply step, but
   it is one of many in a row, so it stays a labelled checkbox
   rather than a switch. */
.view-controls .toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    margin: 0;
    cursor: pointer;
    padding: 5px 10px;
    background: var(--panel);
    border-radius: var(--radius-control);
}
.view-controls .toggle input { width: auto; margin: 0; }
.view-controls .toggle:hover { color: var(--text); }

/* ==========================================================
   Canvas frame
   The drawing surface is the app's one dark ground besides the
   code areas; it uses the same neutral charcoal so the page has
   exactly two grounds, not three.
   ========================================================== */

.canvas-wrap {
    position: relative;
    background: var(--code-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    overflow: hidden;
    height: 600px;
}

.canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Readouts sitting on the dark ground follow the code-area
   roles: data reads brightest, chrome reads muted. */
.canvas-coords,
.canvas-overlay {
    position: absolute;
    font-family: var(--font-mono);
    font-size: 11px;
    pointer-events: none;
    background: var(--code-raised);
    border-radius: 4px;
    padding: 3px 8px;
}
.canvas-coords {
    top: 8px;
    right: 8px;
    color: var(--code-text);
}
.canvas-coords:empty,
.canvas-overlay:empty { display: none; }
.canvas-overlay {
    bottom: 8px;
    left: 8px;
    color: var(--code-comment);
}

.drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(18, 89, 176, 0.85);   /* --accent at 85% */
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: none;
}
.drop-overlay.show { display: flex; }
.drop-overlay-inner {
    border: 2px dashed #fff;
    border-radius: var(--radius);
    padding: 48px;
    text-align: center;
    color: #fff;
    font-size: 20px;
    font-weight: 600;
}

/* ==========================================================
   Drop zones
   ========================================================== */

.drop-zone {
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-control);
    padding: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
    text-align: center;
}
.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent);
    background: var(--highlight);
    color: var(--accent);
}
.drop-zone:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.drop-zone .icon {
    width: 20px;
    height: 20px;
    margin-bottom: 6px;
}
.drop-zone .label { font-size: 13px; font-weight: 600; color: var(--text); }
.drop-zone .hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.drop-zone .filename {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    margin-top: 6px;
    word-break: break-all;
}
.drop-zone.dragover .label,
.drop-zone:hover .label { color: inherit; }

/* Three zones side by side, laid out as a row */
.file-pair {
    display: grid;
    /* auto-fit, not a fixed 3: the drop-zone labels are nowrap, so a track
       narrower than their content would overflow. 240px clears the widest. */
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.file-pair .drop-zone {
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    padding: 10px 14px;
}
.file-pair .drop-zone .icon { margin-bottom: 0; }
.file-pair .drop-zone .hint { margin-top: 0; }
.file-pair .drop-zone .filename { margin-top: 0; }
.file-pair .drop-zone .label,
.file-pair .drop-zone .hint,
.file-pair .drop-zone .filename { white-space: nowrap; }
.file-pair .drop-zone .filename {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* ==========================================================
   Stats & readouts
   ========================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.stat-item {
    background: var(--panel);
    border-radius: var(--radius-control);
    padding: 7px 9px;
}
.stat-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.stat-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-top: 2px;
}

/* Machine position: live data from the controller, so it sits on
   the dark ground and takes the code area's brightest role. */
.pos-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.pos-item {
    background: var(--code-surface);
    border-radius: var(--radius-control);
    padding: 8px;
    text-align: center;
}
.pos-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--code-comment);
    text-transform: uppercase;
}
.pos-value {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    color: var(--code-text);
    margin-top: 2px;
}

.layer-legend {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 8px;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ==========================================================
   Code areas — G-code listing and serial console
   The dark ground and every colour on it come from the
   system's code-surface and syntax roles.
   ========================================================== */

.code-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.code-panel .section-header { flex-shrink: 0; }

.code-wrap {
    border-radius: var(--radius-control);
    overflow: hidden;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--code-surface);
}

.gcode-list,
.console-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.6;
    padding: 8px;
    background: var(--code-surface);
    color: var(--code-text);
}

.gcode-line {
    padding: 1px 6px;
    border-radius: 3px;
    white-space: nowrap;
    color: var(--code-text);
}
.gcode-line.clickable { cursor: pointer; }
.gcode-line.clickable:hover { background: var(--code-raised); }
.gcode-line.highlight { background: var(--code-selection); }
.gcode-line.sent { opacity: 0.45; }

.gcode-line .ln {
    color: var(--code-comment);
    display: inline-block;
    width: 38px;
    text-align: right;
    margin-right: 8px;
    user-select: none;
}

/* Five coloured roles, the system cap. Everything else is
   code text, so the coordinates read brightest. */
.gcode-line .cmd     { color: var(--code-keyword); }
.gcode-line .comment { color: var(--code-comment); font-style: italic; }
.gcode-line .rapid   { color: var(--code-enum); }
.gcode-line .cut     { color: var(--code-string); }
.gcode-line .arc     { color: var(--code-unit); }

.console-log .tx   { color: var(--code-keyword); }
.console-log .rx   { color: var(--code-string); }
.console-log .err  { color: var(--code-enum); }
.console-log .info { color: var(--code-unit); }

.console-panel {
    flex: 0 0 220px;
    display: flex;
    flex-direction: column;
}

.console-input-row {
    display: flex;
    border-top: 1px solid var(--code-raised);
}
.console-input-row input {
    flex: 1;
    border: none;
    border-radius: 0;
    padding: 7px 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--code-raised);
    color: var(--code-text);
}
.console-input-row input::placeholder { color: var(--code-comment); }
.console-input-row input:focus {
    outline: 2px solid var(--code-caret);
    outline-offset: -2px;
    border-color: transparent;
}
.console-input-row .btn {
    border-radius: 0;
    font-size: 12px;
    padding: 7px 14px;
}
/* The console's send action sits on the dark ground, so it uses the
   code area's blue rather than the page's filled primary — Start Job
   stays the single primary button on this view. */
.console-send {
    background: var(--code-raised);
    border-color: var(--code-raised);
    color: var(--code-keyword);
}
.console-send:hover { background: var(--code-comment); color: #fff; }
.console-send:focus-visible { outline-color: var(--code-caret); }

/* Scrollbars inside a code area follow its ground */
.gcode-list::-webkit-scrollbar,
.console-log::-webkit-scrollbar { width: 8px; }
.gcode-list::-webkit-scrollbar-track,
.console-log::-webkit-scrollbar-track { background: var(--code-surface); }
.gcode-list::-webkit-scrollbar-thumb,
.console-log::-webkit-scrollbar-thumb {
    background: var(--code-raised);
    border-radius: 4px;
}
.gcode-list::-webkit-scrollbar-thumb:hover,
.console-log::-webkit-scrollbar-thumb:hover { background: var(--code-comment); }

/* ==========================================================
   Job progress & playback
   ========================================================== */

.playback-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.playback-row input[type="range"] { flex: 1; min-width: 120px; }
.playback-row select {
    width: auto;
    font-size: 12px;
    padding: 6px 8px;
}
/* Playing is an active state, so it takes the interactive accent */
.play-btn.playing {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Position in the run: a key metric, so it carries the accent */
.line-count {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 600;
    color: var(--accent);
    text-align: center;
    margin-top: 8px;
}

.job-controls {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.job-progress { margin-top: 12px; }
.job-status {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 8px;
}

.connect-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.connect-row select { flex: 1; }
.connect-row .btn { white-space: nowrap; }

.machine-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}
.machine-btns .btn {
    width: 100%;
    justify-content: center;
    padding: 7px 6px;
    font-size: 12px;
}
.machine-btns .full-width { grid-column: 1 / -1; }
