:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1c2733;
  --text-muted: #5c6b7a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --success: #15803d;
  --success-bg: #dcfce7;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
  line-height: 1.5;
}

.layout {
  max-width: 1000px;
  margin: 0 auto 0 240px;
  padding: 1.75rem 1.25rem 4rem;
}

/* sidebar navigation */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.9rem;
  overflow-y: auto;
}

.sidebar .brand {
  display: block;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  padding: 0.25rem 0.6rem 1rem;
}

.sidebar-nav a {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 0.15rem;
}

.sidebar-nav a:hover {
  background: var(--border);
  color: var(--text);
}

.sidebar-nav a.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-group {
  margin-top: 1.25rem;
}

.sidebar-group-title {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0 0.6rem 0.35rem;
}

.sidebar-group a {
  padding-left: 1.2rem;
}

/* typography */
h1 {
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 1.75rem;
  font-size: 0.95rem;
}

h2 {
  font-size: 1.1rem;
  margin: 2rem 0 0.75rem;
}

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.card p {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* forms */
form .field {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.hint {
  font-weight: 400;
  color: var(--text-muted);
}

input[type="text"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 5.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row.three {
  grid-template-columns: 1fr 1fr 1fr;
}

/* buttons */
.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-secondary:hover {
  background: var(--accent);
  color: #fff;
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

/* icon-only action buttons (table actions column) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
  vertical-align: middle;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn-danger {
  cursor: pointer;
}

.icon-btn-danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

.icon-btn-danger:disabled {
  opacity: 0.5;
  cursor: default;
}

.actions-cell {
  white-space: nowrap;
}

/* rendered list containers may hold wide tables */
[data-render="metainfo-list"] {
  overflow-x: auto;
}

.actions-cell > * {
  margin-right: 0.3rem;
}

/* tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.9rem;
}

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

th {
  background: var(--bg);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

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

/* misc */
code,
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.83em;
  background: var(--bg);
  padding: 0.1em 0.4em;
  border-radius: 5px;
}

.badge {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0 0.2rem 0.2rem 0;
}

/* chip editor */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  min-height: 2.9rem;
  padding: 0.55rem 0.7rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.35rem 0.25rem 0.75rem;
  font-size: 0.83rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.chip-new {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.chip-remove {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  border-radius: 50%;
}

.chip-remove:hover {
  background: rgba(0, 0, 0, 0.1);
}

.chip-add {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chip-add input,
.chip-add select {
  flex: 1;
  min-width: 8rem;
}

.chip-add select[multiple] {
  max-height: 5.2rem;
  padding: 0.3rem 0.4rem;
}

.chip-add + .hint {
  display: block;
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
}

.chip-add .btn {
  white-space: nowrap;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-inline input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.alert {
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
}

.empty {
  color: var(--text-muted);
  font-style: italic;
  padding: 1.5rem;
  text-align: center;
}

.htmx-indicator {
  display: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-left: 0.75rem;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline;
}

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