:root {
  --ink: #14212b;
  --ink-2: #4a5a66;
  --ink-3: #7b8a95;
  --line: #dde3e8;
  --bg: #f3f5f7;
  --card: #ffffff;
  --brand: #123c5a;
  --brand-2: #1d5f8a;
  --accent: #e8a33d;
  --ok: #2e7d4f;
  --warn: #c76a12;
  --crit: #b42318;
  --radius: 10px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.4rem; font-weight: 600; margin: .25rem 0 .75rem; line-height: 1.25; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 .75rem; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--ink-3); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand {
  display: flex; align-items: center; gap: .5rem;
  background: none; border: 0; color: inherit; cursor: pointer;
  font-weight: 600; font-size: 1.05rem; padding: 0;
}
.brand.big { font-size: 1.6rem; color: var(--brand); justify-content: center; }
.mark {
  display: inline-grid; place-items: center;
  width: 1.9em; height: 1.9em; border-radius: 6px;
  background: var(--accent); color: var(--brand);
  font-family: var(--mono); font-size: .8em; letter-spacing: -.02em;
}
.who { margin-left: auto; text-align: right; line-height: 1.2; min-width: 0; }
.who-name { display: block; font-weight: 500; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-role { display: block; font-size: .75rem; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem;
  border-radius: 8px; border: 1px solid transparent;
  font-weight: 500; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-2); }
