:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-dark: #d1d5db;
  --soft: #f8fafc;
  --surface: #ffffff;
  --sidebar: #f3f4f6;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --teal-soft: #ccfbf1;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.055);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

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

.topbar {
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 270px minmax(280px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
}

.brand-area,
.top-actions,
.toolbar,
.tool-left,
.tool-right,
.scope-strip {
  display: flex;
  align-items: center;
}

.brand-area,
.top-actions,
.toolbar,
.tool-left,
.tool-right {
  gap: 9px;
}

.app-mark {
  width: 25px;
  height: 25px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
}

.app-title {
  display: grid;
  min-width: 0;
}

.app-title strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-title span {
  font-size: 11px;
  color: var(--muted);
}

.global-search {
  height: 34px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: #f9fafb;
  color: var(--ink);
  padding: 0 14px;
  width: min(520px, 100%);
}

.global-search::placeholder {
  color: #9ca3af;
}

.top-actions {
  justify-content: flex-end;
}

.top-actions select,
.lang-switch,
.ask-ai {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 10px;
  background: white;
  color: #0f172a;
  font-weight: 700;
}

.ask-ai {
  color: var(--brand-dark);
}

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

.main-sidebar {
  background: #f3f4f6;
  border-right: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-search,
.input,
.select {
  height: 34px;
  border: 1px solid var(--line-dark);
  background: #fff;
  border-radius: 5px;
  padding: 0 10px;
}

.side-search {
  background: #fff;
  margin-bottom: 12px;
  width: 100%;
}

.nav-group-label {
  font-size: 11px;
  color: #6b7280;
  text-transform: uppercase;
  font-weight: 800;
  margin: 10px 8px 6px;
}

.nav-button,
.worksheet-button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #16202b;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  text-align: left;
  font-weight: 700;
}

.nav-button:hover,
.worksheet-button:hover {
  background: #e5e7eb;
}

.nav-button.active,
.worksheet-button.active {
  background: #0f172a;
  color: white;
}

.worksheet-button.active {
  background: #0f766e;
}

.count-pill {
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.1);
  font-size: 11px;
  font-weight: 800;
}

.active .count-pill {
  background: rgba(255, 255, 255, 0.24);
}

.main-sidebar .scope-strip .badge {
  background: #ffffff;
  color: #334155;
  border: 1px solid #e5e7eb;
}

