:root {
  --header-height: 56px;
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-primary-muted: #eff6ff;
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-muted-bg: #f3f4f6;
  --color-error-text: #991b1b;
  --color-error-bg: #fef2f2;
  --color-error-border: #fecaca;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.05);
  --shadow-lg: 0 12px 40px rgba(17, 24, 39, 0.1);
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-pill: 9999px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  padding: 0 1rem;
}

.site-header__inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-primary);
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 500;
}

.site-nav__icon {
  flex-shrink: 0;
  opacity: 0.92;
}

.site-nav a:hover {
  color: var(--color-text);
  background: var(--color-muted-bg);
}

.site-nav a[aria-current="page"] {
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: 0 0 0 1px var(--color-border);
}

.site-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.site-user__name {
  color: var(--color-text);
  font-weight: 600;
}

.site-user__role {
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.site-user__out {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--color-primary);
  text-decoration: none;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 0.8125rem;
}

.site-user__out-icon {
  opacity: 0.95;
}

.site-user__out:hover {
  background: var(--color-muted-bg);
}

.site-main {
  min-height: 100vh;
  padding-top: 0.75rem;
}

.site-main__inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.site-main h1 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: var(--color-bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
}

.login-card__title {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-text);
}

.login-card__hint {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  text-align: center;
}

.login-card__error {
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  font-size: 0.875rem;
  color: var(--color-error-text);
  background: var(--color-error-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-error-border);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.login-form__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-top: 0.35rem;
}

.login-form__label:first-of-type {
  margin-top: 0;
}

.login-form__input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}

.login-form__input:focus {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  outline-offset: 0;
  border-color: var(--color-primary);
}

