:root {
  --primary: #621397;
  --primary-dark: #4D0F77;
  --on-dark: #CA98FD;
  --accent: #BC6F38;
  --accent-soft: #E0A877;
  --font: "Schibsted Grotesk";
  --ink: #1d1a22;
  --muted: #6b6574;
  --line: #e6e2ea;
  --soft: #f7f5f9;
  --white: #fff;
  --ok: #1f7a4d;
  --warn: #9a5b00;
  --bad: #b3261e;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font), system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--soft);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .75rem; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side {
  min-height: 100vh;
  background: var(--primary); color: var(--white); padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: .25rem;
  position: sticky; top: 0; height: 100vh;
}
.side .brand { font-weight: 700; font-size: 1.05rem; margin-bottom: 1rem; line-height: 1.3; }
.side .brand small { display: block; color: var(--on-dark); font-weight: 400; font-size: .8rem; }
.side a {
  color: var(--white); text-decoration: none; padding: .55rem .75rem; border-radius: 8px; display: flex; justify-content: space-between; align-items: center;
}
.side a:hover { background: var(--primary-dark); color: var(--white); }
.side a.active { background: var(--primary-dark); font-weight: 600; }
.side .spacer { flex: 1; }
.side .foot { font-size: .75rem; color: var(--on-dark); padding: .5rem .75rem; }
.badge { background: var(--accent); color: var(--white); border-radius: 999px; font-size: .75rem; padding: 0 .5rem; min-width: 1.4rem; text-align: center; }
.main { padding: 1.75rem 2rem 4rem; max-width: 1100px; width: 100%; }
.topline { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.topline h1 { margin: 0; }
.menu-toggle { display: none; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; display: none; }
  .side.open { display: flex; }
  .menu-toggle { display: inline-flex; margin: 1rem 1rem 0; }
  .main { padding: 1rem; }
}

/* ---------- Pieces ---------- */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card h2 { margin-bottom: .5rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; }
.stat .n { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat a { text-decoration: none; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack > * + * { margin-top: .75rem; }

button, .btn {
  font: inherit; border: 1px solid var(--primary); background: var(--primary); color: var(--white);
  padding: .55rem 1rem; border-radius: 8px; cursor: pointer; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: .4rem;
}
button:hover, .btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: var(--white); }
button.secondary, .btn.secondary { background: var(--white); color: var(--primary); }
button.secondary:hover, .btn.secondary:hover { background: var(--soft); color: var(--primary-dark); }
button.danger { background: var(--white); color: var(--bad); border-color: var(--bad); }
button.danger:hover { background: #fbeceb; }
button.small { padding: .3rem .65rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--white); color: var(--ink);
}
textarea { min-height: 110px; resize: vertical; }
input[type=color] { height: 44px; padding: 4px; cursor: pointer; }
@media (max-width: 640px) { .hide-sm { display: none; } }
.field { margin-bottom: .9rem; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
.check input { width: auto; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 640px) { .fields-2 { grid-template-columns: 1fr; } }

.msg { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.msg.error { background: #fbeceb; color: var(--bad); }
.msg.ok { background: #e8f5ee; color: var(--ok); }
.msg.info { background: #f3ebfa; color: var(--primary-dark); }

table { width: 100%; border-collapse: collapse; background: var(--white); }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--soft); }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; background: var(--white); }
.table-wrap table { border: 0; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

.pill { display: inline-block; border-radius: 999px; padding: .05rem .6rem; font-size: .8rem; font-weight: 600; background: var(--soft); border: 1px solid var(--line); white-space: nowrap; }
.pill.open, .pill.in_progress { background: #f3ebfa; color: var(--primary-dark); border-color: #e3d2f3; }
.pill.needs_approval, .pill.pending, .pill.waiting { background: #fdf1e6; color: var(--warn); border-color: #f4dcc4; }
.pill.blocked, .pill.rejected, .pill.urgent, .pill.disabled { background: #fbeceb; color: var(--bad); border-color: #f2d0cd; }
.pill.done, .pill.approved, .pill.active { background: #e8f5ee; color: var(--ok); border-color: #cfe9da; }
.pill.high { background: #fdf1e6; color: var(--warn); border-color: #f4dcc4; }

.comments .comment { border-left: 3px solid var(--line); padding: .25rem 0 .25rem .9rem; margin-bottom: 1rem; }
.comment .who { font-weight: 600; }
.pre { white-space: pre-wrap; }
.activity { font-size: .9rem; }
.activity li { margin-bottom: .35rem; }

.action { border: 1px solid var(--line); border-radius: 8px; padding: .75rem; margin-bottom: .6rem; }
.action .head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.action pre { background: var(--soft); padding: .6rem; border-radius: 6px; overflow-x: auto; margin: .5rem 0 0; font-size: .8rem; }

/* ---------- Sign-in screens ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--primary); padding: 1.5rem; }
.auth .panel { background: var(--white); border-radius: 14px; padding: 2rem; width: 100%; max-width: 440px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.auth .panel.wide { max-width: 560px; }
.auth .title { font-weight: 700; font-size: 1.35rem; margin-bottom: .25rem; }
.auth .tag { text-align: center; color: var(--on-dark); margin-top: 1.25rem; font-size: .85rem; }
.auth .or { text-align: center; color: var(--muted); margin: 1rem 0; font-size: .85rem; }
.provider { width: 100%; justify-content: center; margin-bottom: .5rem; }
.qr { display: flex; justify-content: center; margin: 1rem 0; }
.qr svg { width: 200px; height: 200px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; font-family: ui-monospace, Menlo, monospace; background: var(--soft); padding: 1rem; border-radius: 8px; margin: 1rem 0; }

.powered { color: var(--muted); font-size: .8rem; margin-top: 2rem; }
.pill.ok { background: #e8f5ee; color: var(--ok); border-color: #cfe9da; }
.pill.warn { background: #fdf1e6; color: var(--warn); border-color: #f4dcc4; }
.pill.bad { background: #fbeceb; color: var(--bad); border-color: #f2d0cd; }
.meter { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; margin: .25rem 0 1rem; }
.meter span { display: block; height: 100%; background: var(--primary); }
button.link { background: none; border: 0; padding: 0; color: var(--bad); text-decoration: underline; cursor: pointer; font: inherit; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.role-grid .card { margin: 0; }
.role ul, .card ul { padding-left: 1.2rem; margin: .5rem 0; }
pre.prompt { white-space: pre-wrap; font-size: .85rem; background: var(--soft); padding: 1rem; border-radius: 8px; max-height: 480px; overflow: auto; }
details summary { cursor: pointer; font-weight: 600; }
