/* ===========================================================================
   coforge admin — design system
   Modern, full-width layout. Token-driven colors, comfortably dense tables
   and controls, consistent radii and focus states.
   =========================================================================== */

:root {
  /* Palette */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8ef;
  --border-strong: #cbd2dd;
  --text: #17203a;
  --text-soft: #4b5568;
  --muted: #6b7486;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #eaf1fe;
  --danger: #dc2626;
  --danger-strong: #b91c1c;
  --danger-soft: #fdecec;
  --success: #16803c;
  --success-soft: #e7f6ed;
  --warning: #92610e;
  --warning-soft: #fdf3d8;
  --violet: #6d28d9;
  --violet-soft: #f1eafd;

  /* Sidebar */
  --sidebar-bg: #101625;
  --sidebar-text: #c6cddc;
  --sidebar-muted: #67718a;

  /* Shape & depth */
  --radius: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.07);
  --ring: 0 0 0 3px rgba(37, 99, 235, 0.16);

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(37, 99, 235, 0.18); }

/* ===== App shell — sidebar + content ===== */
.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 17px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-brand .brand-logo {
  height: 30px; width: auto; max-width: 100%; display: block;
  filter: invert(1) brightness(2);
}

.sidebar-nav { padding: 10px; flex: 1; overflow-y: auto; scrollbar-width: thin; }
.sidebar-nav .nav-section {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.9px;
  color: var(--sidebar-muted); padding: 14px 11px 5px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px; margin: 1px 0;
  color: var(--sidebar-text); border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500;
  transition: background-color 120ms, color 120ms;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.sidebar-nav a.active {
  background: linear-gradient(90deg, rgba(37,99,235,0.32), rgba(37,99,235,0.16));
  color: #fff;
  box-shadow: inset 2px 0 0 var(--primary);
}
.sidebar-nav .nav-icon {
  width: 19px; text-align: center; font-size: 14px; line-height: 1; opacity: 0.8;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-nav a:hover .nav-icon, .sidebar-nav a.active .nav-icon { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.07);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 9px;
}
.sidebar-footer .user-line {
  font-size: 12px; color: var(--sidebar-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-footer .signout {
  width: 100%; background: transparent; color: var(--sidebar-text); border-color: rgba(255,255,255,0.16);
}
.sidebar-footer .signout:hover { background: rgba(255,255,255,0.08); color: #fff; border-color: rgba(255,255,255,0.3); }

.content { display: flex; flex-direction: column; min-width: 0; }
.content-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
  padding: 13px 28px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  min-height: 56px;
}
.content-head .page-title { font-size: 16.5px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.content-actions { display: flex; gap: 8px; align-items: center; }

/* Full-width content on every page. */
.content-body { padding: 20px 28px 42px; width: 100%; max-width: none; }

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .content-head, .content-body { padding-left: 14px; padding-right: 14px; }
}

/* ===== General typography ===== */
h1 { font-size: 19px; margin: 0 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; margin: 18px 0 8px; letter-spacing: -0.01em; }

/* ===== Cards, tables, forms ===== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }

/* Horizontal-scroll wrapper for wide tables — the page never squeezes
   columns into illegibility; it scrolls the table instead. */
.table-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

table { border-collapse: collapse; width: 100%; }
table th, table td {
  text-align: left; padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13.5px;
}
table th {
  background: var(--surface-2); font-weight: 600; font-size: 11px;
  text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px;
  white-space: nowrap;
  padding-top: 9px; padding-bottom: 9px;
}
table thead th:first-child { border-top-left-radius: var(--radius-sm); }
table thead th:last-child { border-top-right-radius: var(--radius-sm); }
table tbody tr { transition: background-color 100ms; }
table tbody tr:hover { background: var(--surface-2); }
table tbody tr:last-child td { border-bottom: 0; }
table td.actions { text-align: right; white-space: nowrap; }
table td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer;
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--text); text-decoration: none;
  line-height: 1.35;
  transition: background-color 120ms, border-color 120ms, box-shadow 120ms, transform 60ms;
}
.btn:hover { background: var(--surface-2); border-color: #b6bfcc; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn.danger { background: transparent; border-color: #efb9b9; color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { background: transparent; border-color: var(--border-strong); color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }

form .row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
form .field { flex: 1 1 230px; min-width: 0; }
form .field.full { flex-basis: 100%; }
form label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; color: var(--text-soft); }
form input[type=text], form input[type=email], form input[type=password],
form input[type=number], form input[type=search], form select, form textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; background: var(--surface); color: var(--text);
  transition: border-color 120ms, box-shadow 120ms;
}
form input:hover, form select:hover, form textarea:hover { border-color: #aab4c3; }
form input:focus, form select:focus, form textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--ring);
}
form input[type=checkbox], form input[type=radio] { accent-color: var(--primary); width: 15px; height: 15px; }
form textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 130px; resize: vertical; }
form .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
form .submit-row { margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Inline filter form (used on logs) */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: end; gap: 12px;
  padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 14px;
}
.filter-bar .field { flex: 0 1 180px; margin: 0; }
.filter-bar .field.wide { flex-basis: 250px; }
.filter-bar .actions { display: flex; gap: 6px; }