.login-form__submit {
  margin-top: 1rem;
  padding: 0.65rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.login-form__submit:hover {
  background: var(--color-primary-hover);
}

.table-wrap {
  width: 100%;
  display: block;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-toolbar__title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.data-table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.data-table th {
  background: var(--color-bg);
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table__muted {
  color: var(--color-text-muted);
}

.data-table__actions {
  text-align: right;
  white-space: nowrap;
}

.data-table__actions .btn + .btn {
  margin-left: 0.35rem;
}

.data-table__protected {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table__cell-desc {
  max-width: none;
  word-break: break-word;
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 1rem 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  cursor: pointer;
  background: var(--color-muted-bg);
  color: var(--color-text);
}

.btn--primary,
.btn--primary:visited {
  color: #ffffff;
}

.btn--primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.btn--primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn--ghost {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

.btn--ghost:hover {
  background: var(--color-muted-bg);
  color: var(--color-text);
}

.btn--danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
}

.btn--danger:hover {
  background: #fee2e2;
}

.btn--small {
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-md);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: var(--radius-pill);
  background: var(--color-primary-muted);
  color: #1d4ed8;
}

/* Dashboard: one color per agent type */
.badge--agent-feed {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #7dd3fc;
}

.badge--agent-summary {
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #c4b5fd;
}

.badge--agent-video {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.data-table__id {
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  font-weight: 600;
  width: 3.5rem;
}

.flash {
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash--success {
  color: #166534;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.flash--error {
  color: var(--color-error-text);
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
}

.app-dialog {
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: min(720px, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem);
  box-shadow: var(--shadow-lg);
}

.app-dialog--narrow {
  width: min(440px, calc(100vw - 1.5rem));
}

.app-dialog::backdrop {
  background: rgba(17, 24, 39, 0.35);
}

.app-dialog form {
  padding: 1.5rem;
  margin: 0;
  background: var(--color-surface);
}

.app-dialog__title {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  font-weight: 700;
}

.app-dialog__text {
  margin: 0 0 1.25rem;
  color: var(--color-text-muted);
}

.app-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}

.form-field {
  margin-bottom: 0.85rem;
}

.form-field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
}

.form-field textarea {
  min-height: 5.5rem;
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  border-color: var(--color-primary);
}

.form-field__legend {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0.35rem;
}

.form-hint {
  margin: -0.25rem 0 0.75rem;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.form-hint--flush {
  margin-top: 0;
}

.form-optional {
  font-weight: 500;
  color: var(--color-text-muted);
}

.project-picker {
  max-height: 14rem;
  overflow-y: auto;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
}

.project-picker__row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.35rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.project-picker__row:hover {
  background: var(--color-surface);
}

.project-picker__row input {
  width: auto;
  margin: 0;
}

.project-picker__empty {
  margin: 0;
  padding: 0.5rem 0.35rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Full-page agent form (AI setup) */
.agent-form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem 1.5rem 1.75rem;
  max-width: 100%;
}

.agent-form__section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.agent-form__section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.agent-form__heading {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
}

.agent-form__intro {
  margin: -0.35rem 0 1rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.agent-form__textarea {
  min-height: 18rem;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  resize: vertical;
}

.agent-form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--color-border);
}

.usage-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.25rem;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.usage-filters .form-field {
  margin-bottom: 0;
}

.usage-filters__field {
  min-width: 10rem;
}

.usage-filters__actions {
  display: flex;
  align-items: flex-end;
  margin-bottom: 0;
}

.usage-summary {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  color: var(--color-text-muted);
}

.usage-summary strong {
  color: var(--color-text);
}

.usage-summary__range {
  color: var(--color-text-muted);
}

.usage-footer-note {
  margin: 0.75rem 0 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  max-width: 52rem;
  line-height: 1.45;
}

/* Cost page: single full-width chart (soft blue bars) */
.cost-chart-panel {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 1.25rem;
  padding: 1rem 1.1rem 1.15rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.cost-chart-panel__head {
  margin-bottom: 0.85rem;
}

.cost-chart-panel__title {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.cost-chart-panel__range {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.cost-chart-panel__empty {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.cost-metric-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  gap: 0.65rem;
  margin-top: 1.25rem;
}

.cost-metric-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  padding: 0.65rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.cost-metric-card__label {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  line-height: 1.25;
}

.cost-metric-card__value {
  font-size: 0.9375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
  word-break: break-word;
}

.cost-bar-chart--time {
  width: 100%;
  margin: 0;
  padding: 0 0 0.25rem;
}

.cost-bar-chart__time-list {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  width: 100%;
  min-height: 10rem;
  margin: 0;
  padding: 0.25rem 0 0;
  list-style: none;
}

.cost-bar-chart--full .cost-bar-chart__time-list {
  min-height: 10.5rem;
}

.cost-bar-chart__time-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
  gap: 0.35rem;
  flex: 1 1 0;
  min-width: 0;
  min-height: 11rem;
}

.cost-bar-chart__time-col {
  flex: 1 1 auto;
  width: 100%;
  min-height: 7.5rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: #eef1f4;
  border-radius: 6px 6px 3px 3px;
}

.cost-bar-chart__time-bar {
  width: min(78%, 2.75rem);
  max-width: 100%;
  min-height: 2px;
  border-radius: 5px 5px 0 0;
  background: #93c5fd;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.cost-bar-chart__time-tick {
  font-size: 0.6875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  text-align: center;
  line-height: 1.15;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Agents list: Run column before name */
.data-table__col-run,
.data-table__cell-run {
  width: 5.5rem;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table__cell-run .btn--run {
  margin: 0 auto;
}

.agent-list__name {
  font-weight: 600;
  color: var(--color-text);
}

.btn--run {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.55rem;
  background: var(--color-primary-muted);
  border-color: rgba(59, 130, 246, 0.35);
  color: var(--color-primary);
}

.btn--run:hover {
  background: #dbeafe;
  border-color: var(--color-primary);
  color: var(--color-primary-hover);
}

.btn--run__icon {
  flex-shrink: 0;
  display: block;
}
