:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1e2740;
  --border: #2a3450;
  --text: #e6ebf5;
  --muted: #8a95b0;
  --accent: #4f7cff;
  --accent-2: #7c5cff;
  --danger: #ff5c7a;
  --ok: #34d399;
  --warn: #fbbf24;
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #eef1f8;
  --border: #d8deeb;
  --text: #1a2233;
  --muted: #5b6478;
}

html[data-accent="purple"] { --accent: #8b5cf6; --accent-2: #d946ef; }
html[data-accent="green"] { --accent: #10b981; --accent-2: #22c55e; }
html[data-accent="orange"] { --accent: #f97316; --accent-2: #f59e0b; }
html[data-accent="rose"] { --accent: #f43f5e; --accent-2: #fb7185; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

.hidden { display: none !important; }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  width: 360px;
  max-width: 92vw;
  text-align: center;
}
.brand {
  font-size: 26px;
  margin: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.slogan { color: var(--muted); font-size: 13px; margin: 6px 0 20px; }
.login-form { text-align: left; }
.login-toolbar { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }

/* ---- App shell / navigation ---- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex: 0 0 auto;
  position: relative;
  z-index: 70;
}
.brand-wrap { display: flex; align-items: baseline; gap: 10px; }
.brand-wrap .brand { font-size: 18px; }

.nav-toggle {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.nav-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 1px; }
.nav-toggle:hover { background: var(--panel-2); }
.sidebar-collapse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.sidebar-collapse:hover { color: var(--text); background: var(--panel-2); }

.app-body { display: flex; flex: 1; min-height: 0; }

@media (min-width: 981px) {
  #app.sidebar-collapsed .sidebar {
    width: 64px;
    flex-basis: 64px;
    padding: 14px 8px;
  }
  #app.sidebar-collapsed .nav-group-toggle { display: none; }
  #app.sidebar-collapsed .nav-group {
    margin-bottom: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
  }
  #app.sidebar-collapsed .nav-group:first-child { border-top: 0; padding-top: 0; }
  #app.sidebar-collapsed .nav-group.collapsed .nav-group-items { display: flex; }
  #app.sidebar-collapsed .tab {
    justify-content: center;
    padding: 9px 0;
  }
  #app.sidebar-collapsed .nav-label { display: none; }
}

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  padding: 14px 10px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: thin;
}
.sidebar-head { display: none; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin-bottom: 14px; }
.nav-group:last-child { margin-bottom: 0; }
.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 10px 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.nav-group-toggle:hover { color: var(--text); }
.nav-chevron { font-size: 12px; line-height: 1; transition: transform 0.15s ease; }
.nav-group.collapsed .nav-chevron { transform: rotate(-90deg); }
.nav-group-items { display: flex; flex-direction: column; gap: 2px; }
.nav-group.collapsed .nav-group-items { display: none; }
.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active {
  color: var(--text);
  background: var(--panel-2);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-close {
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

.toolbar { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-menu-wrap { position: relative; }
.user-info {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.user-info:hover { color: var(--text); background: var(--panel-2); }
.user-info::after { content: "▾"; margin-left: 4px; }
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  display: flex;
  flex-direction: column;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 50;
}
.user-menu-item {
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.user-menu-item:hover { background: var(--panel-2); }
.user-menu-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 4px 6px;
}
.user-menu-label {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
  padding: 0 4px;
}
.company-select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 6px 8px;
  cursor: pointer;
}
.company-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.user-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* ---- Company management ---- */
.company-manage-list { margin-top: 10px; }
.company-row { align-items: flex-start; }
.company-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.company-name { font-weight: 600; }
.company-id { color: var(--muted); font-size: 12px; margin-top: 3px; overflow-wrap: anywhere; }
.company-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.company-hint { color: var(--muted); font-size: 12px; }
.company-confirm {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}
.company-confirm-actions { margin-top: 8px; }

/* ---- Notifications ---- */
.notif-wrap { position: relative; }
.notif-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.notif-btn:hover { color: var(--text); background: var(--panel-2); }
.notif-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.notif-icon { width: 18px; height: 18px; }
.notif-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  transform: translate(30%, -30%);
}
.notif-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 380px;
  max-width: calc(100vw - 24px);
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 60;
  overflow: hidden;
}
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.notif-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.notif-unread-label { color: var(--muted); font-size: 11px; font-weight: 500; }
.notif-head .btn:disabled { opacity: 0.45; cursor: default; }
.notif-list { min-height: 0; overflow-y: auto; }
.notif-item {
  display: flex;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--panel-2); }
.notif-item.unread { background: rgba(79, 124, 255, 0.08); }
.notif-dot {
  flex: none;
  width: 6px;
  height: 6px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.notif-dot.placeholder { visibility: hidden; }
.notif-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.notif-text { font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.notif-item.unread .notif-text { font-weight: 600; }
.notif-meta { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); font-size: 11px; }
.notif-chip {
  background: var(--panel-2);
  border-radius: 999px;
  padding: 1px 7px;
  overflow-wrap: anywhere;
}
.notif-error { color: var(--danger); font-size: 11px; overflow-wrap: anywhere; }
.notif-time { color: var(--muted); font-size: 11px; }
.notif-empty { color: var(--muted); text-align: center; padding: 26px 12px; font-size: 13px; }

.view { padding: 22px; max-width: 1100px; margin: 0 auto; width: 100%; flex: 1; overflow-y: auto; }

/* ---- Cards ---- */
.architecture-shortcut { box-shadow: inset 3px 0 0 var(--accent); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-title { font-size: 16px; font-weight: 600; }
.card-sub { color: var(--muted); font-size: 13px; }

/* ---- Overview dashboard ---- */
.overview-architecture {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
}
.overview-architecture .grow { min-width: 0; }
.overview-arch-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
.overview-arch-stats strong { color: var(--text); font-size: 14px; }
.overview-kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.overview-kpi {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.overview-kpi .num { font-size: 22px; font-weight: 700; line-height: 1.15; }
.overview-kpi .num .meta { font-size: 12px; font-weight: 400; }
.overview-kpi .lbl { margin-top: 3px; color: var(--muted); font-size: 12px; }
.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 1fr);
  gap: 14px;
  align-items: start;
}
.overview-main,
.overview-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.overview-main .card,
.overview-side .card { margin-bottom: 0; }
.overview-finance-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.overview-finance-row:last-child { border-bottom: 0; padding-bottom: 0; }
.overview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 16px;
}
@media (max-width: 1100px) {
  .overview-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .overview-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-architecture,
  .overview-footer { align-items: flex-start; flex-wrap: wrap; }
}

.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge.employee { background: rgba(79, 124, 255, 0.18); color: #8fb0ff; }
.badge.group { background: rgba(124, 92, 255, 0.18); color: #b39cff; }
.badge.external { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge.queued { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge.running { background: rgba(79, 124, 255, 0.15); color: #8fb0ff; }
.badge.completed { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge.failed { background: rgba(255, 92, 122, 0.15); color: var(--danger); }
.badge.pending_approval { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
.badge.paused { background: rgba(138, 149, 176, 0.18); color: var(--muted); }
.badge.cancelled { background: rgba(190, 80, 96, 0.16); color: #d98a96; }
.badge.muted { background: var(--panel-2); color: var(--muted); font-weight: 500; }

/* ---- API keys ---- */
#apiKeysCard .card-header { gap: 12px; }
#apiKeysCard .card-header .btn { flex: none; white-space: nowrap; }
.api-key-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.wrap-anywhere { overflow-wrap: anywhere; }
.api-key-head code.mono { color: var(--muted); }
.api-key-secret {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 6px;
  font-size: 13px;
}

/* ---- Backup & restore ---- */
.backup-warning {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  margin: 10px 0;
}
.backup-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 6px;
}
.backup-file-row:focus-within .btn { border-color: var(--accent); }
.backup-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}
.backup-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.backup-preview { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.backup-preview-head,
.backup-result-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.backup-error { color: var(--danger); font-size: 13px; margin-top: 10px; }
.backup-result { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.backup-meta { color: var(--muted); font-size: 12px; margin-top: 8px; overflow-wrap: anywhere; }
.backup-counts td:first-child { white-space: nowrap; }

/* ---- Webhooks ---- */
.webhook-row { align-items: flex-start; }
.webhook-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.webhook-name { font-weight: 600; }
.webhook-url { color: var(--muted); font-size: 12px; margin-top: 3px; overflow-wrap: anywhere; }
.webhook-events-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.webhook-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.webhook-form-events { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 12px; }
.webhook-check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; margin: 0; }
.webhook-check input { width: auto; margin: 0; padding: 0; flex: none; }
.webhook-hint { margin: -4px 0 10px; }
.webhook-warning {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  margin: 10px 0;
}
.webhook-secret-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.webhook-secret-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 6px;
  font-size: 13px;
}
.webhook-delivery-table td { white-space: nowrap; }
.webhook-delivery-error {
  max-width: 280px;
  white-space: normal !important;
  overflow-wrap: anywhere;
  color: var(--muted);
}

/* ---- Template gallery ---- */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.template-card { display: flex; flex-direction: column; gap: 8px; margin-bottom: 0; }
.template-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.template-card-head .card-title { font-size: 15px; }
.template-card .meta { color: var(--muted); font-size: 12px; }
.template-desc { color: var(--muted); font-size: 13px; line-height: 1.55; flex: 1; }
.template-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.template-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }

/* Task stats summary */
.stats-row { display: flex; gap: 28px; flex-wrap: wrap; }
.cost-periods { display: flex; gap: 6px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat .num { font-size: 22px; font-weight: 700; }
.stat .num.queued { color: var(--warn); }
.stat .num.running { color: #8fb0ff; }
.stat .num.completed { color: var(--ok); }
.stat .num.failed { color: var(--danger); }
.stat .num.pending_approval { color: #c4b5fd; }
.stat .num.paused { color: var(--muted); }
.stat .num.cancelled { color: #d98a96; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Task stepper (4-stage progress bar) */
.stepper { display: flex; align-items: center; flex-wrap: wrap; row-gap: 10px; }
.step { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 6px; border-radius: 8px; font: inherit; color: inherit; background: transparent; border: none; }
.step:hover { background: var(--panel-2); }
.step-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  flex: none;
}
.step-label { font-size: 13px; color: var(--muted); }
.step.active .step-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.active .step-label { color: var(--text); font-weight: 600; }
.step.done .step-dot { background: transparent; border-color: var(--ok); color: var(--ok); }
.step-line { flex: 1; min-width: 24px; height: 2px; background: var(--border); margin: 0 6px; }
.step-line.done { background: var(--ok); }

/* Prominent primary action (dashboard 「新建」) */
.btn.lg { padding: 12px 24px; font-size: 15px; font-weight: 600; }

/* Clickable task rows (open the stepper lifecycle view) */
.list-item.clickable { cursor: pointer; padding: 10px 8px; margin: 0 -8px; border-radius: 8px; }
.list-item.clickable:hover { background: var(--panel-2); }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; }
.list-item .meta, .tool-check .meta { color: var(--muted); font-size: 12px; }
.task-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.task-row { flex-wrap: wrap; row-gap: 8px; }

form label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
form input, form textarea, form select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
form textarea { min-height: 60px; resize: vertical; }

.row { display: flex; gap: 10px; align-items: flex-start; }
.row > * { flex: 1; }
.subrow {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--panel-2);
}
.section-label { font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: var(--muted); }

/* Workflow picker checkboxes (employee form) */
form label.tool-check { display: flex; align-items: center; gap: 8px; color: var(--text); margin: 6px 0; }
form input[type="checkbox"].tool-wf { width: auto; }

/* n8n editor embedded in the workflow form */
.n8n-frame {
  width: 100%;
  height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}

.result-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
  font-size: 13px;
  max-height: 400px;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: 640px;
  max-width: 92vw;
  max-height: 86vh;
  overflow: auto;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  z-index: 200;
}
.toast.hidden { display: none; }
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--danger); }

.empty { color: var(--muted); text-align: center; padding: 30px; font-size: 14px; }

/* ---- Org chart ---- */
.org-children { margin-left: 22px; padding-left: 14px; border-left: 1px solid var(--border); }

/* ---- Workforce / WBS / twin ---- */
.list-item.selected {
  background: var(--panel-2);
  box-shadow: inset 2px 0 0 var(--accent);
}
.wbs-row { align-items: flex-start; }
.comment-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  margin-top: 2px;
}

/* ---- Company foundation ---- */
.foundation-hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 100% 0, color-mix(in srgb, var(--accent) 16%, transparent), transparent 55%),
    var(--panel);
}
.foundation-hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.foundation-hero-name {
  margin: 4px 0 10px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.foundation-hero-meta,
.foundation-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.foundation-hero-score {
  min-width: 180px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
}
.foundation-score-num {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.foundation-score-label {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}
.foundation-meter {
  height: 6px;
  margin-top: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.foundation-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.foundation-hero-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.foundation-chip-row,
.foundation-context-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.foundation-chip-label {
  min-width: 64px;
  padding-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.foundation-chip {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.foundation-chip.principle {
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
  background: color-mix(in srgb, var(--ok) 10%, transparent);
}
.foundation-chip.risk {
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}
.foundation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.foundation-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 180px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
}
.foundation-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.foundation-dim {
  font-size: 14px;
  font-weight: 600;
}
.foundation-maturity {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.foundation-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
}
.foundation-dot.filled { background: var(--accent); }
.foundation-card .meta { color: var(--muted); font-size: 12px; }
.foundation-statement {
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.foundation-list-label {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.foundation-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.foundation-empty {
  padding: 10px 0 4px;
  border-top: 1px solid var(--border);
}
.foundation-form-group {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.foundation-form-group:first-of-type {
  padding-top: 0;
  border-top: 0;
}
.foundation-form-group .row { align-items: flex-start; }
.foundation-form-group .row > div { flex: 1; min-width: 0; }
.foundation-context {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.foundation-context-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.foundation-context-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.foundation-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.foundation-link:hover { color: var(--accent-2); }
.foundation-context-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}
.foundation-context-line { font-size: 12px; }
.foundation-context-hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}
.foundation-context-empty {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

/* ---- Responsive ---- */
@media (max-width: 980px) {
  .nav-toggle { display: inline-flex; }
  .sidebar-collapse { display: none; }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 90;
    width: min(84vw, 300px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.35);
    padding-top: 14px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  .view { padding: 16px 14px; }
  .card { padding: 14px; }
  .stats-row { gap: 18px; }
}

@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  .topbar { padding: 9px 12px; gap: 8px; }
  .brand-wrap .brand { font-size: 16px; }
  .toolbar { gap: 4px; }
  .toolbar .btn { padding: 6px 8px; font-size: 12px; }
  .notif-menu {
    position: fixed;
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    max-height: 70vh;
  }
  .view { padding: 12px 10px 24px; }
  .card { padding: 13px; border-radius: 10px; }
  .stats-row { gap: 14px 20px; }
  .stats-row .stat { min-width: 30%; }
  .money { white-space: normal; overflow-wrap: anywhere; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 7px 6px; }
  .data-table.responsive thead { display: none; }
  .data-table.responsive,
  .data-table.responsive tbody,
  .data-table.responsive tr,
  .data-table.responsive td { display: block; width: 100%; }
  .data-table.responsive tr { padding: 9px 0; border-bottom: 1px solid var(--border); }
  .data-table.responsive tr:last-child { border-bottom: none; }
  .data-table.responsive td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    border: none;
    padding: 3px 0;
    text-align: left;
    white-space: normal;
  }
  .data-table.responsive td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
  .data-table.responsive td:first-child { display: block; padding-bottom: 6px; }
  .data-table.responsive td:first-child::before { display: none; }
  .list-item { flex-wrap: wrap; row-gap: 8px; align-items: flex-start; }
  .task-actions { width: 100%; justify-content: flex-start; }
  .modal-box { width: 100%; max-width: 100%; max-height: 92vh; padding: 14px; border-radius: 12px; }
  .modal-actions { flex-wrap: wrap; }
  input, textarea, select,
  form input, form textarea, form select { font-size: 16px; }
  .btn.sm { padding: 6px 10px; }
  .stepper { row-gap: 6px; }
  .step { padding: 2px 4px; gap: 6px; }
  .step-label { font-size: 12px; }
  .step-line { min-width: 10px; margin: 0 2px; }
  .toast { left: 12px; right: 12px; bottom: 12px; text-align: center; }
  .org-children { margin-left: 10px; padding-left: 8px; }
  .foundation-hero-name { font-size: 22px; }
  .foundation-hero-score { width: 100%; }
  .foundation-grid { grid-template-columns: 1fr; }
  .foundation-chip-label { min-width: 100%; padding-top: 0; }
  .login-box { width: 100%; max-width: 92vw; padding: 18px; }
  img, svg { max-width: 100%; }
}
