/* Avicen - Operations Weekly MIS Portal — stylesheet (no external dependencies) */
:root {
  --teal: #0d9488; --teal-d: #0f766e; --teal-l: #ccfbf1; --brand: #03ae6e;
  --emerald: #059669; --emerald-l: #d1fae5;
  --amber: #d97706; --amber-l: #fef3c7; --amber-b: #fcd34d;
  --red: #dc2626; --red-l: #fee2e2;
  --ink: #0f172a; --ink2: #334155; --muted: #64748b; --line: #e2e8f0; --line2: #cbd5e1;
  --bg: #f3f6f6; --card: #ffffff; --soft: #f8fafc;
  --r: 12px; --sh: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --sh2: 0 10px 30px rgba(15,23,42,.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- Brand mark ---------- */
.mark { width: 38px; height: 38px; flex: none; display: block; }
.mark.lg { width: 60px; height: 60px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: 10px; border: 1px solid transparent; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, transform .08s, box-shadow .15s, border-color .15s; user-select: none; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { cursor: not-allowed; opacity: .75; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--teal); color: #fff; box-shadow: 0 1px 2px rgba(13,148,136,.4); }
.btn-primary:hover:not(:disabled) { background: var(--teal-d); }
.btn-ghost { background: #fff; border-color: var(--line2); color: var(--ink2); }
.btn-ghost:hover:not(:disabled) { background: var(--soft); border-color: var(--muted); }
.btn-danger { background: #fff; border-color: #fca5a5; color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red-l); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 36px; padding: 0; }
.btn.is-busy { background: var(--teal-d); color: #fff; }
.btn.is-ok { background: var(--emerald); color: #fff; border-color: var(--emerald); }
.btn.is-err { background: var(--red); color: #fff; border-color: var(--red); }
.btn.is-dirty { background: var(--amber); color: #fff; border-color: var(--amber); animation: pulse 1.6s ease-in-out infinite; }
.btn.is-dirty:hover { background: #b45309; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(217,119,6,.55); } 50% { box-shadow: 0 0 0 7px rgba(217,119,6,0); } }
.spin { width: 16px; height: 16px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: rot .7s linear infinite; flex: none; }
.spin.dark { border-color: rgba(13,148,136,.25); border-top-color: var(--teal); }
@keyframes rot { to { transform: rotate(360deg); } }
.save-btn { min-width: 220px; height: 42px; font-size: 14.5px; }

/* ---------- Forms ---------- */
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink2); }
.inp, select.inp, textarea.inp { height: 38px; border: 1px solid var(--line2); border-radius: 9px; padding: 0 11px; background: #fff; outline: none; width: 100%;
  transition: border-color .15s, box-shadow .15s; font-weight: 400; }
textarea.inp { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.inp:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,.16); }
.inp:disabled, .inp[readonly] { background: var(--soft); color: var(--muted); }
.inp.bad { border-color: var(--red); box-shadow: 0 0 0 3px rgba(220,38,38,.12); }
.fgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.fgrid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---------- Login / setup ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #d7f3ec 0, transparent 60%), radial-gradient(900px 500px at 110% 110%, #d9f1f0 0, transparent 55%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; box-shadow: var(--sh2); padding: 34px 30px 26px; }
.auth-card.wide { max-width: 520px; }
.auth-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; margin-bottom: 22px; }
.auth-head h1 { font-size: 19px; }
.auth-head p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .btn { height: 44px; width: 100%; margin-top: 4px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 12px; color: var(--muted); }
.pw-wrap { position: relative; }
.pw-wrap .inp { padding-right: 42px; }
.pw-eye { position: absolute; right: 4px; top: 4px; width: 32px; height: 30px; border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: 7px; }
.pw-eye:hover { background: var(--soft); }
.alert { padding: 10px 12px; border-radius: 9px; font-size: 13px; line-height: 1.45; }
.alert.err { background: var(--red-l); color: #991b1b; }
.alert.info { background: var(--teal-l); color: #115e59; }
.alert.warn { background: var(--amber-l); color: #92400e; }

/* ---------- App shell ---------- */
.topbar { position: sticky; top: 0; z-index: 40; background: #fff; border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1480px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand h1 { font-size: 15.5px; letter-spacing: -.01em; }
.brand .sub { font-size: 11.5px; color: var(--muted); }
.hdr-mid { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.teal { background: var(--teal-l); color: #115e59; }
.badge.gray { background: #f1f5f9; color: var(--ink2); }
.badge.role-SA { background: #ede9fe; color: #5b21b6; }
.badge.role-OM { background: #dbeafe; color: #1e40af; }
.badge.role-AOM { background: #e0f2fe; color: #075985; }
.badge.role-CM { background: var(--emerald-l); color: #065f46; }
.user { display: flex; align-items: center; gap: 10px; padding-left: 14px; border-left: 1px solid var(--line); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--teal), var(--brand)); color: #fff; display: grid; place-items: center; font-weight: 700; }
.user .nm { font-weight: 600; font-size: 13px; line-height: 1.2; }
.tabs { max-width: 1480px; margin: 0 auto; display: flex; gap: 4px; padding: 0 20px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 11px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2.5px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--teal-d); border-bottom-color: var(--teal); }
main { max-width: 1480px; margin: 0 auto; padding: 18px 20px 60px; }
.page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.page-title h2 { font-size: 19px; }
.page-title p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- Context bar (sticky) ---------- */
.ctxbar { position: sticky; top: 101px; z-index: 30; background: rgba(243,246,246,.92); backdrop-filter: blur(6px); padding: 10px 0; margin: 0 0 6px; }
.ctxbar-in { background: #fff; border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh); padding: 10px 14px; display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.ctxbar label.f { min-width: 150px; }
.ctxbar .cyc { min-width: 290px; }
.ctx-info { font-size: 12px; color: var(--muted); line-height: 1.45; padding-bottom: 2px; }
.ctx-info b { color: var(--ink2); }

/* ---------- Cluster cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px; margin-bottom: 16px; }
.ccard { position: relative; text-align: left; background: #fff; border: 1.5px solid var(--line); border-radius: 14px; padding: 13px 14px 12px; cursor: pointer;
  box-shadow: var(--sh); transition: transform .09s ease, box-shadow .15s, border-color .15s; overflow: hidden; }
.ccard::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--line2); }
.ccard.h-green::before { background: var(--emerald); }
.ccard.h-yellow::before { background: #eab308; }
.ccard.h-red::before { background: var(--red); }
.ccard:hover { box-shadow: 0 4px 14px rgba(15,23,42,.10); }
.ccard:active { transform: scale(.975); }
.ccard.on { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,.22), 0 8px 22px rgba(13,148,136,.18); }
.ccard-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 9px; }
.ccard-h .id { font-weight: 800; font-size: 15px; color: var(--teal-d); }
.ccard-h .rg { font-size: 12px; color: var(--ink2); font-weight: 600; }
.ccard-h .mg { font-size: 11.5px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.pct { font-weight: 800; }
.pct.g { color: var(--emerald); } .pct.y { color: #b45309; } .pct.r { color: var(--red); }
.bar { height: 6px; border-radius: 99px; background: #eef2f6; overflow: hidden; margin: 8px 0 9px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--brand)); border-radius: 99px; transition: width .4s; }
.tally { display: flex; gap: 6px; margin-top: 9px; }
.tally span { flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; height: 26px; border-radius: 7px; font-size: 12px; font-weight: 700; }
.tally .g { background: var(--emerald-l); color: #065f46; }
.tally .y { background: #fef9c3; color: #854d0e; }
.tally .r { background: var(--red-l); color: #991b1b; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.g { background: var(--emerald); } .dot.y { background: #eab308; } .dot.r { background: var(--red); } .dot.n { background: var(--line2); }

/* ---------- Panels ---------- */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh); margin-bottom: 16px; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-h h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.panel-h .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--teal-l); color: var(--teal-d); font-size: 12px; font-weight: 800; }
.panel-b { padding: 14px 16px; }
.panel-b.flush { padding: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 > .panel { margin-bottom: 0; }
.stack > * + * { margin-top: 16px; }
.empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.ro-note { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 9px; background: #f5f3ff; color: #5b21b6; font-size: 13px; margin-bottom: 12px; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.t th { position: sticky; top: 0; background: var(--soft); color: var(--ink2); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.t td { padding: 8px 10px; border-bottom: 1px solid #eef2f6; vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: #fbfdfd; }
table.t th.r, table.t td.r { text-align: right; }
table.t tfoot td { background: #f0fdfa; font-weight: 800; border-top: 2px solid var(--teal); border-bottom: 0; }
table.t .ref { color: var(--muted); }
.grid-tbl th.ed { color: var(--teal-d); }
.grid-tbl th.amb { color: #b45309; }
.cell { width: 118px; height: 34px; text-align: right; padding: 0 9px; border: 1px solid var(--line2); border-radius: 7px; background: #fff; outline: none; font-variant-numeric: tabular-nums; }
.cell.sm { width: 84px; }
.cell:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,.18); background: #f0fdfa; }
.cell.amb { background: var(--amber-l); border-color: var(--amber-b); }
.cell.amb:focus { background: #fffbeb; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(217,119,6,.18); }
.cell.dirty { border-color: var(--amber); border-width: 1.5px; }
.cell.bad { border-color: var(--red); background: var(--red-l); }
.cell:disabled { background: var(--soft); color: var(--ink2); border-color: var(--line); }
.over { color: var(--red); font-weight: 700; }
.nm-cell { min-width: 210px; }
.nm-cell .small { white-space: nowrap; }
.bid { font-weight: 700; color: var(--teal-d); white-space: nowrap; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.chip.g { background: var(--emerald-l); color: #065f46; } .chip.y { background: #fef9c3; color: #854d0e; } .chip.r { background: var(--red-l); color: #991b1b; }
.chip.b { background: #dbeafe; color: #1e40af; } .chip.n { background: #f1f5f9; color: var(--ink2); } .chip.p { background: #ede9fe; color: #5b21b6; }
.chip.a { background: var(--amber-l); color: #92400e; }
.grid-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); flex-wrap: wrap; }
kbd { font-family: inherit; font-size: 11px; padding: 1px 6px; border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 5px; background: #fff; color: var(--ink2); }

/* ---------- Day chips / segmented ---------- */
.days { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.day { border: 1.5px solid var(--line2); background: #fff; border-radius: 9px; padding: 6px 4px; cursor: pointer; text-align: center; transition: all .12s; }
.day b { display: block; font-size: 13px; }
.day span { font-size: 11px; color: var(--muted); }
.day:active { transform: scale(.96); }
.day.on { border-color: var(--teal); background: var(--teal-l); color: var(--teal-d); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--ink2); }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on.ok { background: var(--emerald-l); color: #065f46; }
.seg button.on.ex { background: var(--red-l); color: #991b1b; }
.seg button.on.na { background: #f1f5f9; color: var(--ink); }
.audit-area { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.audit-area + .audit-area { margin-top: 8px; }
.audit-area.ex { border-color: #fca5a5; background: #fffafa; }
.audit-area .hd { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.audit-area .bd { margin-top: 10px; }
.store-line { display: flex; gap: 8px; }
.store-line + .store-line { margin-top: 8px; }
.linkbtn { border: 0; background: none; color: var(--teal-d); font-weight: 700; cursor: pointer; padding: 4px 0; font-size: 13px; }
.linkbtn:hover { text-decoration: underline; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 10px 0; border-top: 1px solid #eef2f6; font-size: 13px; }
.feed li:first-child { border-top: 0; }
.feed .t1 { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.feed .t1 b { font-size: 13px; }
.feed .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.feed .body { margin-top: 4px; color: var(--ink2); white-space: pre-wrap; line-height: 1.45; }
.sub-h { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 16px 0 6px; }

/* ---------- MIS ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; box-shadow: var(--sh); }
.kpi .l { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 19px; font-weight: 800; margin-top: 3px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .s { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.pillar-h { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; }
.pillar-h .pn { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--teal), var(--brand)); color: #fff; display: grid; place-items: center; font-weight: 800; }
.pillar-h h3 { font-size: 16.5px; }
.pillar-h p { margin: 0; font-size: 12.5px; color: var(--muted); }
.meter { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.meter .bar { flex: 1; margin: 0; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; background: #fff; border-radius: 12px; box-shadow: var(--sh2); padding: 12px 14px; border-left: 5px solid var(--teal);
  animation: tin .25s ease-out; font-size: 13px; line-height: 1.45; }
.toast.ok { border-left-color: var(--emerald); } .toast.err { border-left-color: var(--red); } .toast.warn { border-left-color: var(--amber); }
.toast .ti { font-weight: 700; margin-bottom: 1px; }
.toast .x { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; }
.toast.out { animation: tout .25s ease-in forwards; }
.toast svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
@keyframes tin { from { opacity: 0; transform: translateY(20px); } }
@keyframes tout { to { opacity: 0; transform: translateX(30px); } }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 90; display: grid; place-items: center; padding: 16px; animation: fin .15s; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 460px; box-shadow: var(--sh2); max-height: calc(100vh - 32px); overflow: auto; }
.modal.wide { max-width: 620px; }
.modal-h { padding: 16px 20px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-h h3 { font-size: 16px; }
.modal-b { padding: 14px 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-f { padding: 4px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fin { from { opacity: 0; } }

.loading-screen { min-height: 60vh; display: grid; place-items: center; color: var(--muted); }
.skel { background: linear-gradient(90deg, #eef2f6 25%, #f6f8fa 50%, #eef2f6 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 12px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .topbar-in { padding: 10px 14px; }
  .hdr-mid { margin-left: 0; width: 100%; order: 3; }
  .user { margin-left: auto; }
  .tabs, main { padding-left: 14px; padding-right: 14px; }
  .ctxbar { position: static; }
  .save-btn { width: 100%; }
  .fgrid { grid-template-columns: 1fr; }
  .days { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 560px) { .brand .sub, .user .rl { display: none; } .ctx-info { width: 100%; } .ctxbar .cyc, .ctxbar label.f { min-width: 0; width: 100%; } }

/* ---------- Print (Friday review) ---------- */
@media print {
  .topbar, .ctxbar, #toasts, .no-print, .tabs { display: none !important; }
  body, main { background: #fff; padding: 0; }
  .panel, .kpi, .ccard { box-shadow: none; break-inside: avoid; }
  .tbl-wrap { overflow: visible; }
}
