:root {
  --bg: #f6f1e8; --panel: #fffdf9; --ink: #2b2118; --muted: #7a6a5a; --line: #e5dacb; --line2: #efe7db;
  --saffron: #c0702a; --saffron-d: #9a5520; --saffron-l: #f6e3cf;
  --cut: #b8432f; --cut-l: #f6dcd5; --keep: #3d7a4e; --keep-l: #dcefe1; --pending: #d4962a; --pending-l: #fbecd0;
  --blue: #3b6e8f; --blue-l: #dde9f1; --radius: 10px;
  --font: -apple-system, "Segoe UI", "Helvetica Neue", Roboto, Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; }
a { color: var(--saffron-d); }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 14px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: var(--mono); font-size: 12px; }
.hidden { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 18px; background: #2b2118; color: #f6efe4; }
.brand { display: flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { color: #cdbca6; font-size: 11px; }
.topbar-right { display: flex; gap: 6px; align-items: center; }
.topbar .btn.ghost { color: #f6efe4; border-color: #5a4a3b; }
.topbar .btn.ghost:hover { background: #3d3024; }
.save-state { font-size: 12px; color: #cdbca6; margin-right: 6px; }

main { padding: 18px; max-width: 1500px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.card.tight { padding: 10px 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--line2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--saffron); border-color: var(--saffron); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--saffron-d); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.cut { background: var(--cut); border-color: var(--cut); color: #fff; }
.btn.keep { background: var(--keep); border-color: var(--keep); color: #fff; }
.btn.danger { color: var(--cut); border-color: #e7b9ae; }
.btn.big { padding: 10px 20px; font-size: 15px; }

input[type=text], input[type=password], input[type=number], select, textarea {
  font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; color: var(--ink); }
textarea { width: 100%; resize: vertical; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 4px; }
label.f input[type=text], label.f input[type=password], label.f select { width: 100%; }
label.chk { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; cursor: pointer; }
label.chk input { margin-top: 3px; }
.hint { font-size: 12px; color: var(--muted); }

.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--line2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.badge.cut { background: var(--cut-l); color: var(--cut); } .badge.keep { background: var(--keep-l); color: var(--keep); }
.badge.pending { background: var(--pending-l); color: #94660f; } .badge.blue { background: var(--blue-l); color: var(--blue); }
.badge.saffron { background: var(--saffron-l); color: var(--saffron-d); }
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.alert.warn { background: #fdf3df; border-color: #ecd09a; color: #6d4b0b; }
.alert.err { background: #fbe6e1; border-color: #e7b9ae; color: #7a2716; }
.alert.ok { background: #e3f1e6; border-color: #b4d6bd; color: #24502f; }
.alert.info { background: var(--blue-l); border-color: #b5cede; color: #234b63; }

/* Stepper: 8 bước của quy trình */
.stepper { display: flex; gap: 0; overflow-x: auto; margin-bottom: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.stp { flex: 1 1 0; min-width: 120px; display: flex; flex-direction: column; gap: 1px; padding: 7px 10px 7px 12px; border-radius: 7px; cursor: pointer; position: relative; border: 1px solid transparent; }
.stp + .stp::before { content: "›"; position: absolute; left: -6px; top: 50%; transform: translateY(-50%); color: #c9b9a4; font-size: 18px; }
.stp:hover { background: var(--line2); }
.stp.active { background: var(--saffron-l); border-color: #ebc9a6; }
.stp.locked { opacity: .45; cursor: default; }
.stp .n { font-size: 10.5px; font-weight: 700; color: var(--muted); letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.stp .t { font-size: 12.5px; font-weight: 700; line-height: 1.2; }
.stp .d { font-size: 11px; color: var(--muted); line-height: 1.25; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #d6c9b8; display: inline-block; }
.dot.done { background: var(--keep); } .dot.running { background: var(--saffron); animation: pulse 1s infinite; }
.dot.error { background: var(--cut); } .dot.stale { background: var(--pending); }
@keyframes pulse { 50% { opacity: .3; } }

.projhead { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.projhead h1 { margin: 0; cursor: text; }
.job { margin-bottom: 14px; }
.bar { height: 8px; background: var(--line2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--saffron); transition: width .3s; }

.drop { border: 2px dashed #d8c6ae; border-radius: var(--radius); padding: 28px; text-align: center; background: #fffaf2; cursor: pointer; }
.drop.over { background: var(--saffron-l); border-color: var(--saffron); }
table.list { width: 100%; border-collapse: collapse; }
table.list td, table.list th { padding: 8px 6px; border-bottom: 1px solid var(--line2); text-align: left; vertical-align: middle; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; }
.ministeps { display: inline-flex; gap: 3px; }
.stat { background: #fff; border: 1px solid var(--line2); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; word-break: break-all; }

/* Sóng âm */
.wavebox { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; margin-bottom: 10px; }
.wavebox canvas { display: block; width: 100%; }
canvas.ov { height: 34px; cursor: pointer; border-bottom: 1px solid var(--line2); margin-bottom: 4px; }
canvas.dt { height: 130px; cursor: crosshair; }
.transport { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding-top: 8px; }
.transport .time { font-family: var(--mono); font-size: 13px; min-width: 150px; }
.transport .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* Metta Review */
.review { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr); gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.panel-h { padding: 9px 12px; border-bottom: 1px solid var(--line2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-b { overflow-y: auto; padding: 10px 12px; height: calc(100vh - 420px); min-height: 320px; }
.transcript p { margin: 0 0 10px; line-height: 1.85; font-size: 15px; }
.transcript .sid { font-family: var(--mono); font-size: 10.5px; color: #b3a28d; margin-right: 6px; user-select: none; cursor: pointer; }
.w { border-radius: 3px; padding: 1px 1px; cursor: pointer; }
.w:hover { background: var(--line2); }
.w.now { background: #ffe9a8; box-shadow: 0 0 0 1px #f0cf6e; }
.w.p { background: var(--pending-l); }
.w.c { background: var(--cut-l); color: #9d4a3a; text-decoration: line-through; text-decoration-color: var(--cut); }
.w.k { border-bottom: 2px solid #9fcaa9; }
.w.selsug { box-shadow: inset 0 -2px 0 var(--saffron); }
.w.sel { background: var(--blue-l); box-shadow: 0 0 0 1px #9cbcd2; }
.w.suspect { border-bottom: 2px dotted var(--cut); }
.w.low { border-bottom: 2px dotted var(--pending); }
.w.ev { font-style: italic; color: var(--muted); }
.selbar { position: sticky; top: 0; z-index: 3; background: var(--blue-l); border: 1px solid #b5cede; border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }

.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { font: inherit; font-size: 12.5px; border: 0; background: #fff; padding: 4px 10px; cursor: pointer; border-right: 1px solid var(--line); }
.tabs button:last-child { border-right: 0; }
.tabs button.on { background: var(--saffron-l); color: var(--saffron-d); font-weight: 650; }

.sug { border: 1px solid var(--line); border-left: 4px solid var(--pending); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; background: #fff; cursor: pointer; }
.sug.cut { border-left-color: var(--cut); } .sug.keep { border-left-color: var(--keep); }
.sug.sel { box-shadow: 0 0 0 2px var(--saffron); }
.sug .top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.sug .txt { margin: 6px 0 4px; font-size: 14px; }
.sug.cut .txt { text-decoration: line-through; text-decoration-color: var(--cut); color: #8a5246; }
.sug .why { font-size: 12.5px; color: var(--muted); }
.sug .acts { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.sug .fine { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); display: grid; grid-template-columns: auto 1fr; gap: 6px 8px; align-items: center; font-size: 12.5px; }
.sug .fine .nudge { display: flex; gap: 3px; align-items: center; }
.sug .fine input { width: 96px; font-family: var(--mono); font-size: 12px; padding: 3px 6px; }
.prog { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 220px; }
.prog .bar { flex: 1; }
.kbd { font-family: var(--mono); font-size: 11px; background: #fff; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

/* QC */
.joins .j { display: flex; gap: 8px; align-items: center; padding: 7px 4px; border-bottom: 1px solid var(--line2); flex-wrap: wrap; }
.joins .j.ok { background: #f2f9f3; } .joins .j.bad { background: #fdf0ec; }
.joins .j .mono { min-width: 70px; }
.check { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line2); }
.check .i { width: 22px; text-align: center; }
.files .file { display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: #fff; }
.files .file .ic { font-size: 22px; width: 32px; text-align: center; }
.files .file .nm { flex: 1; }
ol.guide li { margin-bottom: 6px; }

.modal { position: fixed; inset: 0; background: rgba(43, 33, 24, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal .box { background: var(--panel); border-radius: 12px; padding: 20px 22px; width: min(720px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #2b2118; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--cut); }

@media (max-width: 1000px) {
  .review { grid-template-columns: 1fr; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .panel-b { height: 50vh; }
}

.btn.cut .kbd, .btn.keep .kbd, .btn.primary .kbd { background: transparent; color: #fff; border-color: rgba(255,255,255,.55); }
a.btn { text-decoration: none; display: inline-block; }
