:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --primary: #111827;
  --focus: #1d4ed8;
  --ok: #166534;
  --ok-bg: #ecfdf3;
  --warn: #9a3412;
  --warn-bg: #fff7ed;
  --bad: #991b1b;
  --bad-bg: #fef2f2;
  --overlay: rgba(17, 24, 39, 0.45);
  --shadow: 0 12px 32px rgba(17, 24, 39, 0.12);
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --radius: 8px;
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "IBM Plex Sans", "Segoe UI", sans-serif;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

a { color: inherit; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; flex-direction: column; }
.brand strong { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.brand span { font-size: 12px; color: var(--muted); }

.header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.user { font-size: 13px; color: var(--muted); }

.wrap {
  width: min(1180px, calc(100% - 48px));
  margin: 24px auto 48px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.stat {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}
.stat:last-child { border-right: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat b { display: block; margin-top: 4px; font-size: 22px; font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--bad); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 16px 16px 12px;
}
.panel-head > div:first-child { min-width: 0; }

.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-head p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

.toolbar {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.toolbar .field.search,
.toolbar .select { width: 100%; min-width: 0; }
.toolbar .select-trigger,
.toolbar .field.search { height: 34px; }
.seg {
  display: inline-flex;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  white-space: nowrap;
}
.seg .btn {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  height: 34px;
  background: #fff;
}
.seg .btn:last-child { border-right: 0; }
.seg .btn.btn-primary { background: var(--primary); color: #fff; }
.seg .btn.btn-primary:hover { background: #030712; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; }
th {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
  background: #fafafa;
}
td { border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafafa; }

.code { font-weight: 600; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-neutral { background: #f3f4f6; color: #374151; }

.due-bad { color: var(--bad); }
.due-warn { color: var(--warn); }

.col-actions { text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; white-space: nowrap; }

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: transform 120ms var(--ease), background-color 120ms ease, border-color 120ms ease;
}
.btn:hover { background: #f9fafb; }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover { background: #030712; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { height: 28px; padding: 0 8px; font-size: 12px; }

.field, .select-trigger {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  outline: none;
}
textarea.field { height: auto; padding: 8px 10px; resize: vertical; }
.field:focus, .select-trigger:focus, .select-trigger[aria-expanded="true"] {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; letter-spacing: -0.02em; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.stack { display: grid; gap: 12px; }
.label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
.alert {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid #fecaca;
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 13px;
}
.flash {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid #bbf7d0;
  background: var(--ok-bg);
  color: var(--ok);
  border-radius: 6px;
}

.side { display: grid; gap: 16px; }
.list { padding: 4px 0 8px; }
.item { padding: 10px 16px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item-btn {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.item-btn:hover { background: #fafafa; }
.item-top { display: flex; justify-content: space-between; gap: 8px; }
.empty { padding: 24px 16px; color: var(--muted); font-size: 13px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
}
.overlay.open { display: flex; }
.modal {
  display: none;
  width: min(520px, 100%);
  max-height: min(88vh, 760px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  transform: scale(0.96);
  opacity: 0;
  transition: transform 200ms var(--ease), opacity 200ms var(--ease);
}
.overlay.open .modal.show {
  display: block;
  transform: scale(1);
  opacity: 1;
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  background: var(--surface);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.modal form { padding: 4px 18px 18px; }
.modal-body { padding: 4px 18px 12px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 18px 18px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.form-actions .left { margin-right: auto; }
.login-card .btn { width: 100%; }

.select { position: relative; }
.select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  cursor: pointer;
}
.select-trigger::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 1.5px solid #6b7280;
  border-bottom: 1.5px solid #6b7280;
  transform: rotate(45deg) translate(-2px, -2px);
  flex: 0 0 auto;
}
.select-placeholder { color: var(--muted); }

.select-menu {
  position: fixed;
  z-index: 80;
  min-width: 180px;
  max-height: 260px;
  overflow: auto;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform-origin: var(--origin, top center);
  transform: scale(0.96);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 160ms var(--ease), opacity 160ms var(--ease), visibility 160ms var(--ease);
}
.select-menu.open {
  transform: scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.select-search {
  width: calc(100% - 8px);
  height: 34px;
  margin: 4px 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  padding: 0 8px;
}
.select-option {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.select-option:hover { background: #eef0f3; }
.select-option[aria-selected="true"] { background: #f3f4f6; font-weight: 500; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 90;
  display: none;
  padding: 10px 14px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  transform: translateY(8px);
  opacity: 0;
  transition: transform 180ms var(--ease), opacity 180ms var(--ease);
}
.toast.show { display: block; transform: translateY(0); opacity: 1; }

.history-item { padding: 12px 0; border-top: 1px solid var(--line); }
.history-item:first-child { border-top: 0; padding-top: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (hover: none) and (pointer: coarse) {
  tbody tr:hover td { background: transparent; }
}

@media (max-width: 1100px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .seg { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 980px) {
  .layout, .stats, .grid-2 { grid-template-columns: 1fr; }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
  .wrap { width: calc(100% - 24px); }
  .app-header { padding: 10px 12px; flex-wrap: wrap; }
}
