:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #d9dee4;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --danger: #c62828;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-color: var(--bg);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 12px 16px;
  background: #1b2430;
  color: #fff;
}
.brand { font-weight: 700; }
.nav { display: flex; gap: 14px; flex-wrap: wrap; }
.nav a { color: #cbd5e1; text-decoration: none; }
.nav a.active, .nav a:hover { color: #fff; }
.who { margin-left: auto; font-size: 14px; }
.who .muted { color: #aab4c0; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.narrow { max-width: 380px; margin: 40px auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: flex-end; margin: 8px 0 12px; }
.filters label { margin: 0; min-width: 160px; }
.filters input, .filters select { width: auto; min-width: 150px; }

label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
label input, label select, label textarea { margin-top: 4px; }

input, select, textarea, button, .btn {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
input, select, textarea { width: 100%; }
input[type="file"] { width: auto; padding: 6px 0; border: none; }
textarea { resize: vertical; }

button, .btn { cursor: pointer; text-decoration: none; display: inline-block; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.link { background: none; border: none; padding: 2px 4px; color: var(--primary); }
.danger { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.stack-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.stack-row > * { flex: 1 1 160px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.list-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
table.lines input.f-price { min-width: 90px; width: 110px; }

/* Approval path diagram */
.ap-wrap { overflow-x: auto; }
.ap-svg { display: block; width: 100%; min-width: 620px; height: auto; }
.ap-node .ap-when { fill: var(--muted); font-size: 9.5px; }
.ap-arrowhead { fill: var(--muted); }

.ap-line { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* Done: the line draws itself in, one segment after another */
.ap-line.done { stroke: #2e7d32; stroke-dasharray: 1 1; stroke-dashoffset: 1; animation: ap-draw 0.7s ease forwards; }
/* Waiting now: a bright line that keeps flowing toward the next step */
.ap-line.current { stroke: #7aa6f5; stroke-dasharray: 0.04 0.085; animation: ap-flow 2.6s linear infinite; stroke-width: 3; }
/* Rejection: red line flowing back to the requester */
.ap-line.bad { stroke: var(--danger); stroke-dasharray: 0.0625 0.0625; animation: ap-flow 1s linear infinite; stroke-width: 3.5; }
.ap-line.pending { stroke: var(--border); stroke-dasharray: 0.01 0.04; }
.ap-line.idle { stroke: var(--border); stroke-dasharray: 0.01 0.05; opacity: 0.8; }

@keyframes ap-draw { to { stroke-dashoffset: 0; } }
@keyframes ap-flow { to { stroke-dashoffset: -1; } }

.ap-node .body { fill: #fff; stroke: var(--border); stroke-width: 2; }
.ap-node.done .body { fill: #2e7d32; stroke: #2e7d32; }
.ap-node.bad .body { fill: var(--danger); stroke: var(--danger); }
.ap-node.current .body { fill: var(--primary); stroke: var(--primary); }
.ap-node.skipped .body { fill: #f1f3f5; stroke-dasharray: 3 3; }
.ap-node .icon { fill: #fff; font-size: 8px; font-weight: 700; }
.ap-node.pending .icon, .ap-node.skipped .icon { fill: var(--muted); }
.ap-node .ap-label { fill: var(--text); font-size: 11px; font-weight: 600; }
.ap-node .ap-who { fill: var(--muted); font-size: 10px; }
.ap-node.pending .ap-label, .ap-node.skipped .ap-label { fill: var(--muted); font-weight: 500; }
.ap-node .pulse {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2;
  transform-box: fill-box;
  transform-origin: center;
  animation: ap-pulse 2.4s ease-out infinite;
}
@keyframes ap-pulse {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(2); opacity: 0; }
}
.ap-tag { fill: var(--muted); font-size: 12px; font-style: italic; }
.ap-tag.bad { fill: var(--danger); }

.ap-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.sw.idle { height: 0; background: none; border-top: 2px dotted var(--border); }
.ap-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 18px; height: 4px; border-radius: 2px; }
.sw.done { background: #2e7d32; }
.sw.current { background: var(--primary); }
.sw.pending { background: var(--border); }
.sw.bad { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .ap-line, .ap-node .pulse { animation: none !important; }
  .ap-line.done { stroke-dashoffset: 0; }
}

/* Searchable dropdown */
.combo { position: relative; min-width: 0; }
.combo-input { width: 100%; }
.combo-panel {
  z-index: 50;
  max-height: 280px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.combo-opt { padding: 8px 10px; cursor: pointer; }
.combo-opt:hover, .combo-opt.hi { background: #eef4ff; }
.combo-opt.on { font-weight: 600; }
.combo-empty { padding: 8px 10px; color: var(--muted); font-size: 14px; }
.combo-new {
  position: sticky;
  bottom: 0;
  padding: 9px 10px;
  border-top: 1px solid var(--border);
  background: var(--card);
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}
.combo-new:hover { background: #eef4ff; }
table .combo { min-width: 170px; }

dialog.quick-add {
  width: min(420px, 92vw);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--card);
  color: var(--text);
}
dialog.quick-add::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog.quick-add h2 { margin-top: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f8fafc; font-size: 13px; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f1f6ff; }
tr.inactive td { color: var(--muted); }
table.lines input, table.lines select { min-width: 110px; }
table.lines input[type="number"] { min-width: 80px; width: 90px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #e5e7eb;
  color: #374151;
  white-space: nowrap;
}
.s-draft { background: #e5e7eb; color: #374151; }
.s-requested { background: #fef3c7; color: #92400e; }
.s-accepted { background: #dbeafe; color: #1e40af; }
.s-rejected { background: #fee2e2; color: #991b1b; }
.s-purchased { background: #ede9fe; color: #5b21b6; }
.s-sent { background: #cffafe; color: #155e75; }
.s-received { background: #dcfce7; color: #166534; }

.info { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; margin-bottom: 8px; }
.info div span { display: block; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); }
.section-title { display: flex; align-items: center; gap: 8px; }

.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.receipts { list-style: none; padding: 0; margin: 0 0 12px; }
.receipts li { padding: 6px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.list li.inactive { color: var(--muted); }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #1b2430;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  max-width: calc(100% - 32px);
  z-index: 10;
}
.toast.error { background: var(--danger); }

@media (max-width: 600px) {
  .container { padding: 12px; }
  .who { margin-left: 0; width: 100%; }
  .card { padding: 12px; }
}
