:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --text: #18212b;
  --muted: #637083;
  --line: #dce2e8;
  --line-strong: #c8d0d8;
  --accent: #176b5b;
  --accent-dark: #105044;
  --accent-soft: #e6f3ef;
  --blue: #2563a7;
  --blue-soft: #eaf2fb;
  --amber: #94610c;
  --amber-soft: #fff5d9;
  --danger: #b33a3a;
  --danger-soft: #fcecec;
  --sidebar: #18232c;
  --shadow: 0 12px 32px rgba(27, 38, 48, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.2; }
h2 { font-size: 18px; line-height: 1.3; }

.eyebrow {
  margin-bottom: 5px;
  color: #7d8998;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.muted { color: var(--muted); }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #e9edf0;
}

.login-panel {
  width: min(420px, 100%);
  padding: 38px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel > .brand-mark { margin-bottom: 28px; }
.login-panel h1 { margin-bottom: 8px; font-size: 28px; }
.login-panel .stack-form { margin-top: 28px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  color: #dbe3e8;
  background: var(--sidebar);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand strong { display: block; color: #fff; font-size: 16px; }
.brand span { display: block; margin-top: 2px; color: #93a2ad; font-size: 12px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-size: 19px;
  font-weight: 800;
}

.main-nav { display: grid; gap: 4px; }
.nav-item {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  color: #aab7c0;
  background: transparent;
  text-align: left;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.nav-item.active { color: #fff; background: #263640; }
.nav-symbol { width: 18px; color: #8fc7ba; font-size: 18px; text-align: center; }

.sidebar-footer { margin-top: auto; display: grid; gap: 10px; padding: 16px 12px 0; border-top: 1px solid #31404a; }
.sidebar-footer a, .link-button { padding: 0; border: 0; color: #95a4ae; background: none; font-size: 12px; text-align: left; text-decoration: none; }
.sidebar-footer a:hover, .link-button:hover { color: #fff; }

.workspace { min-width: 0; }
.topbar {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.live-dot { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.live-dot i { width: 7px; height: 7px; border-radius: 50%; background: #2d9a6c; box-shadow: 0 0 0 3px #dff3e9; }

.content { padding: 28px 32px 48px; }
.view { display: none; }
.view.active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.metric {
  min-height: 118px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.metric-label { color: var(--muted); font-size: 12px; }
.metric-value { display: block; margin-top: 12px; font-size: 30px; line-height: 1; }
.metric-note { display: block; margin-top: 11px; color: #7b8795; font-size: 11px; }

.section-block, .tool-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.section-block.flush { min-width: 0; }
.section-heading {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.section-heading p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.section-heading.compact { min-height: 66px; }
.page-action-row { margin-bottom: 16px; padding: 0; border: 0; }
.page-action-row h2 { font-size: 22px; }

.split-layout { display: grid; grid-template-columns: minmax(270px, 0.7fr) minmax(520px, 1.5fr); gap: 18px; align-items: start; }
.tool-panel .stack-form { padding: 20px; }

.table-wrap { min-width: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { min-height: 48px; padding: 13px 16px; border-bottom: 1px solid #e8ecef; text-align: left; vertical-align: middle; }
th { color: #6f7b88; background: var(--surface-muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
td { color: #303b46; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.truncate-id { display: inline-block; max-width: 160px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; white-space: nowrap; }
.empty-state { padding: 54px 20px; color: var(--muted); text-align: center; }

.badge { display: inline-flex; min-height: 23px; align-items: center; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.success { color: var(--accent-dark); background: var(--accent-soft); }
.badge.info { color: #205b91; background: var(--blue-soft); }
.badge.warning { color: var(--amber); background: var(--amber-soft); }
.badge.danger { color: var(--danger); background: var(--danger-soft); }
.badge.neutral { color: #56616e; background: #edf0f3; }

.row-actions { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 650;
}
.button.primary { color: #fff; background: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { color: #33404b; border-color: var(--line-strong); background: var(--surface); }
.button.secondary:hover { background: #f2f5f6; }
.button.danger { color: var(--danger); border-color: #edcaca; background: #fff; }
.button.small { min-height: 30px; padding: 5px 9px; font-size: 11px; }
.button.full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: 0.55; }

.stack-form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #44515e; font-size: 12px; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: 0;
  color: var(--text);
  background: #fff;
}
input, select { min-height: 40px; padding: 8px 10px; }
textarea { resize: vertical; padding: 10px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.11); }
.form-error { min-height: 18px; color: var(--danger); font-size: 12px; }
.field-hint { color: var(--muted); font-size: 11px; font-weight: 500; }

.priority-stepper {
  width: 116px;
  height: 32px;
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
}
.stepper-button {
  border: 0;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.stepper-button:hover { color: #fff; background: var(--accent); }
.stepper-button:disabled { cursor: wait; opacity: 0.55; }
.priority-value {
  display: grid;
  place-items: center;
  min-width: 48px;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.import-results { display: grid; gap: 6px; padding: 0 20px 20px; }
.import-result { display: flex; justify-content: space-between; gap: 12px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 4px; font-size: 12px; }

.dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(15, 24, 31, 0.48); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { font-size: 20px; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 4px; color: #5f6c79; background: #f0f3f5; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-height: calc(100vh - 220px); padding: 22px; overflow-y: auto; }
.form-grid .wide { grid-column: 1 / -1; }
.toggle-row { display: flex; align-items: center; gap: 9px; }
.toggle-row input { width: 17px; min-height: 17px; margin: 0; accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); }

.toast-region {
  position: fixed;
  z-index: 30;
  top: 18px;
  left: 50%;
  width: min(440px, calc(100vw - 28px));
  display: grid;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  position: relative;
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 12px 42px 12px 14px;
  border: 1px solid #bcd8d0;
  border-radius: 5px;
  color: #164f43;
  background: #edf8f5;
  box-shadow: var(--shadow);
  animation: toast-in 160ms ease-out;
  pointer-events: auto;
}
.toast.error { border-color: #ecc4c4; color: #8e2f2f; background: #fff2f2; }
.toast-message { line-height: 1.45; overflow-wrap: anywhere; }
.toast-close {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  color: currentColor;
  background: transparent;
  font-size: 20px;
  line-height: 1;
}
.toast-close:hover { background: rgba(0, 0, 0, 0.07); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-shell { display: block; padding-bottom: 62px; }
  .sidebar { position: fixed; z-index: 10; top: auto; bottom: 0; width: 100%; height: 62px; padding: 6px 8px; }
  .brand, .sidebar-footer { display: none; }
  .main-nav { height: 100%; grid-template-columns: repeat(4, 1fr); gap: 3px; }
  .nav-item { height: 50px; flex-direction: column; justify-content: center; gap: 1px; padding: 3px; font-size: 10px; text-align: center; }
  .nav-symbol { height: 22px; font-size: 17px; }
  .topbar { min-height: 72px; padding: 14px 16px; }
  .topbar h1 { font-size: 20px; }
  .live-dot { display: none; }
  .content { padding: 20px 14px 36px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric { min-height: 102px; padding: 15px; }
  .metric-value { font-size: 25px; }
  .section-heading { align-items: flex-start; }
  .page-action-row { align-items: center; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .toast-region { top: 10px; width: calc(100vw - 20px); }
}
