:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #e2e6eb;
  --primary: #2563eb;
  --primary-soft: #e8efff;
  --ok: #16a34a;
  --ok-soft: #e7f6ec;
  --danger: #dc2626;
  --empty: #e5e8ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-bottom: .75rem; }
.muted { color: var(--muted); }
.empty { padding: .5rem 0; margin: 0; }
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea, select {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 2.4rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem; white-space: nowrap;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer;
  color: var(--text); text-decoration: none;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d4fd8; }
.btn:disabled { opacity: .6; cursor: default; }
.icon {
  width: 2rem; height: 2rem; border: 1px solid transparent; background: transparent; border-radius: 6px;
  cursor: pointer; color: var(--muted); flex: none;
}
.icon:hover:not(:disabled) { background: #eef0f3; color: var(--text); }
.icon:disabled { opacity: .3; cursor: default; }
.icon.danger:hover { color: var(--danger); background: #fdecec; }
.linklike { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .7rem 1.25rem; background: #111827; color: #e5e7eb; flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; }
.brand span, .login-card h1 span { color: #93b4ff; font-weight: 500; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 1.1rem; }
.topbar nav a, .topbar .linklike { color: #cbd2dc; }
.topbar nav a.on { color: #fff; font-weight: 600; }
.logout { margin: 0; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: .25rem 0 0; }
.inline-form { display: flex; gap: .5rem; min-width: min(100%, 340px); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem;
}

/* Dashboard cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.pkg-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.1rem; cursor: pointer; display: flex; flex-direction: column; gap: .8rem; transition: border-color .15s;
}
.pkg-card:hover, .pkg-card:focus { border-color: var(--primary); outline: none; }
.pkg-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.pkg-top h2 { overflow-wrap: anywhere; }
.pct { font-weight: 700; font-size: 1.3rem; color: var(--primary); font-variant-numeric: tabular-nums; }
.pct.full { color: var(--ok); }
.pkg-foot { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; }
.card-actions { display: flex; gap: .1rem; }
.segbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.seg { height: 10px; border-radius: 3px; background: var(--empty); display: block; }
.seg.done { background: var(--ok); }
a.seg:hover { outline: 2px solid var(--primary-soft); }

/* Report */
.report { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.report .card { margin: 0; display: flex; flex-direction: column; gap: .75rem; }
.empty-steps { margin: 0; padding-left: 1.1rem; }
.empty-steps li { margin: .2rem 0; }
.ok { color: var(--ok); margin: 0; font-weight: 600; }
.stage-summary { list-style: none; margin: 0; padding: 0; }
.stage-summary li { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; border-top: 1px solid var(--line); }
.stage-summary li:first-child { border-top: 0; }
.stage-n {
  flex: none; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; font-size: .82rem; font-weight: 600;
}
.stage-t { flex: 1; min-width: 0; }
.stage-c { flex: none; color: var(--muted); font-size: .9rem; }
.stage-c.ok { color: var(--ok); }

/* Package page */
.crumbs { margin-bottom: .5rem; font-size: .9rem; }
.pkg-head { align-items: center; flex-wrap: nowrap; }
.title-input {
  font-size: 1.5rem; font-weight: 700; border-color: transparent; background: transparent; padding: .2rem .4rem; margin-left: -.4rem;
}
.title-input:hover { border-color: var(--line); background: #fff; }
.stepper {
  list-style: none; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 0; margin: 0 0 1.25rem; counter-reset: s;
}
.stepper li { position: relative; text-align: center; }
.stepper li::before {
  content: ""; position: absolute; top: 1rem; left: -50%; width: 100%; height: 3px; background: var(--empty); z-index: 0;
}
.stepper li:first-child::before { display: none; }
.stepper li.done::before { background: var(--ok); }
.stepper a { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: .35rem; color: var(--muted); padding: 0 .2rem; }
.stepper a:hover { text-decoration: none; color: var(--text); }
.stepper .dot {
  width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: #fff; border: 2px solid var(--empty); color: var(--muted);
}
.stepper li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.stepper li.active .dot { box-shadow: 0 0 0 4px var(--primary-soft); border-color: var(--primary); }
.stepper li.active.done .dot { border-color: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.stepper li.active .label { color: var(--text); font-weight: 600; }
.stepper .label { font-size: .82rem; line-height: 1.3; }
.step-title { margin: 0 0 1rem; }
.step-nav { display: flex; justify-content: space-between; margin: 1.5rem 0 2rem; }

/* Collapsible sub-parts */
details.sub { padding: 0; }
details.sub summary {
  cursor: pointer; padding: .85rem 1.1rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; list-style: none;
}
details.sub summary::-webkit-details-marker { display: none; }
details.sub summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.sub[open] summary::before { transform: rotate(90deg); }
.sub-body { padding: 0 1.1rem 1rem; }
.pill { font-size: .72rem; font-weight: 500; color: var(--muted); background: #f0f2f5; border-radius: 999px; padding: .1rem .5rem; }

/* Editable lists */
.rows { list-style: none; margin: 0 0 .75rem; padding: 0; }
.row { display: flex; align-items: flex-start; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.num {
  flex: none; width: 1.7rem; height: 1.7rem; margin-top: .35rem; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary); display: grid; place-items: center; font-size: .82rem; font-weight: 700;
}
.fields { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .5rem; min-width: 0; }
.row-actions { display: flex; flex: none; gap: .1rem; padding-top: .2rem; }
.add-row { display: flex; gap: .5rem; align-items: flex-start; padding-top: .75rem; border-top: 1px dashed var(--line); }

/* Rich text */
.rich .ql-toolbar.ql-snow { border-radius: 8px 8px 0 0; border-color: var(--line); background: #fafbfc; }
.rich .ql-container.ql-snow { border-radius: 0 0 8px 8px; border-color: var(--line); font: inherit; }
.rich .ql-editor { min-height: 140px; font-size: 15px; line-height: 1.55; }
.rich .ql-editor.ql-blank::before { color: #9aa4b0; font-style: normal; }
.rich-foot { display: flex; justify-content: flex-end; min-height: 1.3rem; font-size: .8rem; padding-top: .25rem; }

/* Cases table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.cases { width: 100%; border-collapse: collapse; min-width: 900px; }
.cases th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfc; padding: .55rem .5rem; border-bottom: 1px solid var(--line); }
.cases td { padding: .4rem; vertical-align: top; border-bottom: 1px solid var(--line); }
.cases tr:last-child td { border-bottom: 0; }
.cases tr.testcase td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
.cases tr.usecase td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.cases .c-code { width: 80px; }
.cases .c-kind { width: 120px; }
.cases td input, .cases td textarea, .cases td select { padding: .4rem .5rem; font-size: .9rem; }
.cases .row-actions { white-space: nowrap; }

/* Wireframes */
.upload { display: grid; grid-template-columns: 2fr 120px 2fr auto; gap: .5rem; margin-bottom: 1rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .3rem .8rem; cursor: pointer; font-size: .88rem; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.wf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.wf { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.wf > a { display: block; background: #f0f2f5; aspect-ratio: 4 / 3; }
.wf img { width: 100%; height: 100%; object-fit: contain; display: block; }
.wf figcaption { padding: .5rem; display: flex; flex-direction: column; gap: .4rem; }
.wf-actions { display: flex; align-items: center; gap: .4rem; }
.wf-actions select { width: auto; padding: .3rem .4rem; font-size: .85rem; }
.wf-actions .icon { margin-left: auto; }
.tag { font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 4px; text-transform: uppercase; }
.tag.web { background: var(--primary-soft); color: var(--primary); }
.tag.mobile { background: #fff4e0; color: #b45309; }

/* Toast */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: #111827; color: #fff;
  padding: .55rem 1rem; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; font-size: .92rem; max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 1.75rem; }
.login-card form { display: flex; flex-direction: column; gap: .9rem; margin-top: 1rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
.login-card .btn { margin-top: .3rem; padding: .65rem; }
.alert { background: #fdecec; color: var(--danger); border-radius: 8px; padding: .55rem .75rem; margin-top: .75rem; font-size: .9rem; }

/* Mobile */
@media (max-width: 640px) {
  .container { padding: .9rem; }
  .topbar { padding: .6rem .9rem; }
  .topbar nav { gap: .8rem; font-size: .92rem; }
  h1, .title-input { font-size: 1.25rem; }
  .stepper .label { font-size: .68rem; }
  .stepper .dot { width: 1.75rem; height: 1.75rem; }
  .stepper li::before { top: .875rem; }
  .add-row { flex-direction: column; align-items: stretch; }
  .upload { grid-template-columns: 1fr; }
  .inline-form { width: 100%; }
  .row { flex-wrap: wrap; }
  .row .fields { flex-basis: calc(100% - 2.5rem); }
  .row .row-actions { margin-left: auto; }
}
