/* ==========================================================================
   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: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0 0 20px 0;
}
.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; }
.msw-page-header__actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* 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; }

/* KPIs */
.msw-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.msw-kpi {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 16px 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
}
.msw-kpi__label { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: #6b7280; }
.msw-kpi__value { font-size: 24px; font-weight: 800; color: #1f2937; margin-top: 4px; line-height: 1.2; }
.msw-kpi__hint { font-size: 12px; color: #9ca3af; margin-top: 2px; }

/* 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; }

.msw-grid {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 20px;
}
@media (max-width: 1100px) {
    .msw-grid { grid-template-columns: minmax(0, 1fr); }
}

/* 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; }

/* Version distribution */
.msw-dist-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: #f3f4f6; margin: 4px 0 10px; }
.msw-dist-bar span { display: block; height: 100%; }
.msw-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: #4b5563; }
.msw-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Rollouts */
.msw-rollout { border: 1px solid #f0f0f5; border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.msw-rollout:last-child { margin-bottom: 0; }
.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-counts { display: flex; flex-wrap: wrap; gap: 6px; }
.msw-rollout details { margin-top: 8px; font-size: 12px; }
.msw-rollout details summary { cursor: pointer; color: #6b7280; font-weight: 600; }
.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--on_version { background: #22c55e; }
.msw-state--installing { background: #1e40af; }
.msw-state--downloading { background: #3b82f6; }
.msw-state--ready { background: #93c5fd; }
.msw-state--waiting { background: #f59e0b; }
.msw-state--failed { background: #dc2626; }
.msw-state--pending { background: #9ca3af; }
.msw-state--not_reporting { background: #d1d5db; }
.msw-state--moved_on { background: #e5e7eb; }

/* Machines table */
.msw-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.msw-toolbar .msw-input { width: 220px; }
.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.is-active { background: #8b1a4a; border-color: #8b1a4a; color: #fff; }
.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: top; }
.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-actions .dropdown-menu { font-size: 13px; }
.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-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-kpi__value,
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-kpi,
html.theme-dark .msw-card,
html.theme-dark .msw-chip,
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-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-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 { background: #92400e33 !important; color: #fbbf24 !important; }
html.theme-dark .msw-dist-bar,
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 { 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; }
