:root {
  --ink: #18211c;
  --muted: #6c756f;
  --soft: #f5f7f4;
  --surface: #ffffff;
  --line: #e2e7e3;
  --line-strong: #cfd7d1;
  --green: #247a52;
  --green-soft: #eaf5ee;
  --red: #b5413b;
  --red-soft: #fbedeb;
  --amber: #a56713;
  --amber-soft: #fff5df;
  --blue: #376c88;
  --radius: 12px;
  --shadow: 0 12px 34px rgba(34, 51, 41, .06);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--soft); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--soft); font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .93); border-bottom: 1px solid var(--line); backdrop-filter: blur(18px); }
.topbar-inner { width: min(1240px, calc(100% - 40px)); min-height: 62px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand > span:last-child { display: grid; gap: 1px; }
.brand strong { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand small { color: var(--muted); font-size: 11px; }
.brand-glyph { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; color: #fff; background: var(--ink); border-radius: 11px; font: 700 11px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: -.04em; }
.topbar-actions { display: flex; align-items: center; gap: 5px; }
.topbar-actions form { margin: 0; }
.quiet-action { min-height: 38px; display: inline-flex; align-items: center; gap: 6px; padding: 0 11px; color: var(--muted); background: transparent; border: 0; border-radius: 9px; text-decoration: none; font-size: 13px; font-weight: 600; }
.quiet-action:hover { color: var(--ink); background: var(--soft); }
.quiet-action span { font-size: 17px; font-weight: 400; }

.dashboard { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 64px; }
.system-overview { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding-bottom: 18px; }
.system-copy h1 { margin: 8px 0 6px; font-size: clamp(26px, 3vw, 34px); line-height: 1.05; letter-spacing: -.045em; font-weight: 650; }
.system-copy p { margin: 0; color: var(--muted); font-size: 12px; }
.status-line { display: inline-flex; align-items: center; gap: 8px; color: var(--green); font-size: 13px; font-weight: 700; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 5px rgba(36, 122, 82, .1); }
.status-line-failed { color: var(--red); }
.status-line-failed .status-dot { box-shadow: 0 0 0 5px rgba(181, 65, 59, .1); }
.status-line-running { color: var(--blue); }
.status-line-running .status-dot { animation: pulse 1.5s ease infinite; }
.status-line-waiting { color: var(--muted); }
.environment-badge { min-width: 178px; display: grid; gap: 4px; padding: 13px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.environment-badge span { color: var(--muted); font-size: 11px; }
.environment-badge strong { font-size: 13px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric-card { min-height: 86px; display: grid; gap: 8px; align-content: center; padding: 14px 18px; border-right: 1px solid var(--line); }
.metric-card:last-child { border-right: 0; }
.metric-card .metric-label { color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-card strong { margin-top: 0; font-size: clamp(26px, 3vw, 32px); line-height: 1; letter-spacing: -.04em; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-label { display: flex; align-items: center; gap: 7px; }

.control-panel { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 12px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.section-label { margin: 0 0 7px; color: var(--muted); font-size: 10px; line-height: 1.2; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
h2 { margin: 0; font-size: 18px; line-height: 1.25; letter-spacing: -.025em; font-weight: 650; }
.muted { color: var(--muted); line-height: 1.5; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.actions form { margin: 0; }
.button { min-height: 40px; appearance: none; display: inline-flex; align-items: center; justify-content: center; padding: 0 15px; border: 1px solid transparent; border-radius: 10px; font-size: 12px; font-weight: 700; transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .6; transform: none; }
.button-secondary { color: var(--ink); background: #fff; border-color: var(--line-strong); }
.button-secondary:hover { background: var(--soft); border-color: #b9c4bc; }
.button-primary { color: #fff; background: var(--ink); border-color: var(--ink); }
.button-primary:hover { background: #2a352e; }
.button.compact { min-height: 38px; }

.surface { margin-top: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.timeline-section { padding: 18px 20px 6px; }
.timeline-head { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.timeline-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 14px; }
.change-toggle { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; font-size: 10px; font-weight: 650; white-space: nowrap; user-select: none; }
.change-toggle input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.toggle-track { width: 32px; height: 18px; display: inline-flex; align-items: center; padding: 2px; border: 1px solid var(--line-strong); border-radius: 99px; background: var(--soft); transition: background .16s ease, border-color .16s ease; }
.toggle-track span { width: 12px; height: 12px; border-radius: 50%; background: #98a19a; box-shadow: 0 1px 2px rgba(24, 33, 28, .15); transition: transform .16s ease, background .16s ease; }
.change-toggle input:checked + .toggle-track { background: var(--green-soft); border-color: #aed3bc; }
.change-toggle input:checked + .toggle-track span { background: var(--green); transform: translateX(14px); }
.change-toggle input:focus-visible + .toggle-track { outline: 3px solid rgba(36, 122, 82, .12); outline-offset: 2px; }
.change-toggle > span:last-child { display: inline-flex; align-items: center; gap: 5px; }
.change-toggle b { min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px; color: var(--green); background: var(--green-soft); border-radius: 6px; font-size: 9px; font-variant-numeric: tabular-nums; }
.timeline-filters { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.filter-chip { min-height: 32px; padding: 0 11px; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 8px; font-size: 11px; font-weight: 650; }
.filter-chip:hover { color: var(--ink); background: var(--soft); }
.filter-chip.active { color: var(--ink); background: var(--soft); border-color: var(--line); }
.filter-chip-danger.active { color: var(--red); background: var(--red-soft); border-color: #f1d4d1; }

.timeline-list { position: relative; }
.timeline-list::before { content: ""; position: absolute; top: 28px; bottom: 28px; left: 9px; width: 1px; background: var(--line); }
.timeline-list.is-empty::before { display: none; }
.timeline-empty { margin: 0; text-align: center; }
.timeline-empty[hidden] { display: none; }
.timeline-event { position: relative; border-bottom: 1px solid var(--line); }
.timeline-event:last-child { border-bottom: 0; }
.timeline-event[hidden] { display: none; }
.timeline-event summary { min-height: 80px; display: grid; grid-template-columns: 20px minmax(0, 1fr) auto 20px; gap: 11px; align-items: center; padding: 10px 2px; list-style: none; cursor: pointer; }
.timeline-event summary::-webkit-details-marker { display: none; }
.timeline-event summary:hover .event-title strong { color: var(--green); }
.timeline-marker { position: relative; z-index: 1; width: 9px; height: 9px; margin-left: 5px; border: 2px solid #fff; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }
.timeline-event-failed .timeline-marker { background: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }
.timeline-event-running .timeline-marker { background: var(--blue); animation: pulse 1.5s ease infinite; }
.event-content { min-width: 0; display: grid; gap: 6px; }
.event-title { display: flex; align-items: center; gap: 9px; }
.event-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; transition: color .16s ease; }
.event-flow { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 10px; line-height: 1.4; }
.flow-route { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 5px; color: var(--ink); }
.flow-route b { padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--soft); font-weight: 650; }
.flow-route i { color: var(--green); font-size: 12px; font-style: normal; font-weight: 750; }
.flow-scope { min-width: 0; color: var(--muted); }
.flow-scope b { color: #747d76; font-weight: 650; }
.event-meta { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.event-id { color: #a0a7a2; font: 11px/1 "SFMono-Regular", Consolas, monospace; }
.event-chevron { color: #8e9690; font-size: 16px; transition: transform .16s ease; }
.timeline-event[open] .event-chevron { transform: rotate(180deg); }
.status, .level { display: inline-flex; align-items: center; min-height: 22px; padding: 0 7px; border-radius: 6px; font-size: 9px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.status-success, .level-info { color: var(--green); background: var(--green-soft); }
.status-failed, .level-error { color: var(--red); background: var(--red-soft); }
.status-running { color: var(--blue); background: #eaf3f7; }
.level-warning { color: var(--amber); background: var(--amber-soft); }
.level-debug { color: var(--muted); background: var(--soft); }
.event-details { margin: -4px 33px 17px; padding: 17px 19px; background: var(--soft); border-radius: 11px; }
.event-details > p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.counter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 8px; margin-top: 14px; }
.counter-grid > div { min-height: 65px; display: grid; align-content: space-between; gap: 7px; padding: 11px 12px; background: #fff; border: 1px solid var(--line); border-radius: 9px; }
.counter-grid span { color: var(--muted); font-size: 10px; }
.counter-grid strong { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.run-error { margin-top: 14px; padding: 13px 15px; color: var(--red); background: var(--red-soft); border-radius: 9px; }
.run-error strong { font-size: 11px; }
.run-error p { margin: 5px 0 0; font-size: 12px; line-height: 1.5; }

.log-drawer { overflow: hidden; }
.log-drawer > summary { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 20px; list-style: none; cursor: pointer; }
.log-drawer > summary::-webkit-details-marker { display: none; }
.log-drawer > summary > span:first-child { display: grid; }
.log-drawer > summary strong { font-size: 15px; }
.drawer-meta { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 11px; }
.drawer-meta b { font-size: 16px; transition: transform .16s ease; }
.log-drawer[open] .drawer-meta b { transform: rotate(180deg); }
.log-tools { padding: 0 20px 14px; border-top: 1px solid var(--line); }
.log-filter { width: min(320px, 100%); margin-top: 14px; padding: 10px 12px; color: var(--ink); background: var(--soft); border: 1px solid var(--line); border-radius: 9px; outline: 0; font-size: 12px; }
.log-filter:focus { background: #fff; border-color: #aebcb2; box-shadow: 0 0 0 3px rgba(36, 122, 82, .08); }
.log-list { max-height: 480px; overflow: auto; padding: 0 20px 20px; }
.log-row { display: grid; grid-template-columns: 135px 72px 100px minmax(0, 1fr); gap: 12px; align-items: center; min-height: 48px; border-top: 1px solid var(--line); font-size: 11px; }
.log-row[hidden] { display: none; }
.log-row time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-row > strong { font-size: 11px; }
.log-row p { margin: 0; line-height: 1.45; }

.heading-with-help { display: flex; align-items: center; gap: 8px; min-width: 0; }
.help-tooltip { display: inline-flex; flex: 0 0 auto; }
.help-trigger { width: 22px; height: 22px; display: inline-grid; place-items: center; padding: 0; color: var(--muted); background: var(--soft); border: 1px solid var(--line-strong); border-radius: 50%; font: 700 12px/1 Georgia, serif; cursor: help; }
.help-trigger:hover, .help-tooltip.is-open .help-trigger { color: var(--green); background: var(--green-soft); border-color: #aed3bc; }
.help-content { position: fixed; z-index: 50; display: none; width: min(360px, calc(100vw - 24px)); padding: 12px 14px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: 0 6px 24px rgba(24, 33, 28, .14); font: 12px/1.55 "Avenir Next", Avenir, "Segoe UI", sans-serif; font-weight: 400; letter-spacing: normal; text-transform: none; white-space: normal; overflow-wrap: anywhere; }
.help-tooltip.is-open .help-content { display: block; }
button:focus-visible, summary:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
.dashboard-drawer { scroll-margin-top: 78px; box-shadow: none; }
.review-panel.has-attention { border-color: #efd7b0; }
.drawer-summary { display: flex; align-items: center; gap: 10px; min-height: 66px; padding: 14px 20px; list-style: none; cursor: pointer; border-radius: var(--radius); }
.drawer-summary::-webkit-details-marker { display: none; }
.drawer-summary:hover { background: #fafbf9; }
.drawer-title { min-width: 0; font-size: 18px; line-height: 1.25; font-weight: 650; letter-spacing: -.025em; }
.drawer-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.drawer-counts { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; margin-left: auto; }
.count-chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 8px; color: var(--muted); background: var(--soft); border: 1px solid var(--line); border-radius: 7px; font-size: 11px; line-height: 1.3; white-space: nowrap; }
.count-chip b { font-size: 12px; font-variant-numeric: tabular-nums; }
.count-chip-alert { color: var(--red); background: var(--red-soft); border-color: #f1d4d1; }
.count-chip-waiting { color: #805214; background: var(--amber-soft); border-color: #efd7b0; }
.drawer-chevron { flex: 0 0 auto; color: var(--muted); font-size: 18px; transition: transform .16s ease; }
.dashboard-drawer[open] > .drawer-summary .drawer-chevron { transform: rotate(180deg); }
.drawer-body { padding: 16px 20px 20px; border-top: 1px solid var(--line); }
.drawer-body > .empty { margin: 0; padding: 4px 0; }
.review-group { scroll-margin-top: 78px; }
.review-group + .review-group { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.review-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.review-group h3 { margin: 0; font-size: 14px; font-weight: 700; }
.group-count { min-width: 24px; padding: 3px 6px; color: var(--muted); background: var(--soft); border-radius: 6px; text-align: center; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.conflict-list { display: grid; gap: 6px; margin-top: 10px; }
.conflict-item { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .65fr); gap: 16px; align-items: center; padding: 11px 13px; background: var(--amber-soft); border-radius: 8px; overflow-wrap: anywhere; }
#reconciliation .conflict-item, #queue .conflict-item { grid-template-columns: 1fr; }
.conflict-item strong, .conflict-item small { display: block; }
.conflict-item strong { font-size: 13px; }
.conflict-item small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.conflict-item p { margin: 5px 0 0; color: #7f5112; font-size: 12px; line-height: 1.45; }
.conflict-item form { display: flex; gap: 7px; }
.conflict-item input, .conflict-item select { min-width: 0; width: 100%; min-height: 38px; padding: 0 11px; color: var(--ink); background: #fff; border: 1px solid #dfcba8; border-radius: 8px; font-size: 12px; }
.user-panel-tools { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.user-panel-tools form { margin: 0; }
.user-mapping-list { display: grid; margin-bottom: 16px; }
.user-mapping-row { display: grid; grid-template-columns: minmax(140px, .7fr) repeat(2, minmax(0, 1fr)); gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: start; }
.user-mapping-row > div { min-width: 0; overflow-wrap: anywhere; }
.user-mapping-row strong { font-size: 13px; }
.user-mapping-row label { display: grid; gap: 6px; min-width: 0; font-size: 12px; }
.user-mapping-row small { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.user-mapping-row select { width: 100%; min-width: 0; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: inherit; }

.alert { margin: 0 0 18px; padding: 13px 16px; color: #65440e; background: var(--amber-soft); border: 1px solid #efd7b0; border-radius: 11px; font-size: 12px; }
.alert-error { color: var(--red); background: var(--red-soft); border-color: #f0d0cd; }
.empty { padding: 28px 0; color: var(--muted); font-size: 12px; }
.footer { width: min(1240px, calc(100% - 40px)); display: flex; justify-content: space-between; gap: 20px; margin: -34px auto 0; padding: 22px 0 30px; color: #969d98; border-top: 1px solid var(--line); font-size: 10px; }

.login-page { display: grid; place-items: center; padding: 24px; background: #f3f5f2; }
.login-shell { width: min(100%, 420px); }
.login-card { padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 44px; font-size: 13px; font-weight: 700; }
.login-card h1 { margin: 0; font-size: 29px; letter-spacing: -.04em; font-weight: 650; }
.login-card > .muted { margin: 8px 0 0; font-size: 13px; }
.login-card .alert { margin-top: 20px; }
.login-card form { display: grid; gap: 16px; margin-top: 30px; }
.login-card label { display: grid; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 650; }
.login-card input { width: 100%; min-height: 44px; padding: 0 13px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; outline: 0; }
.login-card input:focus { border-color: #9aada0; box-shadow: 0 0 0 3px rgba(36, 122, 82, .08); }
.login-card .button-primary { width: 100%; min-height: 44px; margin-top: 4px; }

@keyframes pulse { 50% { opacity: .4; transform: scale(.82); } }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-card:nth-child(2) { border-right: 0; }
  .metric-card:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .control-panel { align-items: flex-start; flex-direction: column; }
  .actions { justify-content: flex-start; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .timeline-controls { width: 100%; justify-content: flex-start; }
  .timeline-filters { justify-content: flex-start; }
  .conflict-item { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar-inner, .dashboard, .footer { width: min(100% - 24px, 1240px); }
  .topbar-inner { min-height: 62px; }
  .brand small { display: none; }
  .quiet-action { padding: 0 8px; font-size: 0; }
  .quiet-action span { font-size: 19px; }
  .topbar-actions form .quiet-action { font-size: 11px; }
  .dashboard { padding-top: 18px; }
  .system-overview { align-items: flex-start; flex-direction: column; gap: 18px; }
  .system-copy h1 { font-size: 28px; }
  .environment-badge { min-width: 0; width: 100%; grid-template-columns: 1fr auto; align-items: center; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 80px; padding: 12px 14px; }
  .metric-card strong { font-size: 28px; }
  .control-panel, .timeline-section { padding: 16px; }
  .actions { width: 100%; display: grid; grid-template-columns: 1fr; }
  .actions .button { width: 100%; }
  .timeline-head { padding-bottom: 14px; }
  .timeline-controls { align-items: flex-start; flex-direction: column; gap: 11px; }
  .timeline-filters { width: 100%; flex-wrap: wrap; }
  .filter-chip { white-space: nowrap; }
  .timeline-event summary { grid-template-columns: 20px minmax(0, 1fr) 16px; gap: 10px; }
  .event-id { display: none; }
  .event-title { align-items: flex-start; flex-direction: column; gap: 5px; }
  .event-flow { align-items: flex-start; flex-direction: column; gap: 5px; }
  .event-meta { flex-wrap: wrap; }
  .event-details { margin-right: 0; margin-left: 30px; }
  .counter-grid { grid-template-columns: 1fr 1fr; }
  .log-drawer > summary { padding: 14px 16px; }
  .log-tools, .log-list { padding-right: 16px; padding-left: 16px; }
  .log-row { grid-template-columns: 1fr auto; gap: 7px; padding: 11px 0; }
  .log-row > strong { text-align: right; }
  .log-row p { grid-column: 1 / -1; }
  .conflict-item form { flex-direction: column; }
  .footer { flex-direction: column; }
  .login-card { padding: 28px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-width: 700px) {
  .drawer-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 14px 16px; }
  .drawer-title { font-size: 16px; }
  .dashboard-drawer .drawer-counts { grid-column: 1; grid-row: 2; margin-left: 0; justify-content: flex-start; }
  .dashboard-drawer .drawer-chevron { grid-column: 2; grid-row: 1 / 3; }
  .drawer-body { padding: 14px 16px 16px; }
  .user-mapping-row { grid-template-columns: 1fr; gap: 10px; }
  .user-mapping-row > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
  .user-mapping-row small { margin-top: 0; }
}
