:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #687386;
  --border: #e3e8ef;
  --border-strong: #d3dae4;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

:root.dark {
  color-scheme: dark;
  --bg: #111318;
  --panel: #191c23;
  --panel-soft: #20242c;
  --text: #eef2f7;
  --muted: #9aa4b2;
  --border: #2b3039;
  --border-strong: #3a414d;
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --primary-soft: #17243a;
  --green: #34d399;
  --green-soft: #122b24;
  --amber: #fbbf24;
  --amber-soft: #312613;
  --red: #f87171;
  --red-soft: #35191d;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.brand, .header-actions, .toolbar, .field-row, .server-clock { display: flex; align-items: center; }
.brand { gap: 11px; min-width: 0; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; }
.brand h1 { margin: 0; font-size: 17px; line-height: 22px; font-weight: 700; }
.brand-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; box-shadow: 0 0 0 3px color-mix(in srgb, #94a3b8 16%, transparent); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent); }
.status-dot.error { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 18%, transparent); }
.header-actions { gap: 9px; }
.server-clock { gap: 7px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 96px; }
.server-clock svg { width: 15px; height: 15px; }

main { width: min(1540px, 100%); margin: 0 auto; padding: 22px 28px 30px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 18px;
  overflow: hidden;
}

.metric { min-height: 82px; display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; }
.metric-icon svg { width: 18px; height: 18px; }
.metric-icon.blue { color: var(--primary); background: var(--primary-soft); }
.metric-icon.green { color: var(--green); background: var(--green-soft); }
.metric-icon.amber { color: var(--amber); background: var(--amber-soft); }
.metric-icon.gray { color: var(--muted); background: var(--panel-soft); }
.metric-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.metric strong { display: block; font-size: 17px; font-weight: 700; line-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 18px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.panel-header { min-height: 59px; padding: 12px 15px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.panel-header > div:first-child { min-width: 0; }
.panel-header h2, .dialog-header h2 { display: inline; margin: 0 8px 0 0; font-size: 14px; font-weight: 700; }
.subtle { color: var(--muted); font-size: 11px; }
.toolbar { gap: 8px; }

.btn, .icon-btn, .link-btn {
  border: 0;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}

.btn { height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 12px; border-radius: 5px; font-weight: 600; white-space: nowrap; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { color: #fff; background: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: var(--panel); border: 1px solid var(--border-strong); color: var(--text); }
.btn-secondary:hover, .icon-btn:hover { background: var(--panel-soft); border-color: var(--border-strong); }
.btn:disabled, .icon-btn:disabled { cursor: not-allowed; opacity: 0.55; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 5px; background: transparent; border: 1px solid var(--border); }
.icon-btn svg { width: 16px; height: 16px; }
.link-btn { display: inline-flex; align-items: center; gap: 5px; padding: 3px 0; color: var(--primary); background: none; font-size: 12px; }
.link-btn svg { width: 13px; height: 13px; }

.table-wrap { position: relative; min-height: 260px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 12px; text-align: left; color: var(--muted); background: var(--panel-soft); border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 600; white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--panel-soft) 72%, transparent); }
.center { text-align: center; }
.right { text-align: right; }
.task-name { display: block; max-width: 190px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-id { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.account-pill { display: inline-flex; max-width: 180px; padding: 3px 7px; border-radius: 4px; color: var(--text); background: var(--panel-soft); border: 1px solid var(--border); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-badge, .result-badge, .level-badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 999px; font-size: 11px; font-weight: 650; white-space: nowrap; }
.action-badge svg { width: 12px; height: 12px; }
.action-badge.enable, .result-badge.success, .result-badge.noop { color: var(--green); background: var(--green-soft); }
.action-badge.disable, .result-badge.partial { color: var(--amber); background: var(--amber-soft); }
.result-badge.failed, .level-badge.error { color: var(--red); background: var(--red-soft); }
.result-badge.pending { color: var(--muted); background: var(--panel-soft); }
.time-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; }
.next-run { min-width: 116px; color: var(--muted); font-size: 11px; line-height: 17px; }
.row-actions { display: flex; justify-content: flex-end; gap: 3px; }
.row-actions button { width: 28px; height: 28px; border: 0; display: grid; place-items: center; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.row-actions button:hover { color: var(--primary); background: var(--primary-soft); }
.row-actions button.danger:hover { color: var(--red); background: var(--red-soft); }
.row-actions svg { width: 14px; height: 14px; }

.toggle { position: relative; width: 36px; height: 20px; display: inline-block; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: 160ms ease; }
.toggle span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: 160ms ease; }
.toggle input:checked + span { background: #2563eb; }
.toggle input:checked + span::after { transform: translateX(16px); }

.logs-panel { max-height: calc(100vh - 130px); }
.logs-list { max-height: calc(100vh - 190px); min-height: 260px; overflow: auto; }
.log-item { display: grid; grid-template-columns: 7px minmax(0, 1fr); gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.log-item:last-child { border-bottom: 0; }
.log-mark { width: 7px; height: 7px; margin-top: 5px; border-radius: 50%; background: var(--primary); }
.log-mark.error { background: var(--red); }
.log-mark.noop { background: var(--green); }
.log-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.log-title strong { min-width: 0; font-size: 12px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-title time { flex: 0 0 auto; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.log-message { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 17px; overflow-wrap: anywhere; }
.log-meta { margin-top: 5px; display: flex; gap: 6px; flex-wrap: wrap; }
.log-meta span { color: var(--muted); background: var(--panel-soft); border-radius: 3px; padding: 2px 5px; font-size: 10px; }

.empty-state { min-height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; color: var(--muted); }
.empty-state.compact { min-height: 260px; }
.empty-state strong { font-size: 12px; font-weight: 600; }
.empty-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--muted); background: var(--panel-soft); border-radius: 6px; }
.empty-icon svg { width: 19px; height: 19px; }
.hidden { display: none !important; }

dialog { width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 7px; box-shadow: var(--shadow); overflow: hidden; }
dialog::backdrop { background: rgba(10, 15, 25, 0.5); backdrop-filter: blur(2px); }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 17px; }
.dialog-header { border-bottom: 1px solid var(--border); }
.dialog-footer { justify-content: flex-end; border-top: 1px solid var(--border); }
.dialog-body { max-height: calc(100vh - 170px); padding: 17px; overflow-y: auto; }
.field { display: block; padding: 0; margin: 0 0 16px; border: 0; }
.field > span, .field legend, .field-row > span { display: block; margin-bottom: 7px; color: var(--text); font-size: 12px; font-weight: 650; }
.field-row { justify-content: space-between; }
.field-row > span { margin-bottom: 7px; }
input, select { width: 100%; height: 38px; padding: 0 10px; color: var(--text); background: var(--panel); border: 1px solid var(--border-strong); border-radius: 5px; outline: none; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 13%, transparent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: var(--panel-soft); border: 1px solid var(--border); border-radius: 6px; }
.segmented button { height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 600; }
.segmented button svg { width: 15px; height: 15px; }
.segmented button.active.enable { color: var(--green); background: var(--panel); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.segmented button.active.disable { color: var(--amber); background: var(--panel); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.account-picker { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.search-box { position: relative; border-bottom: 1px solid var(--border); }
.search-box svg { position: absolute; left: 10px; top: 11px; width: 15px; height: 15px; color: var(--muted); }
.search-box input { height: 36px; padding-left: 34px; border: 0; border-radius: 0; box-shadow: none; }
.account-list { height: 190px; overflow-y: auto; }
.account-option { min-height: 42px; display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 7px 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.account-option:last-child { border-bottom: 0; }
.account-option:hover { background: var(--panel-soft); }
.account-option input { width: 15px; height: 15px; margin: 0; accent-color: #2563eb; }
.account-name { min-width: 0; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-info { color: var(--muted); font-size: 10px; }
.account-state { padding: 2px 5px; border-radius: 3px; font-size: 10px; }
.account-state.on { color: var(--green); background: var(--green-soft); }
.account-state.off { color: var(--muted); background: var(--panel-soft); }
.loading-row { height: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 12px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 800ms linear infinite; }
.switch-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 3px; padding: 12px; background: var(--panel-soft); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.switch-row > div { min-width: 0; }
.switch-row strong { display: block; font-size: 12px; }
.switch-row div span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; flex: 0 0 auto; width: 38px; height: 21px; border-radius: 999px; background: var(--border-strong); transition: 160ms ease; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: 160ms ease; }
.switch-row input:checked + .switch { background: #2563eb; }
.switch-row input:checked + .switch::after { transform: translateX(17px); }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 36px)); }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 11px 12px; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--green); border-radius: 5px; box-shadow: var(--shadow); font-size: 12px; line-height: 18px; }
.toast.error { border-left-color: var(--red); }
.toast svg { flex: 0 0 auto; width: 15px; height: 15px; margin-top: 1px; color: var(--green); }
.toast.error svg { color: var(--red); }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 1fr; }
  .logs-panel { max-height: none; }
  .logs-list { max-height: 440px; }
}

@media (max-width: 760px) {
  .topbar { height: auto; min-height: 64px; padding: 10px 14px; }
  .server-clock { display: none; }
  #test-connection span { display: none; }
  #test-connection { width: 34px; padding: 0; }
  main { padding: 14px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric { min-height: 72px; padding: 12px; border-bottom: 1px solid var(--border); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(3), .metric:nth-child(4) { border-bottom: 0; }
  .metric strong { font-size: 14px; }
  .metric-icon { width: 32px; height: 32px; }
  .table-wrap { min-height: 220px; }
  th, td { padding: 9px 10px; }
  th:nth-child(2), td:nth-child(2), th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { display: none; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .dialog-body { padding: 14px; }
}

@media (max-width: 420px) {
  .brand h1 { font-size: 15px; }
  .brand-logo { width: 30px; height: 30px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--border) !important; }
  .metric:last-child { border-bottom: 0 !important; }
  .panel-header { align-items: flex-start; }
  .btn { padding: 0 10px; }
}
