:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --ink: #151a1d;
  --muted: #68747b;
  --line: #dce2e5;
  --green: #138a5b;
  --green-soft: #e8f5ef;
  --red: #c23932;
  --red-soft: #fbeceb;
  --blue: #1769aa;
  --blue-soft: #eaf3fa;
  --amber: #a56610;
  --shadow: 0 10px 28px rgba(22, 31, 36, 0.07);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; letter-spacing: 0; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #172127; }
.login-panel { width: min(100%, 390px); padding: 34px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.brand-mark { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 7px; background: var(--ink); color: #fff; font-size: 15px; font-weight: 800; }
.brand-mark.small { width: 38px; height: 38px; font-size: 12px; }
.login-panel h1 { margin: 24px 0 5px; font-size: 27px; line-height: 1.2; }
.login-panel p { margin: 0 0 28px; color: var(--muted); font-size: 14px; }
.login-panel label { display: block; margin: 0 0 8px; color: #3d474d; font-size: 13px; font-weight: 700; }
.login-panel input { width: 100%; height: 46px; margin-bottom: 17px; padding: 0 13px; border: 1px solid #bcc7cc; border-radius: 6px; outline: none; }
.login-panel input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.form-error { min-height: 20px; margin-top: 12px; color: var(--red); font-size: 13px; }
.form-error.success { color: var(--green); }

.app-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 50px; }
.topbar, .brand-row, .header-actions, .fleet-heading, .target-header, .target-status, .traffic-band, .traffic-copy, .panel-heading, .dialog-actions { display: flex; align-items: center; }
.topbar { min-height: 64px; justify-content: space-between; margin-bottom: 18px; }
.brand-row { min-width: 0; gap: 12px; }
.brand-row h1 { margin: 0; font-size: 19px; line-height: 1.2; }
.brand-row p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { flex: 0 0 auto; gap: 7px; }
.header-actions .button { width: 54px; min-width: 54px; padding-inline: 0; }
.button { min-height: 40px; padding: 0 15px; border: 1px solid transparent; border-radius: 6px; font-size: 13px; font-weight: 700; }
.button.primary { background: var(--blue); color: #fff; }
.button.quiet { border-color: var(--line); background: transparent; color: #445057; }
.button.secondary { border-color: #b9c9d4; background: var(--blue-soft); color: #155c91; }
.button.danger { background: var(--red); color: #fff; }
.button.wide { width: 100%; }

.banner { margin-bottom: 14px; padding: 11px 14px; border: 1px solid #b9d1e2; border-radius: 6px; background: var(--blue-soft); color: #164e73; font-size: 13px; }
.banner.error { border-color: #edc0bd; background: var(--red-soft); color: #842b27; }
.section-label { margin: 0 0 5px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }

.fleet-layout { display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 18px; align-items: start; }
.fleet-panel { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.fleet-heading { justify-content: space-between; padding: 22px; border-bottom: 1px solid var(--line); }
.fleet-heading h2, .target-header h2 { margin: 0; font-size: 20px; }
.fleet-heading > span { min-width: 28px; color: var(--muted); text-align: right; font-size: 13px; font-weight: 800; }
.target-list { padding: 8px; }
.target-row { display: grid; width: 100%; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 11px; align-items: center; min-height: 72px; padding: 11px 12px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--ink); text-align: left; }
.target-row:hover { background: #f5f7f8; }
.target-row.selected { border-color: #b7cee0; background: var(--blue-soft); }
.target-copy { min-width: 0; }
.target-copy strong, .target-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-copy strong { font-size: 13px; }
.target-copy small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.target-state { color: var(--muted); font-size: 11px; font-weight: 700; }

.target-detail { min-width: 0; }
.target-header { justify-content: space-between; min-height: 100px; padding: 8px 4px 18px; border-bottom: 1px solid var(--line); }
.target-header > div:first-child { min-width: 0; }
.target-header h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-header > div > p:last-child { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.target-status { flex: 0 0 auto; gap: 10px; font-size: 14px; }
.status-dot { width: 16px; height: 16px; flex: 0 0 16px; border: 4px solid #edf0f2; border-radius: 50%; background: #98a2a8; box-shadow: 0 0 0 1px #98a2a8; }
.status-dot.mini { width: 10px; height: 10px; flex-basis: 10px; border-width: 2px; }
.status-dot.running { border-color: var(--green-soft); background: var(--green); box-shadow: 0 0 0 1px var(--green); }
.status-dot.stopped, .status-dot.error { border-color: var(--red-soft); background: var(--red); box-shadow: 0 0 0 1px var(--red); }
.status-dot.starting { border-color: var(--blue-soft); background: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.status-dot.stopping { border-color: #fff3df; background: var(--amber); box-shadow: 0 0 0 1px var(--amber); }

.traffic-band { justify-content: space-between; gap: 30px; margin-top: 18px; padding: 24px 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.traffic-band h3 { margin: 0; font-size: 25px; }
.traffic-error { max-width: 300px; margin: 7px 0 0; color: var(--red); font-size: 11px; line-height: 1.45; overflow-wrap: anywhere; }
.threshold-form { margin-top: 17px; }
.threshold-form label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.threshold-input-row { display: flex; align-items: center; gap: 8px; }
.threshold-input-row input { width: 108px; height: 40px; padding: 0 10px; border: 1px solid #bcc7cc; border-radius: 6px; background: #fff; color: var(--ink); outline: none; }
.threshold-input-row input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.threshold-input-row span { color: var(--muted); font-size: 12px; font-weight: 700; }
.traffic-meter { width: min(64%, 560px); }
.traffic-copy { justify-content: space-between; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.progress-track { width: 100%; height: 8px; overflow: hidden; border-radius: 4px; background: #e8edef; }
.progress-value { width: 0; height: 100%; background: var(--blue); transition: width 220ms ease, background 220ms ease; }
.progress-value.warning { background: var(--amber); }
.progress-value.danger { background: var(--red); }

.control-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(290px, .85fr); gap: 18px; margin-top: 18px; }
.control-panel, .policy-panel { min-height: 292px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.panel-heading { justify-content: space-between; gap: 18px; }
.panel-heading h3, .activity h3 { margin: 0; font-size: 19px; }
.operation-state { color: var(--muted); font-size: 12px; font-weight: 700; }
.power-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 39px; }
.power-button { display: flex; min-height: 112px; align-items: center; justify-content: center; gap: 13px; border: 1px solid var(--line); border-radius: 7px; background: #fafbfb; color: var(--ink); font-size: 14px; font-weight: 800; }
.power-button.start:hover:not(:disabled) { border-color: #82bda5; background: var(--green-soft); color: #0c6c45; }
.power-button.stop:hover:not(:disabled) { border-color: #dda6a2; background: var(--red-soft); color: #9d2d28; }
.power-symbol, .stop-symbol { display: inline-block; width: 22px; height: 22px; }
.power-symbol { position: relative; border: 3px solid currentColor; border-top-color: transparent; border-radius: 50%; }
.power-symbol::before { position: absolute; top: -4px; left: 7px; width: 3px; height: 12px; border-radius: 2px; background: currentColor; content: ""; }
.stop-symbol { border: 3px solid currentColor; border-radius: 3px; }

.switch { display: inline-flex; width: 44px; height: 26px; flex: 0 0 44px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: relative; width: 100%; border-radius: 13px; background: #b6c0c5; transition: background 160ms ease; }
.switch-track::after { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); content: ""; transition: transform 160ms ease; }
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--blue-soft); outline-offset: 2px; }
.policy-list { margin: 25px 0 21px; }
.policy-list > div { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid #edf0f1; }
.policy-list dt, .policy-list dd { margin: 0; font-size: 13px; }
.policy-list dt { color: var(--muted); }
.policy-list dd { text-align: right; font-weight: 700; }

.schedule-panel { margin-top: 18px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.schedule-toolbar { display: flex; justify-content: flex-end; margin-top: 18px; }
.schedule-toolbar label { width: min(100%, 300px); }
.schedule-toolbar span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.schedule-toolbar input, .schedule-toolbar select, .schedule-bulk input, .schedule-day-row input[type="time"] { width: 100%; height: 42px; padding: 0 11px; border: 1px solid #bcc7cc; border-radius: 6px; background: #fff; color: var(--ink); outline: none; }
.schedule-toolbar input:focus, .schedule-toolbar select:focus, .schedule-bulk input:focus, .schedule-day-row input[type="time"]:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.schedule-bulk { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 12px 18px; align-items: end; margin-top: 18px; padding: 16px; border: 1px solid #cbd9e1; border-radius: 6px; background: #f6fafc; }
.schedule-bulk .section-label { margin-bottom: 4px; }
.schedule-bulk h4 { margin: 0; font-size: 14px; }
.schedule-bulk-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.schedule-bulk-actions .button { min-height: 32px; padding: 0 10px; font-size: 12px; }
.schedule-bulk-fields { display: grid; grid-column: 1 / -1; grid-template-columns: 130px 130px minmax(150px, max-content); justify-content: end; gap: 10px; align-items: end; }
.schedule-bulk-fields label, .schedule-time-field { min-width: 0; }
.schedule-bulk-fields label > span, .schedule-time-field > span { display: block; margin: 0 0 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.schedule-bulk-fields .button { min-height: 42px; }
.schedule-table { margin-top: 14px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.schedule-table-head, .schedule-day-row { display: grid; grid-template-columns: 56px minmax(70px, 1fr) 70px minmax(120px, 1.3fr) minmax(120px, 1.3fr); gap: 12px; align-items: center; }
.schedule-table-head { min-height: 38px; padding: 0 14px; background: #eef3f6; color: var(--muted); font-size: 11px; font-weight: 800; }
.schedule-days { display: grid; }
.schedule-day-row { min-width: 0; min-height: 58px; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--surface); }
.schedule-day-row:first-child { border-top: 0; }
.schedule-select-cell { display: grid; place-items: center; height: 100%; }
.schedule-select-cell input { width: 17px; height: 17px; accent-color: var(--blue); }
.schedule-day-name { font-size: 13px; }
.switch.compact { width: 38px; height: 22px; justify-self: start; flex-basis: 38px; }
.switch.compact .switch-track { border-radius: 11px; }
.switch.compact .switch-track::after { top: 3px; left: 3px; width: 16px; height: 16px; }
.switch.compact input:checked + .switch-track::after { transform: translateX(16px); }
.schedule-time-field { min-width: 0; }
.schedule-day-row input[type="time"] { min-width: 0; height: 38px; padding: 0 9px; font-size: 13px; }
.schedule-footer { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-top: 22px; padding-top: 20px; border-top: 1px solid #edf0f1; }
.schedule-footer > div { min-width: 0; }
.schedule-footer > div > span { margin-bottom: 5px; }
.schedule-footer strong { display: block; overflow-wrap: anywhere; font-size: 13px; }
.schedule-footer .button { flex: 0 0 auto; }

.activity { margin-top: 18px; padding: 22px 4px 0; border-top: 1px solid var(--line); }
.activity-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.activity-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.activity-filters label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.activity-filters select { height: 32px; min-width: 116px; padding: 0 8px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink); font-size: 12px; }
.activity-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.activity-row { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 18px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: #3d484e; font-size: 13px; }
.activity-row > div { min-width: 0; }
.activity-row strong, .activity-row time { display: block; overflow-wrap: anywhere; }
.activity-row strong { color: var(--ink); font-size: 13px; }
.activity-row time { margin-top: 3px; color: var(--muted); font-size: 12px; }
.activity-outcome { flex: 0 0 auto; padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: 800; }
.activity-outcome.success { background: var(--green-soft); color: #0c6c45; }
.activity-outcome.skipped { background: #edf0f1; color: #566269; }
.activity-outcome.failed { background: var(--red-soft); color: #9d2d28; }
.activity-empty { padding: 16px 0; color: var(--muted); font-size: 13px; }
.activity-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.activity-meta { color: var(--muted); font-size: 12px; }
.confirm-dialog { width: min(430px, calc(100% - 32px)); padding: 0; border: 0; border-radius: var(--radius); box-shadow: 0 22px 70px rgba(0,0,0,.28); }
.confirm-dialog::backdrop { background: rgba(15,22,26,.62); }
.confirm-dialog form { padding: 28px; }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 21px; }
.confirm-dialog p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.dialog-actions { justify-content: flex-end; gap: 8px; margin-top: 25px; }

.management-view { min-width: 0; }
.management-heading, .management-section-heading, .editor-heading, .editor-actions, .management-row, .management-row-actions { display: flex; align-items: center; }
.management-heading { justify-content: space-between; min-height: 100px; padding: 8px 4px 18px; border-bottom: 1px solid var(--line); }
.management-heading h2, .management-section-heading h3 { margin: 0; }
.management-heading h2 { font-size: 22px; }
.management-section { padding: 28px 0; border-bottom: 1px solid var(--line); }
.management-section-heading { justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.management-section-heading h3 { font-size: 18px; }
.management-list { display: grid; gap: 8px; }
.management-row { min-width: 0; justify-content: space-between; gap: 18px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.management-row-copy { min-width: 0; }
.management-row-copy strong, .management-row-copy span { display: block; overflow-wrap: anywhere; }
.management-row-copy strong { font-size: 14px; }
.management-row-copy span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.management-row-actions { flex: 0 0 auto; gap: 7px; }
.empty-state { padding: 28px 4px; color: var(--muted); font-size: 13px; }

.editor-dialog { width: min(680px, calc(100% - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto; border: 0; border-radius: var(--radius); box-shadow: 0 22px 70px rgba(0,0,0,.28); }
.editor-dialog::backdrop { background: rgba(15,22,26,.62); }
.editor-dialog form { padding: 26px; }
.editor-heading { justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.editor-heading h2 { margin: 0; font-size: 21px; }
.editor-fields { display: grid; gap: 15px; }
.editor-fields.two-column { grid-template-columns: 1fr 1fr; }
.editor-fields label { min-width: 0; }
.editor-fields label > span, .confirm-totp > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.editor-fields input, .editor-fields select, .confirm-totp input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid #bcc7cc; border-radius: 6px; background: #fff; color: var(--ink); outline: none; }
.editor-fields input:focus, .editor-fields select:focus, .confirm-totp input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.editor-fields input:disabled { background: #eef1f2; color: var(--muted); }
.editor-fields .totp-input { grid-column: 1 / -1; max-width: 260px; }
.editor-actions { justify-content: flex-end; gap: 8px; margin-top: 10px; }
.confirm-totp { display: block; margin-top: 18px; }

@media (max-width: 900px) {
  .fleet-layout { grid-template-columns: 1fr; }
  .fleet-panel { background: transparent; box-shadow: none; }
  .fleet-heading { padding: 14px 2px; border-bottom: 0; }
  .target-list { display: grid; overflow-x: auto; grid-auto-flow: column; grid-auto-columns: minmax(220px, 72vw); gap: 8px; padding: 0 0 8px; scrollbar-width: thin; }
  .target-row { border-color: var(--line); background: var(--surface); }
}

@media (max-width: 680px) {
  .app-shell { width: min(100% - 24px, 620px); padding-top: 14px; }
  .topbar { margin-bottom: 12px; }
  .brand-row p { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .target-header { min-height: 90px; }
  .traffic-band, .control-grid { grid-template-columns: 1fr; }
  .traffic-band { align-items: stretch; flex-direction: column; gap: 23px; padding: 22px; }
  .traffic-meter { width: 100%; }
  .threshold-input-row input { flex: 1 1 auto; width: auto; min-width: 0; }
  .control-grid { display: grid; }
  .control-panel, .policy-panel { min-height: auto; padding: 22px; }
  .schedule-panel { padding: 22px; }
  .schedule-toolbar { justify-content: stretch; }
  .schedule-toolbar label { width: 100%; }
  .schedule-bulk { grid-template-columns: 1fr; }
  .schedule-bulk-actions { justify-content: flex-start; }
  .schedule-bulk-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); justify-content: stretch; }
  .schedule-bulk-fields .button { grid-column: 1 / -1; }
  .schedule-table { overflow: visible; border: 0; border-radius: 0; }
  .schedule-table-head { display: none; }
  .schedule-day-row { grid-template-columns: 28px minmax(58px, 1fr) 44px minmax(0, 1.25fr) minmax(0, 1.25fr); gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
  .schedule-day-row:first-child { border-top: 1px solid var(--line); }
  .schedule-time-field > span { font-size: 10px; }
  .activity-heading { align-items: flex-start; flex-direction: column; }
  .activity-row { align-items: flex-start; }
  .management-row { align-items: flex-start; flex-direction: column; }
  .management-row-actions { width: 100%; }
  .management-row-actions .button { flex: 1 1 0; }
  .editor-fields.two-column { grid-template-columns: 1fr; }
  .editor-fields .totp-input { grid-column: auto; max-width: none; }
}

@media (max-width: 440px) {
  .header-actions { gap: 4px; }
  .power-actions { grid-template-columns: 1fr; margin-top: 28px; }
  .power-button { min-height: 74px; }
  .target-header { align-items: flex-start; gap: 12px; }
  .target-status { margin-top: 21px; }
  .schedule-day-row { grid-template-columns: 24px 44px 36px minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
  .schedule-day-name { font-size: 12px; }
  .schedule-footer { align-items: stretch; flex-direction: column; }
  .schedule-footer .button { width: 100%; }
  .management-heading { align-items: flex-start; gap: 12px; }
  .management-section-heading { align-items: flex-start; }
  .editor-dialog form { padding: 21px; }
  .editor-heading { align-items: flex-start; }
  .editor-actions { align-items: stretch; flex-direction: column-reverse; }
  .editor-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
