:root {
  --ink: #23262b;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f5f2;
  --card: #fff;
  --gold: #b8923a;
  --gold-soft: #f3e7c9;
  --charcoal: #2b2b2b;
  --red: #c0392b; --red-soft: #fde2e1;
  --green: #2e7d32; --green-soft: #e2f0d9;
  --amber: #9a6b00; --amber-soft: #fff2cc;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; }
[dir="ltr"] { text-align: left; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--charcoal); color: #fff; }
.brand { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.logo { background: var(--gold); color: var(--charcoal); font-weight: 700; padding: 8px 10px; border-radius: 8px; letter-spacing: 1px; }
.brand-title { font-weight: 700; font-size: 18px; }
.brand-sub { font-size: 12px; opacity: .7; }
.health { font-size: 13px; opacity: .9; }
.top-right { display: flex; align-items: center; gap: 14px; }
.lang-btn { font: inherit; font-weight: 700; background: transparent; color: var(--gold); border: 1px solid var(--gold); border-radius: 20px; padding: 4px 14px; cursor: pointer; }
.lang-btn:hover { background: var(--gold); color: var(--charcoal); }
.export-group { display: inline-flex; border: 1px solid var(--gold); border-radius: 8px; overflow: hidden; }
.export-group .btn { border: 0; border-radius: 0; }
.export-group .btn + .btn { border-inline-start: 1px solid #d9c38f; }
.export-group select { border: 0; border-radius: 0; background: #fffdf7; padding: 0 8px; border-inline-start: 1px solid #d9c38f; }
.health .bad { color: #ffb4a8; }

main { max-width: 1280px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
h2 { margin: 0 0 16px; font-size: 19px; }
h3 { margin: 18px 0 8px; font-size: 16px; color: var(--charcoal); }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.grid-form .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }

.drop { position: relative; border: 2px dashed #d6c79d; border-radius: var(--radius); padding: 26px; text-align: center; background: #fffdf7; }
.drop.over { background: var(--gold-soft); }
.drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-text small { color: var(--muted); }
#file-list { list-style: none; padding: 0; margin: 10px 0 0; font-size: 13px; }
#file-list li { display: inline-block; background: var(--gold-soft); padding: 3px 10px; border-radius: 20px; margin: 3px; }

.actions { display: flex; gap: 10px; justify-content: flex-start; flex-wrap: wrap; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; padding: 8px 16px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--charcoal); color: #fff; border-color: var(--charcoal); }
.btn.primary:hover { background: #000; }
.btn.gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { background: #faf8f3; font-weight: 700; color: var(--charcoal); position: sticky; top: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fffdf7; }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; white-space: nowrap; background: #eef0f3; }
.badge.mandatory, .badge.high, .badge.error { background: var(--red-soft); color: var(--red); }
.badge.optional, .badge.low, .badge.done { background: var(--green-soft); color: var(--green); }
.badge.unclear, .badge.medium, .badge.analyzing, .badge.extracting { background: var(--amber-soft); color: var(--amber); }

.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 16px 0 4px; }
.stat { background: #faf8f3; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.stat b { display: block; font-size: 24px; color: var(--charcoal); }
.stat span { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin: 18px 0 14px; flex-wrap: wrap; }
.tab { padding: 9px 16px; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; color: var(--muted); }
.tab.active { color: var(--charcoal); border-color: var(--gold); font-weight: 700; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { flex: 1; min-width: 200px; }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #fff; }
.box h4 { margin: 0 0 8px; color: var(--gold); font-size: 14px; }
.box ul { margin: 0; padding-inline-start: 18px; }
.box li { margin: 3px 0; }
.overview { line-height: 1.9; background: #fffdf7; border-inline-start: 4px solid var(--gold); padding: 12px 16px; border-radius: 6px; }

.progress { display: flex; align-items: center; gap: 12px; padding: 16px; background: var(--amber-soft); border-radius: 8px; }
.spinner { width: 22px; height: 22px; border: 3px solid #e8d7a6; border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: 12px 16px; border-radius: 8px; background: var(--red-soft); color: var(--red); margin: 10px 0; }
.warn { padding: 8px 12px; border-radius: 8px; background: var(--amber-soft); color: var(--amber); font-size: 13px; margin-top: 4px; }

.req-detail td { background: #fffdf7; }
.req-detail .quote { font-size: 13px; color: var(--muted); border-inline-start: 3px solid var(--line); padding-inline-start: 10px; margin: 6px 0; }
.inline-edit { display: grid; grid-template-columns: 160px 140px 1fr auto; gap: 8px; margin-top: 8px; }
.inline-edit textarea { min-height: 38px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--charcoal); color: #fff; padding: 10px 20px; border-radius: 8px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 10; }
.toast.show { opacity: 1; }

@media (max-width: 700px) {
  .inline-edit { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
}

/* ---- Phase 2 ---- */
.logo-row { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.logo-box { width: 180px; height: 90px; border: 1px dashed var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; background: #fff; }
.logo-box img { max-width: 170px; max-height: 80px; }
table.catalog input, table.catalog select { width: 100%; padding: 6px 8px; font-size: 13px; }
.export-box { margin-bottom: 14px; border-color: var(--gold); background: #fffdf7; }
.stat.total { background: var(--charcoal); }
.stat.total b, .stat.total span { color: #fff; }
.filters label { min-width: 140px; }
select.st-comply { background: var(--green-soft); }
select.st-partial { background: var(--amber-soft); }
select.st-not_comply { background: var(--red-soft); }
select.st-clarify { background: #e6ecf5; }
#ms-table input { width: 100%; }
input[type=color] { height: 40px; width: 90px; padding: 3px; cursor: pointer; }
.badge.src-ext { background: #e6ecf5; color: #2f4f7f; }

/* ---- Dashboard ---- */
.kpis { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); margin-top: 0; }
.kpis .stat b { font-size: 21px; }
.stat small { display: block; margin-top: 2px; font-size: 11px; }
.stat.danger { background: var(--red-soft); }
.stat.danger b { color: var(--red); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: #fff; padding: 7px 14px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--charcoal); color: #fff; }
.dash-grid { display: block; margin-top: 16px; }
.dash-side { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 16px; align-items: start; }
.dash-side a { color: var(--charcoal); font-weight: 700; text-decoration: none; }
.dash-side a:hover { color: var(--gold); }
.board { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.col { background: #efede8; border-radius: 10px; padding: 8px; min-height: 260px; transition: background .15s; }
.col.over { background: var(--gold-soft); }
.col-h { font-weight: 700; font-size: 13px; padding: 4px 6px 8px; border-bottom: 3px solid; margin-bottom: 8px; display: flex; justify-content: space-between; }
.col-h span { background: #fff; border-radius: 10px; padding: 0 8px; font-weight: 500; }
.kcard { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; cursor: grab; font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.kcard:hover { border-color: var(--gold); }
.kcard b { display: block; line-height: 1.4; }
.kmeta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.kmeta .val { font-weight: 700; color: var(--charcoal); }
.dl { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: #eef0f3; color: var(--muted); }
.dl.over { background: var(--red-soft); color: var(--red); font-weight: 700; }
.dl.soon { background: var(--amber-soft); color: var(--amber); font-weight: 700; }
.dl.ok { background: var(--green-soft); color: var(--green); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: 0; }
ul.plain.small { font-size: 12.5px; }
.hbar { display: grid; grid-template-columns: 90px 1fr 28px; align-items: center; gap: 8px; font-size: 12.5px; margin: 5px 0; }
.hbar div { background: #f1efe9; border-radius: 6px; height: 10px; overflow: hidden; display: flex; }
.hbar i { display: block; height: 100%; border-radius: 6px; }
.vbars { display: flex; align-items: flex-end; gap: 4px; height: 110px; }
.vbars div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.vbars i { display: block; width: 100%; background: var(--gold); border-radius: 3px 3px 0 0; min-height: 2px; }
.vbars span { font-size: 9.5px; color: var(--muted); margin-top: 3px; }
.stage-pill { color: #fff; padding: 2px 10px; border-radius: 12px; font-size: 12px; white-space: nowrap; }
.pipe-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: #faf8f3; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 14px; }
.pipe-bar label { min-width: 130px; }
.pipe-bar .pl-notes { flex: 1; min-width: 200px; }
.pipe-title { align-self: center; color: var(--gold); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline .ic { width: 30px; height: 30px; border-radius: 50%; background: var(--gold-soft); display: flex; align-items: center; justify-content: center; flex: none; }
.timeline li.error .ic { background: var(--red-soft); }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.chk { display: grid; grid-template-columns: 22px 1fr; gap: 2px 6px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.chk span { grid-row: span 2; font-weight: 700; }
.chk.ok span { color: var(--green); }
.chk.bad { background: var(--red-soft); }
.chk.bad span { color: var(--red); }
.chk small { color: var(--muted); overflow-wrap: anywhere; }
[hidden] { display: none !important; }

/* ---- Delivery ---- */
.kprog { height: 6px; background: #eceae4; border-radius: 4px; overflow: hidden; margin-top: 6px; display: flex; }
.kprog i { display: block; height: 100%; background: var(--green); }
.kprog.at_risk i { background: var(--amber); }
.kprog.behind i { background: var(--red); }
.stat.total .kprog { background: #555; }
.gantt { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.g-row { display: grid; grid-template-columns: 230px 1fr 200px; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.g-row:last-child { border-bottom: 0; }
.g-label b { display: block; font-size: 13px; }
.g-label .meta { font-size: 11px; }
.g-track { position: relative; height: 26px; background: #f6f5f2; border-radius: 6px; }
.g-bar { position: absolute; top: 3px; bottom: 3px; background: #e6e2d6; border-radius: 5px; overflow: hidden; display: flex; }
.g-bar i { display: block; height: 100%; background: var(--gold); opacity: .85; }
.g-bar.done i { background: var(--green); }
.g-bar.late { outline: 2px solid var(--red); }
.g-bar span { position: absolute; inset-inline-start: 6px; top: 2px; font-size: 11px; font-weight: 700; color: var(--charcoal); }
.g-today { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--red); }
.g-acc { display: flex; gap: 6px; align-items: center; }
.g-acc select { padding: 4px 6px; font-size: 12px; }
@media (max-width: 900px) { .g-row { grid-template-columns: 1fr; } }
.dl-board { grid-template-columns: repeat(5, minmax(180px, 1fr)); }
.col-h.st-todo { border-color: #9ca3af; } .col-h.st-in_progress { border-color: var(--gold); }
.col-h.st-testing { border-color: #6b7fa6; } .col-h.st-done { border-color: var(--green); } .col-h.st-blocked { border-color: var(--red); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 20; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: min(900px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.crit { display: flex; flex-direction: column; gap: 6px; }
.chkline { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--ink); font-size: 14px; }
.chkline input { margin-top: 4px; }
pre.prompt { background: #1f2023; color: #e6e6e6; padding: 12px; border-radius: 8px; white-space: pre-wrap; font-size: 12px; max-height: 240px; overflow: auto; text-align: left; }
tr.pay-paid td { background: #f1f8ee; }
tr.pay-invoiced td { background: #fffaf0; }
tr.muted-row td { opacity: .55; }
td.neg { color: var(--red); font-weight: 700; }
td.pos { color: var(--green); font-weight: 700; }
.dl-board .col { max-height: 640px; overflow-y: auto; }

/* ---- Auth ---- */
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-box .urole { background: var(--gold); color: var(--charcoal); border-radius: 10px; padding: 1px 8px; font-weight: 700; font-size: 11.5px; }
.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 30px; border-top: 4px solid var(--gold); }
.login-card h2 { margin: 6px 0 0; }
.login-logo { align-self: flex-start; background: var(--charcoal); color: var(--gold); font-weight: 800; padding: 10px 14px; border-radius: 10px; letter-spacing: 1px; }
body[data-role="viewer"] .btn.danger, body[data-role="viewer"] .btn.primary:not([type=submit]) { display: none; }

/* ---- v0.8 ---- */
.texts-box textarea { width: 100%; font: inherit; line-height: 1.7; }
.texts-box h4 { margin: 14px 0 6px; }
.texts-box label { margin-bottom: 8px; }
.modal h3 { margin-top: 16px; }

/* ---- v0.9 ---- */
tr.muted td { opacity: .55; }
.clar-box { margin-bottom: 14px; border-inline-start: 4px solid var(--gold, #B8923A); }
label.btn input[type=file] { display: none; }
.health .ver { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #B8923A; color: #fff; font-weight: 700; font-size: 12px; direction: ltr; margin-inline-end: 6px; }
#uat-body td[dir=ltr] { white-space: nowrap; }
