:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #94a3b8;
  --line: #e2e8f0;
  --line-dark: #334155;
  --brand: #2563eb;
  --brand-soft: #dbeafe;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --purple: #7c3aed;
  --shadow: 0 1px 3px rgba(15, 23, 42, .12), 0 8px 24px rgba(15, 23, 42, .08);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #f1f5f9;
  font-size: 14px;
}
a { cursor: pointer; text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  height: 56px;
  background: var(--bg);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.brand b { font-weight: 700; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 18px;
}
/* real brand logo: white rounded badge so the navy mark reads on the dark bar */
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: #fff; object-fit: contain; padding: 3px; }
.topbar-spacer { flex: 1; }
.search-wrap input {
  background: var(--bg-soft); border: 1px solid var(--line-dark); color: #fff;
  border-radius: 8px; padding: 8px 12px; width: 260px; outline: none;
}
.search-wrap input::placeholder { color: var(--muted); }
.icon-btn {
  position: relative; background: var(--bg-soft); border: 1px solid var(--line-dark);
  color: #fff; width: 38px; height: 38px; border-radius: 8px; font-size: 16px;
}
.badge {
  position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff;
  border-radius: 10px; font-size: 11px; min-width: 18px; height: 18px; padding: 0 4px;
  display: grid; place-items: center; font-weight: 700;
}
.me-wrap { display: flex; align-items: center; gap: 8px; }
.me-wrap label { color: var(--muted); font-size: 12px; }
.me-wrap select {
  background: var(--bg-soft); color: #fff; border: 1px solid var(--line-dark);
  border-radius: 8px; padding: 8px 10px; outline: none;
}

/* ---- layout ---- */
.body { display: flex; height: calc(100vh - 56px); }
.sidenav {
  width: 200px; background: #fff; border-right: 1px solid var(--line);
  padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0;
}
.navlink {
  padding: 9px 12px; border-radius: 8px; color: var(--ink-soft); font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.navlink:hover { background: #f1f5f9; }
.navlink.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-sep { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 14px 12px 6px; letter-spacing: .04em; }
main { flex: 1; overflow-y: auto; padding: 20px 24px; }

/* ---- shared ---- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head .sub { color: var(--ink-soft); font-size: 13px; }
.spacer { flex: 1; }
.btn {
  background: var(--brand); color: #fff; border: none; padding: 9px 14px;
  border-radius: 8px; font-weight: 600; font-size: 13px;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f8fafc; }
.btn.subtle { background: #f1f5f9; color: var(--ink); }
.btn.danger { background: var(--red); }
.btn.green { background: var(--green); }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* ---- filter chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 7px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-soft); font-weight: 600;
}
.chip:hover { border-color: var(--brand); }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .n { opacity: .7; margin-left: 4px; }

/* ---- table ---- */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); font-weight: 700;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; cursor: pointer; }
.order-no { font-weight: 700; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
td.cb, th.cb { width: 36px; text-align: center; padding-left: 10px; padding-right: 0; }
.row-cb, #selAll { width: 16px; height: 16px; cursor: pointer; }
tbody tr.sel { background: #eff6ff; }
tbody tr.sel:hover { background: #e0eefe; }
.qf-select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-family: inherit; font-size: 13px; outline: none; max-width: 220px; }
.qf-select:focus { border-color: var(--brand); }
.bulk-bar {
  position: sticky; bottom: 0; margin-top: 14px; z-index: 15;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15,23,42,.25);
}
.bulk-bar b { margin-right: 4px; }
.bulk-bar .qf-select { background: var(--bg-soft); color: #fff; border-color: var(--line-dark); }
.muted { color: var(--ink-soft); }
.mini { font-size: 12px; color: var(--muted); }
.prod-cell { line-height: 1.35; }

/* ---- badges ---- */
.tag {
  display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 11.5px;
  font-weight: 700; white-space: nowrap;
}
.tag.ws-Unassigned { background: #f1f5f9; color: var(--ink-soft); }
.tag.ws-Claimed { background: #e0f2fe; color: #0369a1; }
.tag.ws-In.Progress, .tag.ws-In-Progress { background: #dbeafe; color: #1d4ed8; }
.tag.ws-Needs.Help, .tag.ws-Needs-Help { background: #fef3c7; color: #b45309; }
.tag.ws-On.Hold, .tag.ws-On-Hold { background: #ede9fe; color: #6d28d9; }
.tag.ws-Resolved { background: #dcfce7; color: #15803d; }
.tag.issue { background: #f1f5f9; color: var(--ink-soft); }
.tag.pri-Low { background: #f1f5f9; color: var(--ink-soft); }
.tag.pri-Normal { background: #e0f2fe; color: #0369a1; }
.tag.pri-High { background: #fef3c7; color: #b45309; }
.tag.pri-Urgent { background: #fee2e2; color: #b91c1c; }
.tag.overdue { background: #fee2e2; color: #b91c1c; }

.avatar {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 11px; margin-right: 6px;
}
.handler { display: inline-flex; align-items: center; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }
.table-more { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }

/* ---- drawer ---- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100%; width: min(1100px, 94vw);
  background: #f8fafc; box-shadow: -8px 0 40px rgba(0,0,0,.2); overflow-y: auto;
  animation: slidein .18s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head {
  position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--line);
  padding: 16px 22px; display: flex; align-items: center; gap: 14px; z-index: 2;
}
.drawer-head h2 { margin: 0; font-size: 18px; }
.close-x { margin-left: auto; background: #f1f5f9; border: none; width: 34px; height: 34px; border-radius: 8px; font-size: 18px; }

.detail-grid { display: grid; grid-template-columns: 1fr 1.1fr 1fr; gap: 16px; padding: 18px 22px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 16px; }
.litem { display: flex; gap: 10px; padding: 8px; border-bottom: 1px solid var(--line); }
.litem:last-child { border-bottom: none; }
.litem-img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); flex-shrink: 0; background: #f1f5f9; }
.litem-noimg { display: grid; place-items: center; color: var(--muted); }
.litem-body { min-width: 0; }
.litem-name { font-weight: 600; font-size: 13px; line-height: 1.3; }
.litem-name a { color: var(--brand); }
.litem-name a:hover { text-decoration: underline; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.panel h3 { margin: 0; padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-soft); }
.panel-body { padding: 14px 16px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); font-size: 12.5px; }
.kv .v { font-weight: 600; text-align: right; }

.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 5px; font-weight: 600; }
.field select, .field input, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-family: inherit; font-size: 13px; outline: none;
}
.field select:focus, .field input:focus, .field textarea:focus { border-color: var(--brand); }
.inline-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---- activity / chat ---- */
.feed-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.feed-seg button { padding: 4px 10px; font-size: 11.5px; }
.feed-more { align-self: center; border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  font-size: 11.5px; font-weight: 600; padding: 5px 12px; border-radius: 999px; cursor: pointer; margin-bottom: 4px; }
.feed-more:hover { background: var(--bg); color: var(--ink); }
.feed { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow-y: auto; padding: 14px 16px; }
.msg { display: flex; gap: 9px; align-items: flex-start; }
.msg .bubble { background: #f1f5f9; border-radius: 12px; padding: 8px 11px; max-width: 80%; }
/* my own messages sit on the right in brand colour (Google-chat style) */
.msg.mine { flex-direction: row-reverse; }
.msg.mine .bubble { background: var(--brand); color: #fff; border-radius: 12px 12px 4px 12px; }
.msg.mine .bubble .when { color: rgba(255, 255, 255, .8); }
.msg.mine .text .mention { color: #fff; text-decoration: underline; }
.msg.mine .att-file { background: rgba(255, 255, 255, .2); color: #fff; }
.msg.mine .msg-tool:hover { background: rgba(255, 255, 255, .25); }
/* notes stay yellow even when they're mine */
.msg.note .bubble { background: #fffbeb; border: 1px solid #fde68a; color: var(--ink); border-radius: 12px; }
.msg.note .bubble .when { color: var(--muted); }
.msg .who { font-weight: 700; font-size: 12.5px; }
.msg .when { color: var(--muted); font-size: 11px; margin-left: 6px; font-weight: 500; }
.msg .text { margin-top: 2px; white-space: pre-wrap; line-height: 1.4; }
.msg .text .mention { color: var(--brand); font-weight: 700; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 7px; }
.att-img { max-width: 170px; max-height: 150px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.att-img:hover { filter: brightness(.95); }
.att-file { font-size: 12.5px; color: var(--brand); font-weight: 600; background: #eff6ff; padding: 5px 9px; border-radius: 7px; }
#fileName { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sys {
  text-align: center; font-size: 11.5px; color: var(--muted); padding: 3px 0;
}
.sys span { background: #eef2f7; padding: 3px 10px; border-radius: 999px; }
.composer { border-top: 1px solid var(--line); padding: 12px 16px; position: relative; }
.msg-head { display: flex; align-items: center; gap: 6px; }
.msg-tools { margin-left: auto; display: flex; gap: 1px; opacity: 0; transition: opacity .1s; }
.msg:hover .msg-tools { opacity: 1; }
.msg-tool { border: none; background: transparent; cursor: pointer; font-size: 11px; line-height: 1; padding: 2px 4px; border-radius: 5px; }
.msg-tool:hover { background: #e2e8f0; }
.mention-box { position: absolute; left: 16px; right: 16px; bottom: calc(100% - 8px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 6; max-height: 200px; overflow-y: auto; }
.mention-item { display: flex; align-items: center; gap: 8px; padding: 8px 11px; cursor: pointer; font-size: 13px; }
.mention-item .avatar { width: 24px; height: 24px; margin: 0; }
.mention-item.active, .mention-item:hover { background: var(--brand-soft); }
.composer textarea { width: 100%; resize: vertical; min-height: 56px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-family: inherit; font-size: 13px; }
.composer .row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 7px 12px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.seg button.active { background: var(--brand); color: #fff; }

/* ---- dashboard ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 28px; font-weight: 800; }
.stat .l { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.stat.warn .n { color: var(--amber); }
.stat.danger .n { color: var(--red); }
.stat.good .n { color: var(--green); }
.danger-zone { border-color: #f3c2c2; background: #fffafa; }
.pw-text { font-size: 13px; font-family: ui-monospace, monospace; background: var(--bg);
  padding: 1px 6px; border-radius: 4px; user-select: all; color: var(--ink); }
/* help / guide page */
.guide { padding: 22px 26px; max-width: 860px; line-height: 1.55; }
.guide h2 { font-size: 17px; margin: 22px 0 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.guide h2:first-of-type { border-top: none; padding-top: 0; margin-top: 4px; }
.guide p { margin: 6px 0; color: var(--ink); }
.guide ul, .guide ol { margin: 6px 0 6px 4px; padding-left: 22px; }
.guide li { margin: 4px 0; }
.guide code { background: var(--brand-soft); color: var(--brand); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 4px; font-size: 12.5px; font-weight: 600;
  font-family: ui-monospace, monospace; }
/* daily summary card */
.sum-card { padding: 4px 0 8px; margin-bottom: 18px; }
.sum-head { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.sum-head b { font-size: 14px; }
.sum-row { display: flex; align-items: flex-start; gap: 12px; padding: 9px 16px; border-bottom: 1px solid var(--line); }
.sum-row:last-child { border-bottom: none; }
.sum-row.zero { opacity: .55; }
.sum-label { width: 220px; flex-shrink: 0; font-weight: 600; color: var(--ink-soft); }
.sum-label:hover { color: var(--brand); text-decoration: underline; }
.sum-count { width: 34px; flex-shrink: 0; text-align: center; font-weight: 800; font-size: 15px; color: var(--muted); }
.sum-count.hot { color: var(--red); }
.sum-orders { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ochip { background: #f1f5f9; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.ochip:hover { border-color: var(--brand); color: var(--brand); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.bar-row .lbl { width: 150px; font-size: 12.5px; color: var(--ink-soft); flex-shrink: 0; }
.bar-track { flex: 1; background: #f1f5f9; border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 6px; }
.bar-row .val { width: 30px; text-align: right; font-weight: 700; font-size: 12.5px; }

/* ---- admin tables / forms ---- */
.admin-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 12px; align-items: end; padding: 14px 16px; border-bottom: 1px solid var(--line); }
/* drop the field's bottom margin inside the add-form so inputs + the Add button line up at the bottom */
.admin-form .field { margin-bottom: 0; }
.admin-form .btn { height: 38px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; }
.slink { color: var(--brand); cursor: pointer; }
.slink:hover { text-decoration: underline; }

/* ---- popover / toast ---- */
.popover {
  position: fixed; top: 58px; right: 130px; width: 340px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 50;
  max-height: 70vh; overflow-y: auto;
}
.popover .ph { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; font-weight: 700; }
.notif-item { padding: 11px 14px; border-bottom: 1px solid var(--line); }
.notif-item.unread { background: #eff6ff; }
.notif-item .nb { font-size: 13px; }
.notif-item .nt { font-size: 11px; color: var(--muted); margin-top: 2px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  z-index: 60; box-shadow: var(--shadow); font-weight: 600; font-size: 13px;
}
.requote-box { background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 12.5px; }

/* identity chip + login screen */
.me-wrap { display: flex; align-items: center; gap: 8px; }
.who-chip { display: inline-flex; align-items: center; gap: 6px; color: #fff; font-weight: 600; font-size: 13px; }
.who-chip .avatar { width: 24px; height: 24px; margin: 0; }
.who-chip .mini { color: var(--muted); }
.login-overlay { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 100; }
.login-overlay.hidden { display: none; }
.login-card { background: #fff; border-radius: 14px; padding: 28px 26px; width: 340px; box-shadow: var(--shadow); text-align: center; }
.login-card h2 { font-size: 20px; }
.login-card .field { text-align: left; }
.login-logo { display: flex; justify-content: center; margin-bottom: 6px; }
.login-logo img { max-width: 260px; width: 100%; height: auto; }
.login-err { color: var(--red); font-size: 12.5px; min-height: 18px; text-align: left; margin: 2px 0; }

/* import drop zone */
.dropzone { border: 2px dashed var(--line); border-radius: 12px; padding: 26px 18px; text-align: center; color: var(--ink-soft); background: #fafcff; transition: border-color .12s, background .12s; }
.dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