/* ===== Flash, tags ===== */
.flash {
  padding: 10px 13px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13.5px;
  border: 1px solid transparent; border-left-width: 3px;
}
.flash.success { background: var(--success-soft); color: var(--success); border-color: #bfe5cd; border-left-color: var(--success); }
.flash.error   { background: var(--danger-soft); color: #8a2222; border-color: #f2c7c7; border-left-color: var(--danger); }

.tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
  background: #edf1f7; color: var(--text-soft); font-weight: 550;
}
.tag.green  { background: var(--success-soft); color: var(--success); }
.tag.red    { background: var(--danger-soft); color: #8a2222; }
.tag.blue   { background: var(--primary-soft); color: var(--primary-strong); }
.tag.gray   { background: #edf1f7; color: var(--muted); }
.tag.amber  { background: var(--warning-soft); color: var(--warning); }
.tag.violet { background: var(--violet-soft); color: var(--violet); }

/* Run status-reason callout (run detail banner) */
.callout {
  padding: 10px 13px; border-radius: var(--radius-sm); margin-bottom: 14px;
  font-size: 13px; border: 1px solid transparent;
}
.callout .callout-title { font-weight: 600; }
.callout .callout-text { margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.callout.amber  { background: var(--warning-soft); color: var(--warning); border-color: #f0dfae; }
.callout.violet { background: var(--violet-soft); color: var(--violet); border-color: #ddd0f5; }
.callout.gray   { background: #edf1f7; color: var(--text-soft); border-color: var(--border-strong); }

/* Short waiting-reason line under a subtask title */
.task-status-reason { font-size: 12px; margin-top: 2px; }

/* Status-specific colorization */
.tag-status { text-transform: capitalize; }
.tag-status.pending,
.tag-status.paused                 { background: var(--warning-soft); color: var(--warning); }
.tag-status.running,
.tag-status.in-progress            { background: var(--primary-soft); color: var(--primary-strong); }
.tag-status.completed              { background: var(--success-soft); color: var(--success); }
.tag-status.failed                 { background: var(--danger-soft); color: #8a2222; }
.tag-status.blocked,
.tag-status.awaiting-clarification,
.tag-status.awaiting-sibling,
.tag-status.awaiting-delegation    { background: var(--violet-soft); color: var(--violet); }
.tag-status.stopped                { background: #edf1f7; color: var(--muted); }

/* Log level pills */
.tag-level.info     { background: var(--primary-soft); color: var(--primary-strong); }
.tag-level.debug    { background: #edf1f7; color: var(--muted); }
.tag-level.warning  { background: var(--warning-soft); color: var(--warning); }
.tag-level.error    { background: var(--danger-soft); color: #8a2222; }

/* Stat cards on dashboard */
.stats {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  margin-bottom: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
}
.stat .label { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; }
.stat .value { font-size: 25px; font-weight: 700; margin-top: 5px; color: var(--text); letter-spacing: -0.02em; }

/* ===== Pagination ===== */
.pagination-wrap {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px; flex-wrap: wrap; gap: 10px;
  font-size: 13px; color: var(--muted);
}
.pagination {
  display: inline-flex; align-items: center; gap: 4px;
  list-style: none; margin: 0; padding: 0;
}
.pagination li a, .pagination li span {
  display: inline-block; padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-size: 13px; line-height: 1.3; min-width: 31px; text-align: center;
}
.pagination li.disabled span { color: #b5bac5; background: var(--surface-2); border-color: var(--border); }
.pagination li.active span { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination li a:hover { background: var(--surface-2); text-decoration: none; }

/* ===== Log row presentation ===== */
.log-row td .ctx-toggle {
  background: none; border: 0; color: var(--primary); cursor: pointer; font-size: 12px; padding: 0;
}
.log-row td .ctx-toggle:hover { text-decoration: underline; }
.log-row .ctx-pre {
  display: none;
  margin-top: 6px; background: #0f172a; color: #e2e8f0;
  padding: 11px 13px; border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow: auto;
}
.log-row .ctx-pre.show { display: block; }

/* Raw action code surfaced inline on the run page (which hides the Action
   column) so lifecycle rows like run.started / agent.executing stay
   identifiable, not just humanised. */
.log-row .log-action {
  display: inline-block; margin-bottom: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: #64748b;
  background: #f1f5f9; border-radius: 4px; padding: 1px 6px;
}
.log-row .log-action.level-error { color: #b91c1c; background: #fee2e2; }
.log-row .log-action.level-warning { color: #92400e; background: #fef3c7; }

/* Structured context: prompt / result / trace rendered as labelled blocks
   with real newlines instead of an escaped JSON dump. */
.log-row .ctx-pre.ctx-structured { white-space: normal; }
.log-row .ctx-section { margin-bottom: 11px; }
.log-row .ctx-section:last-child { margin-bottom: 0; }
.log-row .ctx-label {
  font-weight: 600; color: #93c5fd; margin-bottom: 4px;
  text-transform: capitalize; font-size: 11px; letter-spacing: 0.02em;
}
.log-row .ctx-body {
  margin: 0; background: transparent; color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; white-space: pre-wrap; word-break: break-word;
}

/* ===== Login screen ===== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #101625, #24365c);
}
.login-card {
  background: var(--surface); padding: 28px 32px; border-radius: 13px; width: 370px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
}
.login-card h1 { text-align: center; margin-bottom: 17px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 22px; }
.login-logo img { height: 32px; width: auto; max-width: 100%; display: block; }

/* Dashboard health cards */
.health-grid {
  display: grid; gap: 14px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}
.health-card .card-head h2 { font-size: 14.5px; }
table.kv { width: 100%; }
table.kv th { width: 155px; font-weight: 600; color: var(--text-soft); background: transparent; text-transform: none; letter-spacing: 0; padding-left: 0; }
table.kv td { padding-right: 0; }

/* Settings page — strict two-column layout: key on left, value on right */
.settings-grid { display: flex; flex-direction: column; }
.setting-row {
  display: grid; grid-template-columns: minmax(250px, 1fr) minmax(250px, 1fr);
  gap: 28px; align-items: start; padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; }
.setting-meta label { display: block; font-weight: 600; font-size: 13.5px; color: var(--text); margin-bottom: 3px; }
.setting-meta code { font-size: 12px; color: var(--text-soft); background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 5px; }
.setting-meta .help { font-size: 12px; margin-top: 5px; }
.setting-control { display: flex; flex-direction: column; align-items: stretch; }
.setting-control input[type=text],
.setting-control input[type=number] { width: 100%; }

.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 500; }
.toggle input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }

@media (max-width: 720px) {
  .setting-row { grid-template-columns: 1fr; }
  .setting-control { justify-content: flex-start; }
}

/* Misc helpers */
.muted { color: var(--muted); }
.hstack { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 13px 0; }
.empty { color: var(--muted); padding: 16px; text-align: center; }
