: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;
}

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;
}

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

.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 {
  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);
}

.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;
}

.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;
}

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

.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;
  }
}
