:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --line: #d9dee5;
  --text: #1d232b;
  --muted: #667085;
  --accent: #246b58;
  --accent-dark: #174f41;
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #1f7a4d;
  --info: #235ea9;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: var(--info);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-weight: 700;
  font-size: 20px;
  margin: 0 0 20px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  color: var(--text);
  display: block;
  padding: 9px 10px;
  border-radius: 6px;
}

.nav a.active,
.nav a:hover {
  background: #eaf3ef;
  color: var(--accent-dark);
  text-decoration: none;
}

.main {
  min-width: 0;
  padding: 24px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.2;
}

.page-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px 32px;
  background: rgba(15, 23, 42, 0.58);
}

.modal {
  width: min(820px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.22);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
}

.modal-head p {
  margin: 5px 0 0;
}

.modal-close {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 10px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 14px;
  margin-bottom: 0;
}

.modal .proposal-body {
  min-height: 260px;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar-between {
  justify-content: space-between;
}

.template-search-row {
  align-items: stretch;
}

.template-search-input {
  flex: 1 1 240px;
  min-width: 0;
  width: auto;
}

.template-search-button {
  flex: 0 0 auto;
}

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

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  font-weight: 700;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  color: var(--text);
  background: #fff;
}

textarea {
  min-height: 180px;
  resize: vertical;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(180px, 260px) auto;
  gap: 10px;
  align-items: end;
}

button,
.button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
}

button:hover,
.button:hover {
  border-color: #aab4c0;
  text-decoration: none;
}

button.primary,
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover,
.button.primary:hover {
  background: var(--accent-dark);
}

button.danger {
  color: var(--danger);
  border-color: #e7b8b3;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.notice {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  margin-bottom: 14px;
  background: #fff;
}

.notice[hidden] {
  display: none;
}

.notice.error {
  color: var(--danger);
  border-color: #e7b8b3;
  background: #fff4f2;
}

.notice.ok {
  color: var(--ok);
  border-color: #b8dcc8;
  background: #f1fbf5;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f9fafb;
}

td {
  word-break: break-word;
}

tr:last-child td {
  border-bottom: 0;
}

.check-cell {
  width: 42px;
}

.actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.actions button,
.actions .button {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2f6;
  color: #344054;
  white-space: nowrap;
}

.badge.parsed,
.badge.generated,
.badge.edited,
.badge.success {
  background: #e9f7ef;
  color: var(--ok);
}

.badge.error,
.badge.deleted {
  background: #fff4f2;
  color: var(--danger);
}

.badge.not_clinic,
.badge.archived {
  background: #f1f3f5;
  color: #667085;
}

.badge.parsing {
  background: #fff8e7;
  color: var(--warning);
}

.badge.openai {
  background: #eef5ff;
  color: var(--info);
}

.badge.server {
  background: #eef2f6;
  color: #344054;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  background: #eef5ff;
  color: #1f4e79;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 16px;
}

.definition {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 8px 14px;
}

.definition dt {
  color: var(--muted);
}

.definition dd {
  margin: 0;
  min-width: 0;
}

.empty {
  color: var(--muted);
  padding: 14px;
}

.small-text {
  font-size: 12px;
}

.pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  max-height: 420px;
  overflow: auto;
}

.log-list {
  display: grid;
  gap: 10px;
}

.log-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.log-summary-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #f9fafb;
}

.log-summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.log-summary-item strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}

.log-filter-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 12px;
}

.log-table {
  min-width: 1180px;
}

.log-target {
  font-weight: 600;
}

.log-modal {
  width: min(980px, 100%);
}

.muted {
  color: var(--muted);
}

.progress-slot {
  margin-bottom: 16px;
}

.progress-slot[hidden] {
  display: none;
}

.progress-card {
  border: 1px solid #cfe0d6;
  border-radius: 14px;
  padding: 16px 18px;
  background:
    radial-gradient(circle at top right, rgba(36, 107, 88, 0.08), transparent 34%),
    linear-gradient(135deg, #f9fcfa 0%, #eef7f2 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.progress-card.idle {
  border-style: dashed;
}

.progress-card.completed {
  border-color: #b8dcc8;
}

.progress-card.failed {
  border-color: #e7b8b3;
  background:
    radial-gradient(circle at top right, rgba(180, 35, 24, 0.06), transparent 34%),
    linear-gradient(135deg, #fff9f8 0%, #fff1ef 100%);
}

.progress-card.failed .progress-fill {
  background: linear-gradient(90deg, #b42318, #e26b5d, #b42318);
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.progress-kicker {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.progress-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.progress-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.progress-meta {
  text-align: right;
  min-width: 92px;
}

.progress-percent {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-dark);
  line-height: 1;
}

.progress-count {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  margin-top: 12px;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(23, 79, 65, 0.12);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #4da987, var(--accent));
  background-size: 200% 100%;
  transition: width 220ms ease;
}

.progress-card.running .progress-fill {
  animation: progress-shift 1.4s linear infinite;
}

.progress-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.progress-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.progress-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(23, 79, 65, 0.12);
  color: var(--text);
  font-size: 13px;
}

.progress-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.progress-item {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(23, 79, 65, 0.08);
  border-radius: 10px;
  padding: 8px 10px;
}

.progress-item.error {
  border-color: rgba(180, 35, 24, 0.18);
  background: #fff6f4;
}

.progress-item small {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
}

.progress-empty {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  color: var(--muted);
  background: #fff;
}

@keyframes progress-shift {
  from {
    background-position: 200% 50%;
  }

  to {
    background-position: -200% 50%;
  }
}

.compact-textarea {
  min-height: 120px;
}

.proposal-body {
  min-height: 420px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .main {
    padding: 16px;
  }

  .field-row,
  .split,
  .definition {
    grid-template-columns: 1fr;
  }
}
