/* Sankalp-ERP — premium sidebar theme */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #0b1220;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e7e9ee;
  --line-2: #eef0f4;
  --accent: #f5b83d;          /* gold highlight */
  --primary: #0b1220;         /* primary buttons + active nav */
  --blue: #2563eb;
  --red: #dc2626;   --red-bg: #fef2f2;
  --green: #16a34a; --green-bg: #ecfdf3;
  --amber: #b45309; --amber-bg: #fff7e6;
  --violet: #7c3aed; --violet-bg: #f3efff;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --side-w: 264px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.ic { width: 18px; height: 18px; flex: none; }
b { font-weight: 600; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 30;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow-y: auto;
}
.main { flex: 1; margin-left: var(--side-w); min-width: 0; display: flex; flex-direction: column; }
.content { padding: 24px 28px 48px; max-width: 1240px; width: 100%; }
.scrim { display: none; }

/* ---------- sidebar ---------- */
.side-top { padding: 20px 18px 14px; border-bottom: 1px solid var(--line-2); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand b { display: block; font-size: 16px; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.brand small { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, #1e293b, #0b1220); color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 6px 14px -6px rgba(11,18,32,.6);
}
.brand-mark .ic { width: 22px; height: 22px; }
.env {
  margin-top: 14px; display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 12px;
}
.env .host { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; color: var(--ink-2); }
.env .ver { font-size: 11px; font-weight: 600; color: var(--amber); }
.live { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.15); }
.side-nav { padding: 8px 12px; flex: 1; }
.nav-group { padding: 10px 0 4px; }
.nav-group + .nav-group { border-top: 1px solid var(--line-2); }
.nav-title { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 4px 10px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; margin: 2px 0;
  border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item .ic { color: #64748b; }
.nav-item span:first-of-type { flex: 1; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px -8px rgba(11,18,32,.7); }
.nav-item.active .ic { color: var(--accent); }
.count { font-size: 11px; font-weight: 600; min-width: 22px; text-align: center; padding: 1px 7px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); }
.count.empty { display: none; }
.count.warn { background: #fef3c7; color: #92400e; }
.nav-item.active .count { background: rgba(255,255,255,.14); color: #fff; }
.tag { font-size: 10.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); }
.nav-item.active .tag { background: rgba(255,255,255,.14); color: #fff; }
.quick { padding: 12px 16px 18px; border-top: 1px solid var(--line-2); }
.quick .nav-title { padding-left: 0; }
.quick-row { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 12px; font-weight: 600; padding: 6px 8px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--blue); box-shadow: var(--shadow-sm);
}
.chip:hover { border-color: #c7d2fe; background: #f5f7ff; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 14px 28px; background: rgba(244,245,248,.85); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.page-head { flex: 1; min-width: 0; }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.015em; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  position: relative; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); box-shadow: var(--shadow-sm);
}
.icon-btn:hover { color: var(--ink); border-color: #d6dae1; }
.icon-btn .dot {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--bg);
}
.me { display: flex; align-items: center; gap: 9px; padding: 4px 12px 4px 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); }
.me-text b { display: block; font-size: 13px; line-height: 1.2; }
.me-text small { display: block; font-size: 11px; color: var(--muted); text-transform: capitalize; }
.avatar {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: linear-gradient(145deg, #1e293b, #0b1220); color: var(--accent); font-size: 12px; font-weight: 700;
}
.avatar.xs { width: 24px; height: 24px; border-radius: 7px; font-size: 10px; }
.person { display: inline-flex; align-items: center; gap: 8px; }
.only-mobile { display: none; }

.popover {
  position: absolute; top: 60px; right: 28px; width: 380px; max-height: 70vh; overflow: auto; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 20px 50px -20px rgba(15,23,42,.35);
}
.pop-head { display: flex; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.pop-item { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.pop-item .ic { color: var(--amber); margin-top: 2px; }
.pop-item p { margin: 0 0 2px; font-size: 13px; }
.pop-item small { color: var(--muted); font-size: 11.5px; }
.pop-item.unread { background: #fffbeb; }

/* ---------- content ---------- */
.hello { margin: 0 0 18px; }
.hello h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.hello p { margin: 2px 0 0; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; font-weight: 700; margin: 0 0 14px; letter-spacing: -.01em; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card.error { color: var(--red); background: var(--red-bg); border-color: #fecaca; }
.card.pulse { animation: pulse 1.6s ease-out 1; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(245,184,61,.6); } 100% { box-shadow: 0 0 0 14px rgba(245,184,61,0); } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat {
  display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.stat-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: #eef2ff; color: #4338ca; flex: none; }
.stat:nth-child(3n+3) .stat-ic { background: #ecfdf3; color: var(--green); }
.stat.danger .stat-ic { background: var(--red-bg); color: var(--red); }
.stat.danger .n { color: var(--red); }
.stat .n { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 12px; font-weight: 500; }
.empty-state { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; background: var(--surface-2); }
.empty-state.small { border: 0; background: none; padding: 20px; }
.skeleton { height: 90px; border-radius: var(--radius); margin-bottom: 16px; background: linear-gradient(90deg, #eceef2 0%, #f5f6f8 50%, #eceef2 100%); background-size: 200% 100%; animation: sh 1.2s infinite; }
.skeleton.short { height: 260px; }
@keyframes sh { to { background-position: -200% 0; } }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); }
th:first-child { border-top-left-radius: 10px; } th:last-child { border-top-right-radius: 10px; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td, table tr:hover td { background: #fafbfc; }
.prog { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.prog span { font-variant-numeric: tabular-nums; min-width: 36px; }
.bar { flex: 1; height: 6px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #6366f1, #2563eb); }
.bar i.over { background: linear-gradient(90deg, #f97316, #dc2626); }

/* forms */
form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  font: inherit; font-weight: 400; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #94a3b8; box-shadow: 0 0 0 4px rgba(148,163,184,.18); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); padding: 0; }
fieldset { border: 1px solid var(--line) !important; border-radius: 12px !important; padding: 10px 14px 12px; }
legend { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 0 6px; }
details summary { cursor: pointer; font-weight: 600; color: var(--blue); list-style: none; }
details summary::-webkit-details-marker { display: none; }
details[open] summary { margin-bottom: 4px; }
details form { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }

/* buttons */
button.btn {
  font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--primary);
  background: var(--primary); color: #fff; cursor: pointer; box-shadow: 0 6px 14px -8px rgba(11,18,32,.7);
  transition: transform .05s, background .15s;
}
button.btn:hover { background: #1e293b; }
button.btn:active { transform: translateY(1px); }
button.btn:disabled { opacity: .6; cursor: default; }
button.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow-sm); }
button.btn.ghost:hover { background: var(--surface-2); }
button.btn.small { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
button.btn.block { width: 100%; padding: 11px 16px; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.OVERDUE, .badge.NEEDS_REVIEW { background: var(--red-bg); color: var(--red); }
.badge.EXCELLENT, .badge.DONE, .badge.CONVERTED, .badge.ISSUED { background: var(--green-bg); color: var(--green); }
.badge.ON_TRACK, .badge.IN_PROGRESS, .badge.OPEN { background: var(--amber-bg); color: var(--amber); }
.badge.ECOMMERCE_DIRECT, .badge.CLIENT { background: var(--violet-bg); color: var(--violet); }
.badge.OWNER { background: #0b1220; color: var(--accent); }
.badge.TEAM { background: #eef2ff; color: #4338ca; }

.error { color: var(--red); font-size: 13px; min-height: 18px; }
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 60; background: var(--ink); color: #fff;
  padding: 12px 16px; border-radius: 12px; max-width: 380px; box-shadow: 0 16px 40px -12px rgba(0,0,0,.45);
  border-left: 3px solid var(--accent); animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(8px); opacity: 0; } }
.items-row { display: grid; grid-template-columns: 3fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }

/* ---------- login ---------- */
.auth { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }
.auth-brand {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 40px 48px;
  color: #e2e8f0; background:
    radial-gradient(600px 400px at 85% 10%, rgba(245,184,61,.18), transparent 60%),
    radial-gradient(500px 400px at 0% 100%, rgba(99,102,241,.25), transparent 60%),
    linear-gradient(160deg, #111a2e, #0b1220 60%);
}
.auth-brand .brand small { color: #94a3b8; }
.auth-brand .brand b { color: #fff; }
.auth-brand .brand-mark { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); }
.auth-copy h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.025em; color: #fff; margin: 0 0 14px; max-width: 480px; }
.auth-copy p { color: #94a3b8; max-width: 440px; margin: 0 0 26px; font-size: 15px; }
.auth-copy ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.auth-copy li { display: flex; align-items: center; gap: 12px; color: #cbd5e1; }
.auth-copy li .ic { color: var(--accent); padding: 7px; width: 32px; height: 32px; border-radius: 9px; background: rgba(255,255,255,.06); }
.auth-foot { color: #64748b; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-form form { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.auth-form h2 { font-size: 26px; letter-spacing: -.02em; margin: 0; }
.auth-form p { margin: -8px 0 8px; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(11,18,32,.4); z-index: 25; }
  .main { margin-left: 0; }
  .only-mobile { display: grid; }
  .topbar { padding: 12px 16px; }
  .content { padding: 18px 16px 40px; }
  .me-text { display: none; }
  .me { padding: 4px; }
  .popover { right: 16px; left: 16px; width: auto; }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 28px 24px; }
  .auth-copy h1 { font-size: 24px; }
  .auth-copy p, .auth-copy ul, .auth-foot { display: none; }
}
@media (max-width: 600px) {
  .items-row { grid-template-columns: 1fr 1fr; }
  .page-head p { display: none; }
  .table-wrap { margin: 0 -20px; }
}

/* ---------- v2.4 components ---------- */
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.stack { display: grid; gap: 10px; }
form.grid.two, .grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn { margin: 2px 0 2px 4px; }
button.btn.danger { color: var(--red); }
button.btn.danger:hover { background: var(--red-bg); border-color: #fecaca; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.status-select { width: auto; padding: 5px 8px; font-size: 12px; font-weight: 600; }
.icon-btn.small { width: 30px; height: 30px; border-radius: 8px; font-size: 12px; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* sidebar tags */
.tag.gold { background: #fef3c7; color: #92400e; }
.tag.violet { background: var(--violet-bg); color: var(--violet); }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.blue { background: #e0ecff; color: #1d4ed8; }
.nav-item .tag { font-size: 9.5px; padding: 1px 7px; white-space: nowrap; }

/* stat tones */
.stat.warn .stat-ic { background: #fff7e6; color: var(--amber); }

/* extra badges */
.badge.DRAFT, .badge.NOT_SET, .badge.UNDO { background: var(--line-2); color: var(--ink-2); }
.badge.SENT, .badge.UPDATE, .badge.GEMINI { background: #e0ecff; color: #1d4ed8; }
.badge.PAID, .badge.ACCEPTED, .badge.CREATE, .badge.CONNECTED { background: var(--green-bg); color: var(--green); }
.badge.REJECTED, .badge.DELETE { background: var(--red-bg); color: var(--red); }
.badge.COMPLETED, .badge.GROQ { background: var(--violet-bg); color: var(--violet); }
.badge.ACTIVE { background: var(--green-bg); color: var(--green); }

/* segmented control */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--line-2); flex-wrap: wrap; }
.seg button { font: inherit; font-size: 12px; font-weight: 600; border: 0; background: none; color: var(--muted); padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* modal */
.modal-wrap { position: fixed; inset: 0; z-index: 70; background: rgba(11, 18, 32, .45); display: grid; place-items: center; padding: 16px; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.45); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-2); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px 20px; }
.modal fieldset { margin-bottom: 10px; }

/* line-items editor */
.tpl-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; font-size: 12px; }
.items-head, .items-row { display: grid; grid-template-columns: minmax(0, 3fr) 90px 130px 120px 34px; gap: 8px; align-items: center; }
.items-head { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 2px 6px; }
.items-row { margin-bottom: 8px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.calc { display: grid; grid-template-columns: 250px 110px 1fr; gap: 12px; align-items: end; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.disc-input { display: flex; gap: 6px; }
.disc-input input { flex: 1; min-width: 0; }
.disc-input select { width: 58px; flex: none; padding-left: 8px; padding-right: 4px; }
.calc-sum { justify-self: end; min-width: 240px; display: grid; gap: 4px; }
.calc-sum div { display: flex; justify-content: space-between; gap: 20px; }
.calc-sum .grand { border-top: 1px solid var(--line); padding-top: 6px; font-size: 16px; }
.tpl-edit { display: grid; grid-template-columns: 1fr 2fr 130px 34px; gap: 8px; margin-bottom: 8px; }

/* AI suite */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.tool { position: relative; text-align: left; font: inherit; cursor: pointer; padding: 14px 14px 12px 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.tool:hover { border-color: #cbd5e1; }
.tool.on { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11,18,32,.08); }
.tool b { display: block; font-size: 13px; }
.tool small { color: var(--muted); font-size: 12px; }
.tool-n { position: absolute; left: 12px; top: 13px; width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--line-2); color: var(--ink-2); }
.tool.on .tool-n { background: var(--primary); color: var(--accent); }
.ai-out .md { font-size: 14px; }
.md h2 { font-size: 17px; margin: 18px 0 6px; } .md h3 { font-size: 15px; margin: 14px 0 4px; } .md h4, .md h5 { font-size: 14px; margin: 12px 0 4px; }
.md p { margin: 6px 0; } .md ul, .md ol { margin: 6px 0; padding-left: 22px; } .md li { margin: 3px 0; }
.md code { background: var(--line-2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md .table-wrap { margin: 8px 0; padding: 0; } .md th { text-transform: none; letter-spacing: 0; font-size: 12px; }
.hist { display: grid; gap: 6px; }
.hist-item { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; text-align: left; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }
.hist-item:hover { background: var(--surface-2); }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 22px; text-align: center; cursor: pointer; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.drop.over { border-color: var(--primary); background: #eef2ff; }
.drop #preview img, .drop #preview video { max-height: 260px; max-width: 100%; margin-top: 12px; border-radius: 10px; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: rot .7s linear infinite; vertical-align: -1px; }
@keyframes rot { to { transform: rotate(360deg); } }
.flow-steps { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 10px; }
.flow-steps div { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 500; font-size: 13px; }
.flow-steps b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: var(--primary); color: var(--accent); font-size: 11px; margin-right: 8px; }
.flow-steps span { color: var(--muted); }
.provider label { margin-bottom: 8px; }
.test-result { font-size: 12.5px; font-weight: 500; }
.test-result.ok { color: var(--green); } .test-result.bad { color: var(--red); }

/* deliverables, ratings, portal */
.proof { margin-top: 4px; font-size: 12.5px; }
.proof a { color: var(--blue); font-weight: 600; text-decoration: none; }
.stars { color: #f59e0b; letter-spacing: 1px; } .stars span { color: #e2e8f0; }
.deliv { display: flex; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.deliv:last-child { border-bottom: 0; }
.deliv-main { flex: 1; min-width: 220px; }
.rate { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rate input[name=feedback] { width: 200px; }
.star-input { display: inline-flex; flex-direction: row-reverse; }
.star-input input { display: none; }
.star-input label { font-size: 22px; color: #e2e8f0; cursor: pointer; padding: 0 1px; font-weight: 400; }
.star-input input:checked ~ label, .star-input label:hover, .star-input label:hover ~ label { color: #f59e0b; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.kv div { padding: 12px; border-radius: 10px; background: var(--surface-2); }
.kv span { display: block; font-size: 12px; color: var(--muted); } .kv b { font-size: 18px; }

/* permission overrides */
label.perm { display: inline-flex; margin: 3px 14px 3px 0; padding: 2px 6px; border-radius: 6px; }
label.perm.added { background: var(--green-bg); }
label.perm.removed { background: var(--red-bg); text-decoration: line-through; }
.legend { display: inline-flex; gap: 6px; align-items: center; margin-left: 8px; font-size: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.lg-add { background: var(--green-bg); border: 1px solid #bbf7d0; } .lg-rem { background: var(--red-bg); border: 1px solid #fecaca; }

@media (max-width: 760px) {
  form.grid.two, .grid.two { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .items-head { display: none; }
  .items-row { grid-template-columns: 1fr 1fr; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
  .items-row input[data-k=description] { grid-column: 1 / -1; }
  .calc { grid-template-columns: 1fr 1fr; }
  .calc-sum { grid-column: 1 / -1; justify-self: stretch; }
  .tpl-edit { grid-template-columns: 1fr 1fr; }
  .tpl-edit input[data-k=description] { grid-column: 1 / -1; order: 3; }
  .kv { grid-template-columns: 1fr; }
  .actions { white-space: normal; text-align: left; }
}

/* v2.4 polish */
:root { --side-w: 284px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.stat > div { min-width: 0; }
.stat .n { font-size: clamp(19px, 1.8vw, 26px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item { gap: 10px; }
.nav-item span:first-of-type { min-width: 0; line-height: 1.3; }

/* QC: original product (description + reference photo) */
.orig { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--surface-2); }
.orig-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 10px; }
.ref-box { display: flex; flex-direction: column; gap: 6px; }
.ref-title { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.drop.small-drop { padding: 14px; flex: 1; min-height: 132px; display: flex; flex-direction: column; justify-content: center; background: var(--surface); }
.drop.small-drop #refPreview img { max-height: 160px; max-width: 100%; margin-top: 8px; border-radius: 8px; }
.ref-box .btn { align-self: flex-start; }
.orig .grid.two { align-items: stretch; }
.orig label:has(textarea) { height: 100%; }
.orig textarea { flex: 1; min-height: 150px; resize: vertical; }

/* Brand Kit + QC references */
.brand-pick { display: flex; align-items: end; gap: 16px; flex-wrap: wrap; }
.brand-pick label { min-width: 260px; }
.brand-pick p { margin: 0 0 8px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.thumb { position: relative; margin: 0; width: 112px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.thumb img { display: block; width: 100%; height: 96px; object-fit: contain; background: repeating-conic-gradient(#f1f5f9 0% 25%, #fff 0% 50%) 50% / 14px 14px; }
.thumb figcaption { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; padding: 5px 7px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb select { border: 0; border-top: 1px solid var(--line); border-radius: 0; font-size: 12px; padding: 5px 6px; }
.thumb-x { position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border-radius: 7px; border: 0; background: rgba(11,18,32,.75); color: #fff; cursor: pointer; font-size: 11px; }
.thumb.add { height: 124px; display: grid; place-items: center; text-align: center; border-style: dashed; color: var(--blue); font-weight: 600; font-size: 13px; cursor: pointer; background: var(--surface-2); }
.upload-slot { display: flex !important; flex-direction: column; justify-content: center; gap: 8px; padding: 8px; }
.upload-slot select { border: 1px solid var(--line); border-radius: 8px; }
.upload-slot label { cursor: pointer; color: var(--blue); font-weight: 600; font-size: 13px; }
.products { display: grid; gap: 12px; margin-top: 14px; }
.product { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--surface-2); }
.product-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.product p { margin: 4px 0 10px; }
.kit-refs { display: grid; gap: 8px; margin-bottom: 12px; }
.kit-refs .thumb { width: 92px; }
.kit-refs .thumb img { height: 76px; }
#refList { margin-top: 8px; }
#refList .thumb { width: 104px; }

/* QC report: score card + fixed table */
.qc-score { display: flex; align-items: center; gap: 18px; padding: 14px 16px; margin-bottom: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); }
.qc-score .ring { --c: var(--amber); width: 76px; height: 76px; border-radius: 50%; display: grid; place-content: center; text-align: center; flex: none;
  background: radial-gradient(closest-side, var(--surface) 78%, transparent 80% 100%), conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0); }
.qc-score .ring span { font-size: 22px; font-weight: 800; line-height: 1; }
.qc-score .ring small { font-size: 10px; color: var(--muted); }
.qc-score.ready .ring { --c: var(--green); } .qc-score.reject .ring { --c: var(--red); }
.qc-score .verdict { font-size: 18px; font-weight: 800; letter-spacing: .02em; }
.qc-score.ready .verdict { color: var(--green); } .qc-score.fix .verdict { color: var(--amber); } .qc-score.reject .verdict { color: var(--red); }
.qc-counts { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; font-size: 13px; font-weight: 600; }
.qc-counts .c-fail { color: var(--red); } .qc-counts .c-warn { color: var(--amber); } .qc-counts .c-ok { color: var(--green); }
.ai-out.qc .md table td { font-size: 13px; vertical-align: top; }
.ai-out.qc .md table td:nth-child(1), .ai-out.qc .md table td:nth-child(6), .ai-out.qc .md table th:nth-child(6) { text-align: center; white-space: nowrap; }
.ai-out.qc .md table td:nth-child(2) { font-weight: 600; white-space: nowrap; }
.ai-out.qc .md table td:nth-child(7) { color: var(--ink); font-weight: 500; }
.ai-out.qc .md table tr:has(td:nth-child(6)) td { border-bottom-color: var(--line-2); }
.hist-item .badge { margin-right: 6px; }

/* Task checklists */
.cl-chip { font: inherit; font-size: 11.5px; font-weight: 700; margin-left: 8px; padding: 2px 8px; border-radius: 99px; border: 1px solid #fcd34d; background: #fffbeb; color: #92400e; cursor: pointer; vertical-align: 1px; }
.cl-chip.done { border-color: #bbf7d0; background: var(--green-bg); color: var(--green); }
.cl-edit { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); }
.cl-edit-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.cl-edit-head select { width: auto; margin-left: auto; }
.cl-items { display: grid; gap: 6px; margin-bottom: 8px; }
.cl-row { display: grid; grid-template-columns: 26px 1fr 30px; gap: 6px; align-items: center; }
.cl-num { font-weight: 700; color: var(--muted); font-size: 12px; text-align: right; }
.cl-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 600; font-size: 13px; }
.cl-progress .bar { height: 8px; }
.cl-progress .bar i.full { background: linear-gradient(90deg, #22c55e, #16a34a); }
.cl-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }
.cl-list li { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.cl-list li.done { background: var(--green-bg); border-color: #bbf7d0; }
.cl-list li.done span { text-decoration: line-through; color: var(--ink-2); }
.cl-list label.check { font-size: 14px; }
.cl-list small { display: block; margin: 2px 0 0 24px; font-size: 11.5px; }
.cl-submit { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.cl-ok { margin: 8px 0; color: var(--green); font-weight: 600; }
.cl-block { margin: 8px 0; color: var(--amber); font-weight: 600; }
.row-actions .spacer { flex: 1; }
.cl-tpls { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.cl-tpl { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface-2); display: grid; gap: 8px; }
.cl-tpl-head { display: grid; grid-template-columns: 1fr 30px; gap: 6px; }

/* Task edit + history */
.linklike { font: inherit; background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-align: left; }
.linklike:hover b { text-decoration: underline; }
.hist-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.hist-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface-2); }
.hist-card.final { background: var(--green-bg); border-color: #bbf7d0; }
.hist-card h4, .hist-h { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.hist-h { margin: 16px 0 8px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; background: var(--primary); color: var(--accent); font-size: 11px; }
.hist-card dl { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; margin: 8px 0; font-size: 13px; }
.hist-card dt { color: var(--muted); font-weight: 600; }
.hist-card dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
ol.mini, ul.mini { margin: 4px 0 0; padding-left: 20px; font-size: 13px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px solid var(--line); display: grid; gap: 10px; }
.timeline li { position: relative; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.timeline li::before { content: ""; position: absolute; left: -23px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }
.timeline li.undone { opacity: .6; }
.tl-head { margin-bottom: 6px; font-size: 13px; }
table.diff { width: 100%; font-size: 12.5px; }
table.diff th { font-size: 10.5px; }
table.diff td { padding: 6px 8px; vertical-align: top; white-space: pre-wrap; word-break: break-word; }
table.diff td.old { color: var(--red); text-decoration: line-through; text-decoration-color: rgba(220,38,38,.4); }
table.diff td.new { color: var(--green); font-weight: 600; }
.diff-add { color: var(--green); font-weight: 500; text-decoration: none; }
.diff-rem { color: var(--red); font-weight: 500; }
.subs { display: grid; gap: 8px; }
.sub { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.sub.latest { border-color: #86efac; box-shadow: 0 0 0 3px rgba(22,163,74,.08); }
.sub-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.sub a { color: var(--blue); word-break: break-all; font-size: 13px; }
.sub-note { margin-top: 4px; font-size: 13px; white-space: pre-wrap; }
.sub details { margin-top: 6px; font-size: 12.5px; }
.hist-time { margin-top: 14px; font-size: 13px; }
@media (max-width: 760px) { .hist-grid { grid-template-columns: 1fr; } }

/* line item note (what's included) */
.items-row { grid-template-areas: "d q p a x" "n n n n n"; padding-bottom: 8px; border-bottom: 1px solid var(--line-2); }
.items-row [data-k=description] { grid-area: d; } .items-row [data-k=quantity] { grid-area: q; } .items-row [data-k=unitPrice] { grid-area: p; }
.items-row [data-amt] { grid-area: a; } .items-row > button { grid-area: x; }
.items-row .item-details { grid-area: n; font-size: 12.5px; padding: 6px 10px; resize: vertical; background: var(--surface-2); border-style: dashed; }
@media (max-width: 760px) { .items-row { grid-template-areas: "d d" "q p" "a x" "n n"; } }

/* timing badges + report */
.timing { display: block; margin-top: 4px; font-size: 11.5px; font-weight: 600; }
.timing.on-time, .timing.done { color: var(--green); }
.timing.late { color: var(--red); }
.timing.running { color: var(--blue); }
.timing.not-started { color: var(--muted); }
.time-report { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin: 8px 0 4px; }
.time-report div { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--surface); }
.time-report span { display: block; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.time-report b { font-size: 13px; }
.verdict-line { padding: 8px 12px; border-radius: 10px; font-weight: 700; margin: 6px 0; }
.verdict-line.on-time, .verdict-line.done { background: var(--green-bg); color: var(--green); }
.verdict-line.late { background: var(--red-bg); color: var(--red); }
.verdict-line.running, .verdict-line.not-started { background: #eef2ff; color: #3730a3; }

.tpl-edit .tpl-details { grid-column: 1 / -1; font-size: 12.5px; background: var(--surface-2); border-style: dashed; }

/* clients: upcoming + billing fields */
.billing-fields { grid-column: 1 / -1; border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; }
.billing-fields summary { color: var(--ink); }
.billing-fields .grid { margin-top: 8px; }

/* Task Reports */
.rep-filters { display: grid; gap: 10px; }
.rep-filter-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.rep-filter-row2 { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rep-filter-row2 input[type=search] { width: 240px; }
.rep-filter-row2 .spacer { flex: 1; }
.rep-groups { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.rep-groups > .card { min-width: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f5f7ff; }
tr.sel td { background: #eef2ff; }
.c-late { color: var(--red); font-weight: 700; }
.rep-tasks td { font-size: 13px; }
.rep-tasks td:nth-child(7) { min-width: 170px; }
.rep-tasks .timing { margin-top: 0; }
ul.cl-mini { list-style: none; padding-left: 0; }
ul.cl-mini li { margin: 2px 0; }
@media (max-width: 760px) { .rep-groups { grid-template-columns: minmax(0, 1fr); } .rep-filter-row2 input[type=search] { width: 100%; } }

/* Agency settings → Invoice design */
.ag-flags { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 0; }
.ag-flags .check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.ag-flags .check input { width: auto; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] { width: 54px; height: 38px; padding: 3px; }
.ag-imgs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 14px; }
.ag-img { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.ag-img-prev { width: 96px; height: 96px; flex: none; display: grid; place-items: center; border-radius: 10px; text-align: center;
  background: repeating-conic-gradient(#f1f5f9 0 25%, #fff 0 50%) 0 0 / 16px 16px; border: 1px dashed var(--line); }
.ag-img-prev img { max-width: 90px; max-height: 90px; object-fit: contain; }
.ag-img-btns { display: flex; gap: 6px; margin-top: 6px; }

/* Client picker inside bill / quotation edit */
.bill-client { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 12px; }
.bill-client label { flex: 1; }
.bill-client .btn { margin-bottom: 2px; white-space: nowrap; }
@media (max-width: 560px) { .bill-client { flex-direction: column; align-items: stretch; } }

/* Bill numbering */
.bill-no .check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; margin-top: 4px; color: var(--muted); }
.bill-no .check input { width: auto; }
.num-rows { display: grid; gap: 10px; }
.num-row { display: grid; grid-template-columns: 170px 1fr 90px 130px 1fr; gap: 10px; align-items: end; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.num-row .check { display: inline-flex; align-items: center; gap: 8px; align-self: center; }
.num-row .check input { width: auto; }
.num-row.off label:not(.check), .num-row.off .num-prev { opacity: .45; }
.num-prev { display: grid; gap: 2px; padding-bottom: 8px; }
.num-prev b { font-family: ui-monospace, Menlo, monospace; font-size: 15px; }
@media (max-width: 760px) { .num-row { grid-template-columns: 1fr 1fr; } .num-row .check, .num-prev { grid-column: 1 / -1; } }
.calc-sum .strong { font-weight: 700; border-top: 1px dashed var(--line); padding-top: 4px; }
.calc-sum .calc-note { text-align: right; max-width: 320px; justify-self: end; }
.calc-sum s.was { color: var(--muted); font-weight: 500; }
.disc-input select { width: 118px; }

/* Premium bill fields */
.items-row { grid-template-areas: "d q p a x" "e e e e e" "n n n n n"; }
.items-row .item-extra { grid-area: e; display: grid; grid-template-columns: 1.2fr 1fr 1.2fr; gap: 8px; }
.items-row .item-extra input { font-size: 12.5px; padding: 6px 10px; background: var(--surface-2); }
@media (max-width: 760px) { .items-row { grid-template-areas: "d d" "q p" "a x" "e e" "n n"; } .items-row .item-extra { grid-template-columns: 1fr; } }
.prem-fields { margin-top: 12px; border: 1px dashed var(--line); border-radius: 12px; padding: 10px 14px; }
.prem-fields summary { cursor: pointer; font-weight: 600; }
.prem-fields[open] summary { margin-bottom: 10px; }

/* Team logins */
.pw-row { display: flex; gap: 6px; }
.pw-row input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; }
.login-share pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: 13px; }
.show-gst { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.show-gst input { width: auto; }
.calc-sum .plus-gst { font-size: 12px; color: var(--muted); }
