:root {
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-soft: #f8fafa;
  --border: #e2e8e8;
  --border-strong: #cdd7d7;
  --text: #1d2c2c;
  --muted: #6c7d7f;
  --sidebar: #10211f;
  --sidebar-text: #c5d3d2;
  --teal: #0f766e;
  --teal-dark: #0b5d56;
  --teal-soft: #e6f4f2;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --success: #067647;
  --success-soft: #ecfdf3;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 33, 31, 0.05), 0 4px 16px rgba(16, 33, 31, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--teal-dark); text-decoration: underline; }

h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--text); }
h1 { font-size: 26px; letter-spacing: -0.02em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.text-right { text-align: right; }
.link-strong { font-weight: 600; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 24px;
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--teal);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex: 0 0 auto;
}
.brand-text { font-size: 14px; }

.nav-label {
  margin: 14px 10px 6px;
  color: #6f8986;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(20, 184, 166, 0.16); color: #fff; }
.nav-icon { display: inline-flex; width: 18px; height: 18px; flex: 0 0 18px; }
.nav-icon svg { width: 18px; height: 18px; }
.sidebar-footer {
  margin-top: auto;
  padding: 14px 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #7e9694;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #2dd4bf; }
.sidebar-backdrop { display: none; }

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 66px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-context { display: flex; flex-direction: column; margin-right: auto; }
.topbar-context .eyebrow { margin: 0; }
.topbar-title { font-weight: 600; color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.user-chip { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--teal-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-meta strong { font-size: 13px; }
.user-meta small { color: var(--muted); font-size: 11px; }
.logout-form { margin: 0; }
.icon-button {
  display: none;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}
.icon-button svg { width: 22px; height: 22px; display: block; }

.workspace { padding: 28px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.page-header .muted { margin: 4px 0 0; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-soft); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-soft); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.btn-danger:hover { background: #fde8e6; color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards and panels */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { margin-bottom: 20px; }
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-header .muted { margin: 4px 0 0; }
.panel-body { padding: 16px 20px; }
.danger-zone .panel-header { border-bottom: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; color: var(--text); }
.stat-card:hover { border-color: var(--teal); text-decoration: none; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; }
.stat-foot { color: var(--teal); font-size: 12px; font-weight: 600; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; }
.content-grid-wide { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 20px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; background: var(--surface-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcfc; }

/* Status indicators */
.status {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--surface-soft);
  color: var(--muted);
  border: 1px solid var(--border);
}
.status-active, .status-completed { background: var(--success-soft); color: var(--success); border-color: #abefc6; }
.status-draft { background: var(--surface-soft); color: var(--muted); }
.status-on_hold { background: var(--warning-soft); color: var(--warning); border-color: #fedf89; }
.status-archived { background: #f2f4f4; color: var(--muted); }

/* Forms */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); align-items: center; }
.filter-bar .form-select { width: auto; min-width: 150px; }
.search-field { position: relative; flex: 1 1 280px; min-width: 220px; }
.search-field svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search-field input { padding-left: 36px; }

.form-control, .form-select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.form-control:focus, .form-select:focus, .search-field input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--teal);
}
.form-check-input { width: 16px; height: 16px; accent-color: var(--teal); }
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.form-field label { font-weight: 600; font-size: 13px; }
.form-field-full { grid-column: 1 / -1; }
.form-field-checkbox { flex-direction: row; align-items: center; gap: 9px; }
.form-field-checkbox label { margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; padding: 20px; }
.form-panel { max-width: 860px; }
.form-actions { display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); background: var(--surface-soft); }
.errorlist { list-style: none; margin: 0; padding: 0; color: var(--danger); font-size: 12px; }

.detail-list { margin: 0; padding: 6px 20px 18px; }
.detail-list > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-weight: 600; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }

.task-list { list-style: none; margin: 0; padding: 6px 20px 18px; }
.task-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.task-list li:last-child { border-bottom: 0; }
.task-list .muted, .task-list .status { font-size: 12px; }
.task-list small { grid-column: 1 / -1; }

/* Empty states and messages */
.empty-state { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-state-large { padding: 70px 20px; }
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 20px;
}
.empty-state h3 { margin-bottom: 6px; color: var(--text); }
.empty-state p { margin-bottom: 14px; }
.messages { margin-bottom: 18px; }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-soft); margin-bottom: 8px; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: #abefc6; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.alert-info { background: var(--teal-soft); color: var(--teal-dark); border-color: #b8e4df; }

.pagination { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.page-info { color: var(--muted); font-size: 12px; }

/* Pipeline catalog */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; padding: 20px; }
.module-card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 18px; box-shadow: none; }
.module-card h2 { margin-top: 4px; }
.module-card .muted { margin: 0; }
.module-head { display: flex; align-items: center; gap: 10px; }
.module-icon { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; background: var(--teal-soft); color: var(--teal); font-weight: 800; }
.module-category { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.module-id { color: var(--muted); font-size: 11px; background: var(--surface-soft); padding: 2px 6px; border-radius: 4px; }

/* Authentication */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, #f5f7f7 0%, #e8f2f0 100%); }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.auth-brand { margin-bottom: 22px; }
.auth-brand .brand-mark { margin-bottom: 16px; width: 40px; height: 40px; }
.auth-brand h1 { margin-bottom: 4px; }
.auth-brand .muted { margin: 0; }
.auth-footer { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

/* Responsive */
@media (max-width: 980px) {
  .content-grid, .content-grid-wide { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    z-index: 40;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(16, 33, 31, 0.45); z-index: 30; }
  .icon-button { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .workspace { padding: 20px 16px; }
  .page-header { flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .user-meta { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-list > div { grid-template-columns: 1fr; gap: 2px; }
}
