:root {
  --charcoal: #222E38; --teal: #37A598; --teal-dark: #2b8a7f; --mint: #A7CECA; --mint-light: #D9E8E7; --gray: #525B66;
  --bg: #f4f7f7; --card: #ffffff; --text: #1d262e; --muted: #66707a; --line: #dfe6e6;
  --green: #2f9e6a; --amber: #c98a12; --red: #c8463d; --blue: #3b78c4;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,40,.06), 0 2px 8px rgba(20,30,40,.05);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161d23; --card: #1f2830; --text: #e6ecef; --muted: #9aa5ae; --line: #2f3b45; --mint-light: #24343a; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--teal); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); min-height: 1em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: var(--charcoal); color: #e8f1f0; padding: 12px 14px; border-radius: 8px; overflow: auto; font-size: 12.5px; }

/* layout */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--charcoal); color: #dfe8e7; padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: #c9d6d5; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.active { background: var(--teal); color: #fff; }
.signout { margin-top: auto; color: #c9d6d5 !important; border-color: rgba(255,255,255,.2) !important; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand small { display: block; color: var(--mint); font-size: 12px; }
.brand.big { font-size: 20px; color: var(--text); }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--charcoal) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 15l8-6 8 6v9H8z' fill='none' stroke='%2337A598' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E") center/26px no-repeat; border: 1px solid rgba(255,255,255,.15); flex: none; }
.main { padding: 26px 30px 60px; max-width: 1280px; width: 100%; min-width: 0; }
td.mono { white-space: nowrap; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* cards, grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .num { font-size: 26px; font-weight: 650; }
.tile .lbl { color: var(--muted); font-size: 12.5px; }
.tile.accent { border-left: 4px solid var(--teal); }
.tile.warn { border-left: 4px solid var(--amber); }

/* forms */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--teal) 45%, transparent); border-color: var(--teal); }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

/* tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: color-mix(in srgb, var(--mint-light) 45%, var(--card)); position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: color-mix(in srgb, var(--mint-light) 35%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--mint-light); display: block; }
.thumb.empty { display: grid; place-items: center; color: var(--muted); font-size: 10px; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--mint-light); color: var(--charcoal); }
.side .pill { background: var(--amber); color: #fff; }
.pill.create, .pill.applied, .pill.active, .pill.stored { background: #dcf1e6; color: #1e6d48; }
.pill.update, .pill.staged, .pill.pending { background: #fdf0d5; color: #8a5d06; }
.pill.discontinue, .pill.discontinued, .pill.error, .pill.failed, .pill.rejected, .pill.revoked { background: #f9dfdc; color: #9b2c24; }
.pill.unchanged, .pill.linked, .pill.superseded { background: #e7ecef; color: #4d5863; }
.change { font-size: 12.5px; }
.change .old { color: var(--red); text-decoration: line-through; }
.change .new { color: var(--green); font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { font: inherit; background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--teal); font-weight: 600; }

.steps { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.steps span { padding: 5px 12px; border-radius: 99px; background: var(--mint-light); color: var(--gray); font-weight: 600; font-size: 12.5px; }
.steps span.on { background: var(--teal); color: #fff; }
.drop { border: 2px dashed var(--mint); border-radius: var(--radius); padding: 28px; text-align: center; background: color-mix(in srgb, var(--mint-light) 35%, var(--card)); cursor: pointer; }
.drop.over { border-color: var(--teal); }
.sample { color: var(--muted); font-size: 12px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.gallery { display: flex; gap: 10px; flex-wrap: wrap; }
.gallery figure { margin: 0; width: 110px; }
.gallery img { width: 110px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--mint-light); }
.gallery figcaption { display: flex; justify-content: space-between; align-items: center; font-size: 11px; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15,22,28,.5); display: flex; justify-content: flex-end; z-index: 20; }
.modal-card { background: var(--bg); width: min(860px, 100%); height: 100%; overflow: auto; padding: 22px 24px 40px; box-shadow: -8px 0 30px rgba(0,0,0,.2); }
.modal.center { justify-content: center; align-items: center; }
.modal.center .modal-card { height: auto; max-height: 90vh; border-radius: 12px; width: min(560px, calc(100% - 32px)); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--charcoal); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 30; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.bad { background: var(--red); }
.secret { background: var(--mint-light); padding: 10px 12px; border-radius: 8px; word-break: break-all; font-family: ui-monospace, monospace; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--charcoal), #2c3c48); }
.login-card { background: var(--card); padding: 30px; border-radius: 14px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.empty-state { text-align: center; padding: 30px; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { min-width: 0; position: static; height: auto; flex-direction: column; gap: 10px; }
  .side nav { flex-direction: row; overflow-x: auto; }
  .side nav a { white-space: nowrap; }
  .signout { margin-top: 0; align-self: flex-start; }
  .main { padding: 18px 16px 50px; }
  .grid.two { grid-template-columns: 1fr; }
}