.worksheet-sidebar {
  background: #fbfbfc;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.worksheet-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.worksheet-head h2,
.title-block h1 {
  margin: 0;
}

.worksheet-head h2 {
  font-size: 16px;
}

.worksheet-head p,
.title-block p,
.helper {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.worksheet-list {
  padding: 10px;
  overflow: auto;
}

.content {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #fafafa;
}

.content-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.title-block {
  min-width: 0;
}

.title-block h1 {
  font-size: 20px;
}

.button {
  height: 34px;
  border: 1px solid #0f172a;
  border-radius: 5px;
  background: #111827;
  color: white;
  padding: 0 12px;
  font-weight: 800;
}

.button.secondary {
  background: var(--surface);
  color: #111827;
  border-color: var(--line);
  box-shadow: 0 1px 1px rgba(15, 23, 42, 0.03);
}

.button.blue {
  background: var(--brand);
  border-color: var(--brand);
}

.button.blue:hover,
.ask-ai:hover {
  background: #0d9488;
  border-color: #0d9488;
  color: white;
}

.button:hover {
  filter: brightness(0.98);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.view-tabs {
  display: flex;
  gap: 2px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.view-tab {
  border: 0;
  background: transparent;
  padding: 11px 14px;
  font-weight: 800;
  color: #334155;
  border-bottom: 3px solid transparent;
}

.view-tab.active {
  color: var(--brand-dark);
  border-color: var(--brand-dark);
}

.table-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.tool-left,
.tool-right,
.toolbar,
.scope-strip {
  flex-wrap: wrap;
}

.table-wrap {
  overflow: auto;
  height: calc(100vh - 203px);
  background: white;
}

table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  background: white;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 11px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 13px;
}

td {
  color: #1f2937;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fafb;
  color: #374151;
  font-weight: 850;
}

tbody tr:hover {
  background: #f9fafb;
}

tbody tr.selected-row {
  background: #ecfdf5;
}

.row-index {
  color: #94a3b8;
  width: 44px;
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  background: #e2e8f0;
  color: #334155;
  border: 1px solid rgba(15, 23, 42, 0.04);
}

.badge.blue {
  background: #eef2ff;
  color: #3730a3;
}

.badge.green {
  background: #dcfce7;
  color: #166534;
}

.badge.yellow {
  background: #fef3c7;
  color: #92400e;
}

.badge.red {
  background: #fee2e2;
  color: #991b1b;
}

.cell-token {
  display: inline-block;
  border-radius: 5px;
  background: #f3f4f6;
  padding: 3px 7px;
}

.page {
  padding: 18px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel,
.run-card,
.automation-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.run-list {
  display: grid;
  gap: 12px;
}

.run-card {
  padding: 14px;
}

.run-summary {
  display: grid;
  grid-template-columns: 32px 1fr auto auto auto auto;
  gap: 14px;
  align-items: center;
}

.expand {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-dark);
  border-radius: 5px;
  background: #fff;
}

.run-title {
  display: grid;
  gap: 3px;
}

.run-title strong {
  font-size: 16px;
}

.run-title span,
.run-stat span {
  color: var(--muted);
  font-size: 12px;
}

.run-stat {
  min-width: 120px;
  text-align: right;
}

.run-stat strong {
  display: block;
}

.employee-table {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 20;
  display: flex;
  justify-content: flex-end;
}

.modal-backdrop {
  justify-content: center;
  align-items: flex-start;
  padding-top: 44px;
}

.drawer,
.modal {
  background: var(--surface);
  box-shadow: -16px 0 34px rgba(15, 23, 42, 0.18);
}

.drawer {
  width: min(760px, 96vw);
  height: 100%;
  overflow: auto;
}

.modal {
  width: min(520px, 94vw);
  max-height: calc(100vh - 88px);
  overflow: auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.drawer-head,
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-body,
.modal-body {
  padding: 18px;
}

.close {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 5px;
}

.field.full {
  grid-column: 1 / -1;
}

.field span {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.textarea {
  border: 1px solid var(--line-dark);
  border-radius: 5px;
  background: white;
  color: var(--ink);
  min-height: 110px;
  padding: 10px;
  width: 100%;
  resize: vertical;
}

.info-box {
  border: 1px solid #99f6e4;
  background: #f0fdfa;
  color: #115e59;
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
}

.muted-box {
  background: #f1f5f9;
  color: #64748b;
  border-radius: 6px;
  padding: 11px;
  font-size: 12px;
}

.section-row {
  background: var(--teal-soft);
  color: #115e59;
  font-weight: 900;
}

.money {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.automation-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(460px, 1.2fr);
  gap: 14px;
}

.automation-card {
  padding: 14px;
  display: grid;
  gap: 10px;
  text-align: left;
}

.tree {
  display: grid;
  gap: 10px;
}

.tree-node {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  padding: 10px;
}

.tree-node strong {
  display: block;
  margin-bottom: 5px;
}

pre {
  white-space: pre-wrap;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
}

.scope-strip {
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

@media (max-width: 1100px) {
  .app {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    padding: 10px;
  }

  .shell {
    grid-template-columns: 1fr;
  }

  .main-sidebar,
  .worksheet-sidebar {
    display: block;
    border-right: 0;
  }

  .nav-button,
  .worksheet-button {
    display: inline-flex;
    width: auto;
    margin: 3px;
  }

  .worksheet-list {
    white-space: nowrap;
  }

  .table-wrap {
    height: auto;
    max-height: 65vh;
  }

  .grid.two,
  .grid.three,
  .automation-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .run-summary {
    grid-template-columns: 32px 1fr;
  }

  .run-stat {
    text-align: left;
  }
}
