:root {
  --bg: #f6f7f9;
  --fg: #1c1f24;
  --muted: #6b7280;
  --card: #fff;
  --border: #e5e7eb;
  --accent: #1f5fff;
  --danger: #c1272d;
  --ok: #137333;
}
* { box-sizing: border-box; }
body {
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  margin: 0; background: var(--bg); color: var(--fg);
}
header {
  display: flex; align-items: center; gap: 1rem;
  padding: .8rem 1.2rem; background: #fff; border-bottom: 1px solid var(--border);
}
header .brand {
  font-weight: 600; text-decoration: none; color: var(--fg);
  display: inline-flex; align-items: center;
  gap: calc(.5rem + .5cm);
}
header .brand-logo { height: 40px; width: auto; display: block; }
header nav { margin-left: auto; display: flex; gap: 1rem; align-items: center; }
header nav a { color: var(--accent); text-decoration: none; }
header .who { color: var(--muted); font-size: .9rem; }
main { max-width: 1000px; margin: 1.5rem auto; padding: 0 1rem; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 1.2rem 1.4rem; margin-bottom: 1rem;
}
.card.narrow { max-width: 360px; margin-left: auto; margin-right: auto; }
h1 { margin-top: 0; }
form label { display: block; margin: .6rem 0; }
form input, form select {
  display: block; width: 100%; padding: .45rem .6rem;
  border: 1px solid var(--border); border-radius: 6px; font: inherit;
}
form.inline { display: inline-block; margin: 0; }
form.inline input { width: auto; display: inline-block; }
button {
  padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; cursor: pointer;
}
button.danger { background: var(--danger); border-color: var(--danger); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: #fafbfc; font-weight: 600; font-size: .9rem; }
tr[data-row] { cursor: pointer; outline: none; }
tr[data-row].selected,
tr[data-row].selected td { background: #fff59d; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.row-between h1 { margin: 0; }
.view-links { display: flex; gap: .35rem; }
.view-links a {
  padding: .25rem .65rem; border: 1px solid var(--border); border-radius: 6px;
  text-decoration: none; color: var(--muted); font-size: .9rem;
}
.view-links a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Compact "grid" variant — same font size, much tighter rows. */
table.grid th, table.grid td { padding: 2px 6px; line-height: 1.2; vertical-align: middle; }
table.grid input, table.grid select {
  padding: 1px 4px; line-height: 1.2; border-radius: 3px; height: 22px;
}
table.grid button { padding: 1px 8px; line-height: 1.2; height: 22px; border-radius: 3px; }
table.grid form.inline {
  display: flex; align-items: center; gap: 4px; line-height: 1; margin: 0;
}
table.grid form.inline input { flex: 1; min-width: 6rem; width: auto; }
table.grid td:first-child { color: var(--muted); width: 1%; white-space: nowrap; }
table.grid td:nth-child(3) { width: 1%; white-space: nowrap; color: var(--muted); font-size: .85rem; }
table.grid td:last-child { width: 1%; white-space: nowrap; }

/* Excel-like "table" view. */
.xl-wrap { overflow: auto; border: 1px solid #b7b7b7; }
table.xl {
  border-collapse: collapse;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .9rem;
  background: #fff;
  table-layout: fixed;
  width: 100%;
}
table.xl th, table.xl td {
  border: 1px solid #d0d7de;
  padding: 0 6px;
  height: 20px;
  line-height: 1.1;
  vertical-align: middle;
  text-align: left;
  background: #fff;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.xl thead th {
  background: #f4f5f7;
  color: var(--muted);
  font-weight: 600;
  font-size: .75rem;
  text-align: center;
  position: sticky; top: 0; z-index: 1;
  height: 18px;
}
table.xl .xl-rownum {
  background: #f4f5f7;
  color: var(--muted);
  font-weight: 500;
  font-size: .75rem;
  text-align: center;
  width: 28px;
}
table.xl .xl-corner { width: 28px; background: #ebecef; }
table.xl thead th:nth-child(2),
table.xl tbody td:nth-child(2) { width: 1.5cm; text-align: right; }
table.xl td.readonly { color: var(--muted); }
table.xl td[data-edit] { cursor: cell; }
table.xl tr.xl-row-selected td { background: #fff59d; }
table.xl td.xl-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  position: relative;
  z-index: 2;
}
table.xl td.xl-error { background: #fce8e6; }
table.xl input.xl-input {
  width: 100%; height: 100%;
  border: none; outline: none; background: transparent;
  font: inherit; padding: 0; margin: 0;
}
table.xl:focus { outline: none; }
.pw { font-family: ui-monospace, Menlo, monospace; padding: .15rem .35rem; background: #f1f3f5; border-radius: 4px; }
.pw-form input { padding: .25rem .4rem; }
.flashes { list-style: none; padding: 0; margin: 0 0 1rem; }
.flash { padding: .55rem .8rem; border-radius: 6px; margin-bottom: .4rem; }
.flash.ok    { background: #e6f4ea; color: var(--ok); }
.flash.error { background: #fce8e6; color: var(--danger); }
code { background: #f1f3f5; padding: .1rem .3rem; border-radius: 4px; }
