/* ==========================================================================
   Operator software (msw-* component family)
   The fleet page (machine_software) and the machine page's Operator software
   card (hmi/admin/overview.php). Tokens from design_language.md. Dark mode
   rules are at the end of this file (cache-busted by load_css, unlike
   color/000001.css).
   ========================================================================== */

.msw-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0 0 20px 0;
}
/* what the script hides stays hidden whatever the element's own display is */
.msw-fleet [hidden],
#msw-modal [hidden] { display: none !important; }
.msw-page-header__title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.4px;
    color: #1f2937;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.msw-page-header__title i { color: #8b1a4a; }
.msw-page-header__subtitle { color: #6b7280; font-size: 13px; font-weight: 500; margin-top: 4px; max-width: 780px; }
/* The operator apps (WM800 Operator, WM600 Operator): each has its own page, ?app= */
.msw-apps { display: flex; gap: 8px; flex-wrap: wrap; }
.msw-app {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid #e5e7eb;
    background: #fff;
    font-size: 13px;
    font-weight: 700;
    color: #4b5563;
    text-decoration: none;
}
.msw-app:hover,
.msw-app:focus { color: #8b1a4a; border-color: #8b1a4a; text-decoration: none; }
.msw-app.is-active,
.msw-app.is-active:hover,
.msw-app.is-active:focus { background: #8b1a4a; border-color: #8b1a4a; color: #fff; }

/* Buttons */
.msw-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    line-height: 18px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    text-decoration: none !important;
    transition: all .15s ease;
    white-space: nowrap;
}
.msw-btn:disabled { opacity: .5; cursor: not-allowed; }
.msw-btn--primary { background: #8b1a4a; color: #fff; }
.msw-btn--primary:hover:not(:disabled) { background: #a8325f; color: #fff; }
.msw-btn--outline { background: #fff; color: #374151; border-color: #d1d5db; }
.msw-btn--outline:hover:not(:disabled) { background: #f9fafb; color: #1f2937; }
.msw-btn--danger { background: #fee2e2; color: #991b1b; }
.msw-btn--danger:hover:not(:disabled) { background: #fecaca; }
.msw-btn--sm { padding: 5px 11px; font-size: 12px; }
.msw-link {
    padding: 0;
    border: 0;
    background: none;
    font-size: 12px;
    font-weight: 600;
    color: #8b1a4a;
    cursor: pointer;
}
.msw-link:hover:not(:disabled) { text-decoration: underline; }
.msw-link:disabled { opacity: .5; cursor: not-allowed; }

/* The numbers at the top: fleet version, up to date, updating, and the roll out button */
.msw-status { display: flex; flex-wrap: wrap; align-items: stretch; }
.msw-stat { flex: 1 1 170px; min-width: 0; padding: 18px 24px; border-right: 1px solid #f0f0f5; }
.msw-stat__label { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: #6b7280; }
.msw-stat__value { font-size: 24px; font-weight: 800; color: #1f2937; margin-top: 4px; line-height: 1.2; }
.msw-stat__hint { font-size: 12px; color: #6b7280; margin-top: 2px; }
.msw-stat__hint.is-warning { color: #92400e; font-weight: 600; }
.msw-stat__hint.is-error { color: #991b1b; font-weight: 600; }
.msw-meter { height: 6px; border-radius: 3px; background: #f3f4f6; overflow: hidden; margin: 6px 0 4px; max-width: 220px; }
.msw-meter span { display: block; height: 100%; width: 0; border-radius: 3px; background: #22c55e; transition: width .3s ease; }
.msw-status__actions { flex: 0 1 auto; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 10px; padding: 18px 24px; }

/* What stops updates, said above everything else */
.msw-alert {
    display: flex;
    gap: 10px;
    align-items: baseline;
    background: #fef3c7;
    color: #92400e;
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 13px;
    font-weight: 500;
}
.msw-alert .msw-link { font-size: 13px; color: inherit; text-decoration: underline; }

/* Cards */
.msw-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
    margin-bottom: 20px;
    min-width: 0;
}
.msw-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f5;
}
.msw-card-title { font-size: 15px; font-weight: 700; color: #1f2937; display: flex; align-items: center; gap: 8px; margin: 0; }
.msw-card-title i { color: #8b1a4a; }
.msw-card-body { padding: 20px; }
.msw-note { font-size: 12px; color: #6b7280; }
.msw-muted { color: #9ca3af; }
.msw-mono { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; }

/* Pills */
.msw-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    background: #f3f4f6;
    color: #374151;
}
.msw-pill--success { background: #dcfce7; color: #166534; }
.msw-pill--warning { background: #fef3c7; color: #92400e; }
.msw-pill--error { background: #fee2e2; color: #991b1b; }
.msw-pill--info { background: #dbeafe; color: #1e40af; }
.msw-pill--primary { background: rgba(139, 26, 74, .1); color: #8b1a4a; }
.msw-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #d1d5db; margin-right: 6px; vertical-align: middle; }
.msw-dot--on { background: #22c55e; }

/* Rollout form */
.msw-field { margin-bottom: 16px; }
.msw-field > label, .msw-field__label { display: block; font-size: 12px; font-weight: 600; color: #4b5563; margin-bottom: 6px; }
.msw-select, .msw-input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    color: #1f2937;
    background: #fff;
}
.msw-select:focus, .msw-input:focus { outline: none; border-color: #8b1a4a; box-shadow: 0 0 0 3px rgba(139, 26, 74, .1); }
.msw-options { display: grid; gap: 8px; }
.msw-option {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    cursor: pointer;
    margin: 0;
    font-weight: 400;
}
.msw-option input { margin-top: 3px; accent-color: #8b1a4a; }
.msw-option.is-checked { border-color: #8b1a4a; background: rgba(139, 26, 74, .04); }
.msw-option__title { font-size: 13px; font-weight: 600; color: #1f2937; }
.msw-option__hint { font-size: 12px; color: #6b7280; }
.msw-option .msw-select { margin-top: 6px; }
.msw-notes {
    margin-top: 8px;
    font-size: 12px;
    color: #374151;
    background: #f9fafb;
    border: 1px solid #f0f0f5;
    border-radius: 8px;
    padding: 8px 12px;
}
.msw-notes summary { cursor: pointer; font-weight: 600; color: #4b5563; }
.msw-notes pre { white-space: pre-wrap; font: inherit; margin: 8px 0 0; max-height: 220px; overflow: auto; background: none; border: 0; padding: 0; }
.msw-summary {
    font-size: 13px;
    color: #374151;
    background: #f9fafb;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}
.msw-summary.is-now { background: #fef3c7; color: #92400e; }
.msw-bad { color: #991b1b; }

/* The PLC program that comes with a version: its block in the rollout dialog, and a machine's line */
.msw-plc__box {
    font-size: 13px;
    color: #1f2937;
    background: #f9fafb;
    border: 1px solid #f0f0f5;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}
.msw-plc__box.msw-muted { color: #6b7280; }
.msw-plc__actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.msw-plc__file { margin: 0; cursor: pointer; }
.msw-plc__file input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.msw-plc__file:focus-within { box-shadow: 0 0 0 3px rgba(139, 26, 74, .15); }
.msw-plc__note { margin: 8px 0 0 0; }
.msw-plc__busy { color: #4b5563; }
.msw-plc__now { margin: 0 0 8px 0; font-weight: 600; color: #92400e; }
.msw-plc-line { font-size: 12px; color: #4b5563; margin-top: 4px; overflow-wrap: anywhere; }
.msw-plc-line__label { font-size: 10px; font-weight: 700; letter-spacing: .04em; color: #9ca3af; }
.msw-device-item__value .msw-plc-line { font-size: 13px; margin-top: 0; }
.msw-device-item__value .msw-plc-line__label { display: none; }

/* A choice of two or three (the rollout dialog): one row of radio buttons that reads as a switch */
.msw-seg { display: flex; border: 1px solid #d1d5db; border-radius: 8px; overflow: hidden; }
.msw-seg label { flex: 1 1 0; margin: 0; font-weight: 400; cursor: pointer; border-left: 1px solid #d1d5db; }
.msw-seg label:first-child { border-left: 0; }
.msw-seg input { position: absolute; opacity: 0; pointer-events: none; }
.msw-seg span { display: block; padding: 7px 10px; font-size: 13px; font-weight: 600; color: #4b5563; text-align: center; background: #fff; }
.msw-seg input:checked + span { background: #8b1a4a; color: #fff; }
.msw-seg input:focus-visible + span { box-shadow: inset 0 0 0 2px rgba(139, 26, 74, .45); }
.msw-seg input:disabled + span { color: #d1d5db; cursor: not-allowed; }
.msw-ro .msw-select[id=msw-ro-client] { margin-top: 8px; }
.msw-check { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0 0; font-size: 13px; font-weight: 500; color: #374151; cursor: pointer; }
.msw-check input { margin-top: 2px; accent-color: #8b1a4a; }
.msw-ro .msw-summary { margin: 0; }
#msw-modal .modal-body { padding: 20px; } /* the app drops the side padding of dialogs on a phone */

/* The release feed block: the key SAS reads it with, and how many machines fetch through SAS */
.msw-feed__text { margin: 0 0 12px 0; }
.msw-feed__text:last-child { margin-bottom: 0; }
.msw-feed__text ol { margin: 6px 0; padding-left: 20px; }
#msw-feed-form { margin-bottom: 12px; }
.msw-feed__row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.msw-feed__row .msw-input { flex: 1 1 220px; min-width: 0; }

/* Rollouts */
.msw-rollout { border: 1px solid #f0f0f5; border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.msw-rollout:last-child { margin-bottom: 0; }
/* the rollout in progress is a card of its own above the machines */
.msw-rollout.msw-card { padding: 18px 24px; margin-bottom: 20px; border-color: #e5e7eb; border-radius: 14px; }
.msw-rollout__eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: #8b1a4a; margin-bottom: 4px; }
.msw-rollout__head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.msw-rollout__title { font-size: 14px; font-weight: 700; color: #1f2937; }
.msw-rollout__meta { font-size: 12px; color: #6b7280; margin-top: 2px; }
.msw-progress { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: #f3f4f6; margin: 10px 0 8px; }
.msw-progress span { display: block; height: 100%; }
.msw-rollout__counts { font-size: 12px; color: #4b5563; }
.msw-rollout details { margin-top: 8px; font-size: 12px; }
.msw-rollout details summary { cursor: pointer; color: #6b7280; font-weight: 600; }
/* the small fold-outs (a rollout's machines, release notes, a machine's history) get the same arrow as the cards that fold */
.msw-rollout details > summary,
.msw-notes > summary { list-style: none; }
.msw-rollout details > summary::-webkit-details-marker,
.msw-notes > summary::-webkit-details-marker { display: none; }
.msw-rollout details > summary::before,
.msw-notes > summary::before { content: "\f105"; display: inline-block; font: normal 13px/1 FontAwesome; color: #9ca3af; width: 12px; transition: transform .15s ease; }
.msw-rollout details[open] > summary::before,
.msw-notes[open] > summary::before { transform: rotate(90deg); }
.msw-rollout__machines { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.msw-rollout__machines li { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }

.msw-state--done { background: #22c55e; }
.msw-state--updating { background: #3b82f6; }
.msw-state--failed { background: #dc2626; }
.msw-state--pending { background: #9ca3af; }
.msw-state--silent { background: #d1d5db; }

/* Machines table */
.msw-toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.msw-toolbar .msw-input { width: 220px; }
.msw-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.msw-chips:empty { display: none; }
.msw-chip {
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid #e5e7eb;
    background: #fff;
    font-size: 12px;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
}
.msw-chip span { font-weight: 500; opacity: .7; margin-left: 2px; }
.msw-chip.is-active { background: #8b1a4a; border-color: #8b1a4a; color: #fff; }
/* the ticked rows and what to do with them */
.msw-selection { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 10px 20px; font-size: 13px; color: #374151; background: rgba(139, 26, 74, .05); border-bottom: 1px solid #f0f0f5; }
.msw-table-wrap { overflow-x: auto; }
.msw-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.msw-table th {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #6b7280;
    border-bottom: 2px solid #e5e7eb;
    padding: 10px 12px;
    text-align: left;
    white-space: nowrap;
}
.msw-table td { padding: 10px 12px; border-bottom: 1px solid #f5f5fa; color: #374151; vertical-align: middle; }
.msw-table th:first-child, .msw-table td:first-child { padding-left: 20px; }
.msw-table th:last-child, .msw-table td:last-child { padding-right: 20px; }
.msw-table tbody tr:last-child td { border-bottom: 0; }
.msw-table tr:hover td { background: #fafbfc; }
.msw-table tr.is-selected td { background: rgba(139, 26, 74, .04); }
.msw-table td a { color: #8b1a4a; font-weight: 600; }
.msw-table input[type=checkbox] { accent-color: #8b1a4a; }
.msw-sub { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.msw-blockers { margin: 4px 0 0; padding-left: 16px; font-size: 11px; color: #92400e; }
.msw-actions { white-space: nowrap; text-align: right; }
.msw-nowrap, .msw-table td > a { white-space: nowrap; }
.msw-arrow { color: #9ca3af; }
.msw-target { font-weight: 700; color: #92400e; }
.msw-table td .msw-link { margin-left: 6px; }
.msw-actions .msw-btn + .msw-link { margin-left: 12px; }
.msw-footnote { padding: 12px 20px; border-top: 1px solid #f0f0f5; font-size: 12px; color: #6b7280; }

/* What is rarely needed: a card that opens on a click */
.msw-fold > summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    cursor: pointer;
    list-style: none;
    font-size: 14px;
    font-weight: 700;
    color: #1f2937;
}
.msw-fold > summary::-webkit-details-marker { display: none; }
.msw-fold > summary::before { content: "\f105"; font: normal 16px/1 FontAwesome; color: #9ca3af; width: 10px; transition: transform .15s ease; }
.msw-fold[open] > summary::before { transform: rotate(90deg); }
.msw-fold[open] > summary { border-bottom: 1px solid #f0f0f5; }
.msw-fold > summary:focus-visible { outline: 2px solid rgba(139, 26, 74, .45); outline-offset: -2px; border-radius: 14px; }
.msw-fold__count { font-size: 12px; font-weight: 600; color: #6b7280; background: #f3f4f6; border-radius: 20px; padding: 1px 9px; }
.msw-fold__note { margin: 0; padding: 14px 20px 4px; }
.msw-fold { margin-bottom: 12px; }
.msw-empty { padding: 28px; text-align: center; color: #9ca3af; font-size: 13px; }

/* Log */
.msw-log { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.msw-log li { padding: 7px 0; border-bottom: 1px solid #f5f5fa; display: flex; gap: 10px; flex-wrap: wrap; }
.msw-log li:last-child { border-bottom: 0; }
.msw-log time { color: #9ca3af; min-width: 120px; }

/* Machine page card */
.msw-device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.msw-device-item { background: #f9fafb; border: 1px solid #f0f0f5; border-radius: 10px; padding: 10px 14px; }
.msw-device-item__label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: #6b7280; }
.msw-device-item__value { font-size: 15px; font-weight: 700; color: #1f2937; margin-top: 2px; }
.msw-device-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.msw-device-controls .msw-select { width: auto; min-width: 220px; }
.msw-status-msg { font-size: 12px; margin-top: 8px; }
.msw-status-msg.is-error { color: #991b1b; }
.msw-status-msg.is-ok { color: #166534; }

@media (max-width: 768px) {
    .msw-toolbar .msw-input { width: 100%; }
    .msw-table { min-width: 620px; } /* scrolls sideways instead of squeezing its columns */
    .msw-stat { border-right: 0; border-bottom: 1px solid #f0f0f5; padding: 14px 16px; }
    .msw-status__actions { padding: 14px 16px; }
    .msw-device-controls .msw-select { min-width: 0; width: 100%; }
    .msw-card-body { padding: 16px; }
}

/* Dark mode
   ========================================================================== */
html.theme-dark .msw-page-header__title,
html.theme-dark .msw-stat__value,
html.theme-dark .msw-fold > summary,
html.theme-dark .msw-card-title,
html.theme-dark .msw-option__title,
html.theme-dark .msw-rollout__title,
html.theme-dark .msw-device-item__value { color: #e0e0e0 !important; }
html.theme-dark .msw-card,
html.theme-dark .msw-seg span,
html.theme-dark .msw-chip,
html.theme-dark .msw-app,
html.theme-dark .msw-select,
html.theme-dark .msw-input,
html.theme-dark .msw-btn--outline { background: #1e2022 !important; border-color: #2b2b2b !important; color: #dbdbdb !important; }
html.theme-dark .msw-card-header,
html.theme-dark .msw-stat,
html.theme-dark .msw-seg,
html.theme-dark .msw-seg label,
html.theme-dark .msw-selection,
html.theme-dark .msw-footnote,
html.theme-dark .msw-fold[open] > summary,
html.theme-dark .msw-rollout,
html.theme-dark .msw-option,
html.theme-dark .msw-table th,
html.theme-dark .msw-table td,
html.theme-dark .msw-log li { border-color: #2b2b2b !important; }
html.theme-dark .msw-table td,
html.theme-dark .msw-summary,
html.theme-dark .msw-selection,
html.theme-dark .msw-check,
html.theme-dark .msw-rollout__counts,
html.theme-dark .msw-notes { color: #dbdbdb !important; }
html.theme-dark .msw-table tr:hover td { background: #1a1c1e !important; }
html.theme-dark .msw-summary,
html.theme-dark .msw-notes,
html.theme-dark .msw-device-item { background: #282a2b !important; border-color: #2b2b2b !important; }
html.theme-dark .msw-summary.is-now,
html.theme-dark .msw-alert { background: #92400e33 !important; color: #fbbf24 !important; }
html.theme-dark .msw-stat__hint.is-warning,
html.theme-dark .msw-target { color: #fbbf24 !important; }
html.theme-dark .msw-stat__hint.is-error,
html.theme-dark .msw-bad { color: #f87171 !important; }
html.theme-dark .msw-link,
html.theme-dark .msw-rollout__eyebrow { color: #f9a8d4 !important; }
html.theme-dark .msw-alert .msw-link { color: inherit !important; }
html.theme-dark .msw-seg input:checked + span { background: #8b1a4a !important; color: #fff !important; }
html.theme-dark .msw-seg input:disabled + span { color: #555555 !important; }
html.theme-dark .msw-meter,
html.theme-dark .msw-fold__count,
html.theme-dark .msw-progress,
html.theme-dark .msw-pill { background: #333333 !important; color: #dbdbdb !important; }
html.theme-dark .msw-pill--success { background: #16653433 !important; color: #4ade80 !important; }
html.theme-dark .msw-pill--warning { background: #92400e33 !important; color: #fbbf24 !important; }
html.theme-dark .msw-pill--error { background: #991b1b33 !important; color: #f87171 !important; }
html.theme-dark .msw-pill--info { background: #1e40af33 !important; color: #93c5fd !important; }
html.theme-dark .msw-pill--primary { background: #8b1a4a33 !important; color: #f9a8d4 !important; }
html.theme-dark .msw-chip.is-active,
html.theme-dark .msw-app.is-active { background: #8b1a4a !important; border-color: #8b1a4a !important; color: #fff !important; }
html.theme-dark .msw-option.is-checked { border-color: #a8325f !important; background: #8b1a4a1a !important; }
html.theme-dark .msw-table td a { color: #f9a8d4 !important; }
html.theme-dark .msw-btn--danger { background: #991b1b33 !important; color: #f87171 !important; }