.btn-ghost { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { border-color: var(--brand-2); }
.btn-danger { background: var(--crit); color: #fff; }
.btn-small { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; background: rgba(255,255,255,.12); color: #fff; }
.wide { width: 100%; }
.back { background: none; border: 0; color: var(--brand-2); padding: .25rem 0; cursor: pointer; font-weight: 500; }

/* ---------- Layout ---------- */
.page { max-width: 920px; margin: 0 auto; padding: 1rem 1rem 5rem; }
.page.narrow { max-width: 640px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, var(--brand) 0 38%, var(--bg) 38%); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 14px; padding: 2rem 1.5rem; box-shadow: 0 10px 30px rgba(18, 60, 90, .15); text-align: center; }
.login-card form { text-align: left; margin-top: 1.25rem; display: grid; gap: 1rem; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 1rem; }
label, .field { display: grid; gap: .35rem; font-weight: 500; font-size: .92rem; }
.field-label { font-weight: 500; font-size: .92rem; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: .6rem .75rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; font-weight: 400;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- Stats + tabs ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .7rem; }
.stat b { display: block; font-size: 1.45rem; font-family: var(--mono); line-height: 1.1; }
.stat span { font-size: .75rem; color: var(--ink-2); }
.stat.alert { border-color: var(--crit); }
.stat.alert b { color: var(--crit); }
.actions-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.actions-row .btn-primary { flex: 1 1 auto; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: .6rem .8rem; cursor: pointer; color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.count { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 99px; background: var(--line); font-size: .75rem; text-align: center; }

/* ---------- Task cards ---------- */
.task-list { display: grid; gap: .5rem; }
.task-card {
  display: grid; gap: .4rem; width: 100%; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: var(--radius); padding: .75rem .85rem;
}
.task-card:hover { border-color: var(--brand-2); }
.task-card.prio-urgent { border-left-color: var(--warn); }
.task-card.prio-gmp_critical { border-left-color: var(--crit); }
.task-top { display: flex; justify-content: space-between; gap: .5rem; align-items: start; }
.task-title { font-weight: 600; }
.task-meta, .task-foot { display: flex; flex-wrap: wrap; gap: .35rem .6rem; align-items: center; font-size: .85rem; color: var(--ink-2); }
.task-foot { justify-content: space-between; }
.empty { color: var(--ink-3); text-align: center; padding: 2rem 0; }
.overdue { color: var(--crit); font-weight: 600; }
.code { font-family: var(--mono); font-size: .8rem; background: #eef2f5; padding: .05rem .35rem; border-radius: 4px; color: var(--ink); }
.tag { font-size: .75rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 .35rem; }

/* ---------- Pills ---------- */
.pill { display: inline-block; font-size: .75rem; font-weight: 500; padding: .12rem .5rem; border-radius: 99px; background: #eef2f5; color: var(--ink-2); white-space: nowrap; }
.st-new { background: #e7eef7; color: #1d4f86; }
.st-assigned { background: #ece9f7; color: #4b3a99; }
.st-accepted, .st-in_progress { background: #fdf1de; color: #8a4f06; }
.st-waiting_parts { background: #fbe7dc; color: #9a3b0c; }
.st-fixed { background: #e3f3ea; color: var(--ok); }
.st-closed { background: #eceff1; color: var(--ink-3); }
.pr-low { background: #eef2f5; }
.pr-urgent { background: #fdebd6; color: var(--warn); }
.pr-gmp_critical { background: var(--crit); color: #fff; }

/* ---------- Task detail ---------- */
.detail-head { margin: .5rem 0 1rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .5rem 1rem; margin: 0 0 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; }
.facts dt { font-size: .75rem; color: var(--ink-3); }
.facts dd { margin: 0; }
.description { white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; margin: 0 0 1rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.gallery figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.gallery img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.gallery audio { width: 100%; margin: .6rem 0 0; }
.gallery figcaption { font-size: .75rem; color: var(--ink-3); padding: .25rem .5rem; }
.action-panel { display: grid; gap: .85rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; margin-bottom: 1rem; }
.action { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: end; }
.action-buttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.sub-form { display: grid; gap: .75rem; border-top: 1px dashed var(--line); padding-top: .85rem; }
.confirm-box { background: #f0f8f3; border: 1px solid #bfe0cb; border-radius: 8px; padding: .85rem; display: grid; gap: .6rem; }
.confirm-box p { margin: 0; }
.note-box { background: #fff8ec; border: 1px solid #f1d6a8; border-radius: 8px; padding: .7rem .85rem; font-size: .9rem; }

/* ---------- Timeline ---------- */
.timeline ol { list-style: none; margin: 0 0 .75rem; padding: 0 0 0 1rem; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 .75rem .5rem; }
.timeline li::before { content: ''; position: absolute; left: -1.38rem; top: .45rem; width: 9px; height: 9px; border-radius: 50%; background: var(--brand-2); }
.timeline li.system { color: var(--ink-2); font-size: .9rem; }
.timeline li.system::before { background: var(--line); }
.when { display: block; font-size: .75rem; color: var(--ink-3); }
.note-form { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }

/* ---------- Media picker ---------- */
.media-buttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.media-preview { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.media-item { position: relative; }
.media-item img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.media-item audio { height: 44px; }
.remove { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; cursor: pointer; line-height: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 2rem); padding: .7rem 1rem; border-radius: 8px;
  background: var(--ink); color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 20;
}
.toast.error { background: var(--crit); }

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .action { grid-template-columns: 1fr; }
}

/* ---------- Parts and purchasing ---------- */
.part-card { display: grid; gap: .6rem; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: .75rem .85rem; }
.part-card.ps-ordered { border-left-color: var(--brand-2); }
.part-card.ps-arrived { border-left-color: var(--ok); }
.part-card.ps-cancelled { border-left-color: var(--line); opacity: .75; }
.part-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .4rem; align-items: center; }
.part-task { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; color: var(--ink); }
.part-task:hover b { color: var(--brand-2); text-decoration: underline; }
.lines { width: 100%; border-collapse: collapse; font-size: .9rem; }
.lines th { text-align: left; font-size: .75rem; font-weight: 500; color: var(--ink-3); border-bottom: 1px solid var(--line); padding: .25rem .4rem .25rem 0; }
.lines td { padding: .35rem .4rem .35rem 0; border-bottom: 1px solid #eef1f3; vertical-align: top; }
.lines .num { text-align: right; white-space: nowrap; font-family: var(--mono); font-size: .85rem; }
.part-actions { display: grid; gap: .5rem; }
.pst-requested { background: #fdf1de; color: #8a4f06; }
.pst-ordered { background: #e7eef7; color: #1d4f86; }
.pst-arrived { background: #e3f3ea; color: var(--ok); }
.pst-cancelled { background: #eceff1; color: var(--ink-3); }
.parts-section { display: grid; gap: .5rem; margin-bottom: 1rem; }
.parts-section h2 { margin: 0; }
.part-line { display: grid; grid-template-columns: 1fr 80px 80px 30px; gap: .4rem; align-items: center; }
.part-line .pl-note { grid-column: 1 / 4; }
.remove-line { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: #fff; cursor: pointer; grid-row: 1; grid-column: 4; }
@media (max-width: 480px) { .part-line { grid-template-columns: 1fr 64px 70px 30px; } }

/* ---------- Team & settings ---------- */
.settings-section { display: grid; gap: .75rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; }
.card h2 { margin: 0; }
.user-row { display: grid; gap: .6rem; }
.user-row.inactive { opacity: .6; }
.user-top { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.user-top .code { margin-left: .35rem; }
.user-top .tag { margin-left: .35rem; }
.plain-list { margin: 0; padding-left: 1.1rem; display: grid; gap: .3rem; }

/* Invite links and permissions */
.invite-card { border: 2px solid var(--brand); }
.invite-code { font-family: var(--mono); font-size: 1.6rem; font-weight: 600; letter-spacing: .08em; text-align: center;
  padding: .6rem; margin: .5rem 0; background: #eef2f5; border-radius: 8px; user-select: all; }
.invite-link { font-family: var(--mono); font-size: .75rem; word-break: break-all; color: var(--ink-2); user-select: all; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.check input { width: auto; }
.steps { padding-left: 1.2rem; line-height: 1.5; }
.small { font-size: .82rem; }
.linkish { background: none; border: 0; color: var(--brand-2); text-decoration: underline; padding: .5rem 0; cursor: pointer; font: inherit; }
.user-top { display: flex; flex-direction: column; gap: .15rem; }
