:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --ink: #1a2332;
  --muted: #6b7486;
  --line: #e3e7ee;
  --accent: #1f5eff;
  --accent-dark: #1546c4;
  --accent-soft: #e9efff;
  --green: #0e9f6e;
  --green-soft: #e2f6ee;
  --amber: #b45309;
  --amber-soft: #fdf1de;
  --red: #d92d20;
  --red-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: 0 0 220px; background: #101828; color: #cdd5e0;
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky;
  top: 0; height: 100vh;
}
.brand { color: #fff; font-size: 17px; font-weight: 700; padding: 4px 10px 18px; letter-spacing: .2px; }
.brand span { color: #6ea0ff; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #cdd5e0; margin-bottom: 2px; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; }
.nav svg { width: 17px; height: 17px; flex: none; }
.sidebar .foot { margin-top: auto; padding: 12px 10px; font-size: 14.5px; color: #aeb9c9; line-height: 1.8; }
.sidebar .foot a { color: #c6cfdc; font-size: 14px; font-weight: 500; }
.sidebar .foot b { font-size: 15px; }

.main { flex: 1; padding: 26px 32px; max-width: 1200px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.topbar h1 { font-size: 21px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---- flash ---- */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--green-soft); color: #065f46; border: 1px solid #b7e9d3; }
.flash.err { background: var(--red-soft); color: #991b1b; border: 1px solid #f6c8c5; }

/* ---- cards / stats ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card .num { font-size: 26px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 12.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }
.card.hi .num { color: var(--accent); }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px;
}
.panel h2 { font-size: 15px; margin: 0 0 14px; }

/* ---- tables ---- */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line);
}
table.grid td { padding: 10px; border-bottom: 1px solid var(--line); }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr:hover td { background: #f8fafd; }
td.r, th.r { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }

/* ---- badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.draft { background: var(--amber-soft); color: var(--amber); }
.badge.reviewed { background: var(--accent-soft); color: var(--accent-dark); }
.badge.sent { background: var(--green-soft); color: var(--green); }
.badge.cancelled { background: #eceff3; color: #6b7486; text-decoration: line-through; }
.badge.submitted { background: #f3e8ff; color: #7c3aed; }

/* ---- roles & comments ---- */
.role-chip {
  display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 10.5px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .5px; vertical-align: middle;
}
.role-chip.admin { background: #ffe9d6; color: #c2540a; }
.role-chip.employee { background: #e0edff; color: #1546c4; }
.comment-list { display: flex; flex-direction: column; gap: 10px; }
.comment {
  background: #f7f9fc; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; border-left: 3px solid var(--accent);
}
.comment.admin { border-left-color: #ea7317; background: #fffaf4; }
.comment-head { display: flex; gap: 8px; align-items: center; margin-bottom: 3px; font-size: 13px; }
.comment-text { font-size: 14px; white-space: pre-wrap; }
.card .split { display: flex; gap: 18px; margin-top: 4px; }
.card .sublbl { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.card .of { font-size: 15px; color: var(--muted); font-weight: 600; margin-left: 3px; }
.card.warn .num { color: var(--amber); }
.card .progress { height: 5px; background: var(--line); border-radius: 99px; margin: 6px 0 2px; overflow: hidden; }
.card .progress div { height: 100%; background: var(--green); border-radius: 99px; }
.card.warn .progress div { background: var(--amber); }
.filterbtns { display: flex; gap: 6px; }
.filterbtns a { padding: 6px 14px; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 12.5px; color: var(--muted); }
.filterbtns a.on { background: var(--ink); color: #fff; border-color: var(--ink); text-decoration: none; }
.filterbtns a:hover { text-decoration: none; border-color: #c6cdd8; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600;
  font-size: 14px; cursor: pointer; transition: all .15s ease;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .06); user-select: none;
}
.btn:hover {
  border-color: #b9c2d0; background: #f7f9fc; text-decoration: none;
  transform: translateY(-1px); box-shadow: 0 4px 12px rgba(16, 24, 40, .12);
}
.btn:active { transform: translateY(0); box-shadow: 0 1px 2px rgba(16, 24, 40, .06); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 6px rgba(31, 94, 255, .35); }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark);
  box-shadow: 0 5px 14px rgba(31, 94, 255, .40); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff;
  box-shadow: 0 2px 6px rgba(14, 159, 110, .35); }
.btn.success:hover { background: #0b8a5f; border-color: #0b8a5f;
  box-shadow: 0 5px 14px rgba(14, 159, 110, .40); }
.btn.danger { color: var(--red); border-color: #f3c1bd; }
.btn.danger:hover { background: var(--red-soft); border-color: #eda8a2; }
.btn.sm { padding: 6px 13px; font-size: 13px; border-radius: 8px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
button { font-family: inherit; }

/* ---- forms ---- */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  font: inherit; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.frow { display: grid; gap: 14px; margin-bottom: 14px; }
.frow.c2 { grid-template-columns: 1fr 1fr; }
.frow.c3 { grid-template-columns: 1fr 1fr 1fr; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---- items editor ---- */
#items-table input { padding: 7px 9px; border-radius: 7px; }
#items-table td { padding: 4px 5px; border-bottom: 0; }
#items-table th { padding: 4px 5px; }
.row-del { color: var(--red); background: none; border: 0; font-size: 17px; cursor: pointer; padding: 4px 8px; }
.totals-live {
  margin-left: auto; width: 300px; font-size: 13.5px;
}
.totals-live div { display: flex; justify-content: space-between; padding: 4px 2px; }
.totals-live .grand { font-size: 16px; font-weight: 700; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; }

/* ---- invoice preview ---- */
.inv-preview { max-width: 860px; }
.inv-head { display: flex; justify-content: space-between; border-bottom: 3px solid var(--accent); padding-bottom: 14px; margin-bottom: 16px; }
.inv-head h2 { font-size: 22px; margin: 0 0 4px; }
.inv-head .right { text-align: right; }
.tag { color: var(--accent); font-weight: 700; letter-spacing: 1px; font-size: 13px; }
.small-muted { color: var(--muted); font-size: 12.5px; }
.inv-total-row td { font-weight: 700; font-size: 15px; background: var(--accent-soft); }

/* ---- login ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1000px 600px at 20% 10%, #1c2a4a 0%, #101828 55%, #0b1120 100%);
}
.login-box {
  background: #fff; border-radius: 20px; padding: 42px 40px; width: 400px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.login-logo {
  width: 52px; height: 52px; border-radius: 14px; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; margin-bottom: 18px;
  box-shadow: 0 6px 16px rgba(31, 94, 255, .4);
}
.login-box h1 { margin: 0 0 4px; font-size: 23px; }
.login-box .sub { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.login-box input { padding: 12px 14px; font-size: 15px; border-radius: 10px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 10px; padding: 13px; font-size: 15px; }

/* ---- settings tabs ---- */
.tabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line); background: #fff; padding: 7px 15px; border-radius: 99px;
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* ---- paper invoice editor ---- */
.paper {
  background: #fff; border: 1.6px solid #1a2332; max-width: 920px;
  padding: 16px 18px 12px; box-shadow: var(--shadow); font-size: 13px;
}
.paper-title { text-align: center; font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.phead { display: grid; grid-template-columns: 1fr 1fr; align-items: stretch; }
.pleft { display: flex; flex-direction: column; }
.pleft .pbox { border: 1px solid #1a2332; padding: 6px 9px; margin-bottom: -1px; flex: 1; }
.pright { display: grid; grid-template-columns: 1fr 1fr; align-content: start; margin-left: -1px; }
.pright .pbox { border: 1px solid #1a2332; padding: 4px 8px; margin: 0 -1px -1px 0; min-height: 44px; }
.pright .pbox.span2 { grid-column: 1 / -1; }
.plbl { display: block; font-size: 10px; color: #66707f; letter-spacing: .2px; }
.ppreview { font-size: 12px; color: #333; line-height: 1.45; margin-top: 3px; }
.paper input[type=text], .paper input[type=date], .paper input[type=number],
.paper select, .paper textarea {
  border: 0; background: transparent; box-shadow: none; border-radius: 0;
  padding: 2px 0; width: 100%; font-size: 13px;
}
.paper input:focus, .paper select:focus, .paper textarea:focus {
  outline: none; box-shadow: none; background: #eef4ff;
}
.paper input.r { text-align: right; }
.ptable { width: 100%; border-collapse: collapse; margin-top: -1px; }
.ptable th { border: 1px solid #1a2332; font-size: 11px; padding: 4px 6px; background: #f4f6fa; }
.ptable td { border-left: 1px solid #1a2332; border-right: 1px solid #1a2332;
  padding: 3px 6px; vertical-align: top; }
.ptable td.c { text-align: center; padding-top: 8px; }
.ptable .taxrow td { color: #333; }
.ptable .totrow td { border-top: 1px solid #1a2332; border-bottom: 1px solid #1a2332;
  font-weight: 700; padding: 6px; font-size: 14px; }
.ptable .svc-sel { font-size: 11.5px; color: #556; margin-bottom: 2px; }
.pwords { border: 1px solid #1a2332; margin-top: -1px; padding: 5px 9px; }
.pfoot { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid #1a2332; margin-top: -1px; }

.searchbar { display: flex; gap: 10px; margin-bottom: 16px; }
.searchbar input { max-width: 320px; }
.empty { color: var(--muted); text-align: center; padding: 34px 0; }
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; }
  .nav { display: flex; } .sidebar .foot { display: none; }
  .main { padding: 18px; }
  .frow.c2, .frow.c3 { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .topbar, .btn-row, .flash { display: none !important; }
  .main { padding: 0; } .panel { border: 0; box-shadow: none; }
}

/* ===== v8: color refresh, icons, modal, back button ===== */
:root {
  --accent: #4f46e5; --accent-dark: #4338ca; --accent-soft: #e7e6ff;
  --violet: #7c3aed; --teal: #0d9488; --pink: #db2777;
}
body { background: #f3f4fc; }
.sidebar { background: linear-gradient(180deg, #312e81 0%, #1e2244 55%, #111827 100%); }
.brand span { color: #a5b4fc; }
.nav a.active { background: linear-gradient(90deg, #4f46e5, #7c3aed); box-shadow: 0 4px 14px rgba(79, 70, 229, .45); }
.nav a:hover { background: rgba(165, 180, 252, .12); }
.btn.primary { background: linear-gradient(135deg, #4f46e5, #7c3aed); border-color: transparent; box-shadow: 0 2px 8px rgba(99, 60, 235, .35); }
.btn.primary:hover { background: linear-gradient(135deg, #4338ca, #6d28d9); border-color: transparent; box-shadow: 0 6px 16px rgba(99, 60, 235, .45); }
.tabs button.active { background: linear-gradient(90deg, #4f46e5, #7c3aed); border-color: transparent; }
.filterbtns a.on { background: linear-gradient(90deg, #4f46e5, #7c3aed); border-color: transparent; }
table.grid th { background: #f3f4ff; }
.panel h2 { border-left: 3px solid var(--accent); padding-left: 10px; }
.cards .card { border-top: 3px solid #4f46e5; }
.cards .card:nth-child(2) { border-top-color: #7c3aed; }
.cards .card:nth-child(3) { border-top-color: #0d9488; }
.cards .card:nth-child(4) { border-top-color: #d97706; }
.cards .card:nth-child(5), .cards .card.hi { border-top-color: #db2777; }
.card.hi { background: linear-gradient(135deg, #eef2ff, #fdf4ff); }
.card.hi .num { color: var(--accent); }
.badge.reviewed { background: #e7e6ff; color: #4f46e5; }
.login-wrap { background: radial-gradient(1100px 700px at 15% 10%, #3730a3 0%, #1e1b4b 50%, #0b1120 100%); }
.login-logo { background: linear-gradient(135deg, #4f46e5, #7c3aed); box-shadow: 0 6px 18px rgba(99, 60, 235, .5); }

.back-btn { margin-bottom: 14px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: #4b5563; transition: all .15s; vertical-align: middle;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(16, 24, 40, .16); text-decoration: none; border-color: #b9c2d0; }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.mail { color: #fff; background: var(--green); border-color: var(--green); }
.icon-btn.mail:hover { background: #0b8a5f; }
.icon-btn.sent { color: var(--green); border-color: #b7e9d3; background: var(--green-soft); }
.icon-btn.edit { color: var(--accent); border-color: #cfcdfc; background: #f4f3ff; }
.icon-btn.ghost { visibility: hidden; }
tr.inuse td { opacity: .5; }
tr.inuse .role-chip { opacity: 1; }

/* ---- pagination bar ---- */
.pager { display: flex; gap: 28px; align-items: center; margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--line); font-size: 13.5px; color: var(--muted); flex-wrap: wrap; }
.pg-count { background: var(--accent); color: #fff; padding: 2px 9px; border-radius: 7px; font-weight: 700; }
.pg-size { width: auto; padding: 5px 8px; display: inline-block; }
.pg-nav { display: inline-flex; gap: 5px; align-items: center; }
.pg-num { min-width: 33px; height: 33px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; color: var(--ink); }
.pg-num:hover:not(:disabled) { border-color: #b9c2d0; }
.pg-num.on { background: var(--accent); color: #fff; border-color: transparent; }
.pg-num:disabled { opacity: .4; cursor: default; }
.pg-ellipsis { padding: 0 3px; }

/* ---- sidebar user card ---- */
.userbox {
  display: flex; gap: 10px; align-items: center;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, #4f46e5, #7c3aed); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; letter-spacing: .5px;
  box-shadow: 0 3px 10px rgba(99, 60, 235, .45);
}
.uname { color: #fff; font-weight: 600; font-size: 13.5px; line-height: 1.25; margin-bottom: 3px; }
.ulinks { display: flex; flex-direction: column; gap: 6px; }
.ulinks a {
  display: flex; gap: 9px; align-items: center; white-space: nowrap;
  padding: 8px 12px; border-radius: 9px; background: rgba(255, 255, 255, .06);
  color: #c6cfdc; font-size: 13px; font-weight: 600; transition: all .15s;
}
.ulinks a:hover { background: rgba(255, 255, 255, .14); color: #fff; text-decoration: none; transform: translateX(2px); }
.ulinks svg { flex: none; opacity: .8; }

/* ---- login v2 ---- */
.login-box { position: relative; overflow: hidden; padding-top: 48px; }
.login-box::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 6px;
  background: linear-gradient(90deg, #4f46e5, #7c3aed, #db2777);
}
.login-box h1 { font-size: 27px; letter-spacing: -.3px; }
.login-box .sub b { color: var(--ink); }
.login-foot {
  margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line);
  text-align: center; color: var(--muted); font-size: 12px;
}

/* ---- login v3: prominent brand ---- */
.login-box { width: 450px; padding: 48px 44px 32px; }
.login-eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: 2.5px; text-transform: uppercase;
  color: var(--accent); margin-bottom: 12px;
}
.login-title {
  font-size: 36px; line-height: 1.1; margin: 0 0 4px; letter-spacing: -.5px;
  background: linear-gradient(95deg, #312e81 10%, #7c3aed 90%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.login-app { font-size: 21px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.login-box .sub { font-size: 14.5px; margin-bottom: 28px; }

/* ---- login v4: compact card ---- */
.login-box { width: 400px; padding: 38px 34px 24px; }
.login-title { font-size: 29px; }
.login-app { font-size: 17.5px; margin-bottom: 6px; }
.login-box .sub { font-size: 13.5px; margin-bottom: 22px; }
.login-box input { padding: 10px 12px; font-size: 14px; }
.login-box .btn { padding: 11px; font-size: 14.5px; margin-top: 6px; }
.login-foot { margin-top: 18px; padding-top: 12px; }
.login-eyebrow { margin-bottom: 8px; }

/* ---- toasts ---- */
.toast {
  position: fixed; top: 18px; right: 18px; z-index: 100; max-width: 420px;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 13px 16px; border-radius: 12px; font-weight: 500; font-size: 14px;
  box-shadow: 0 10px 34px rgba(16, 24, 40, .22); animation: toast-in .3s ease;
  transition: opacity .4s;
}
.toast + .toast { top: 84px; }
.toast.ok { background: #0e9f6e; color: #fff; }
.toast.err { background: #d92d20; color: #fff; }
.toast button {
  background: none; border: 0; color: inherit; font-size: 18px; cursor: pointer;
  line-height: 1; padding: 0; opacity: .8;
}
@keyframes toast-in { from { transform: translateX(30px); opacity: 0; } }

/* ---- empty states ---- */
.empty { padding: 44px 0; font-size: 14.5px; }
.empty-ico { font-size: 34px; margin-bottom: 8px; opacity: .8; }

/* ---- print: only the invoice paper ---- */
@media print {
  .paper { border: 1.2px solid #000; box-shadow: none; max-width: none; }
  .panel, form, .back-btn, .toast { display: none !important; }
  .main .paper { display: block !important; }
}

.modal-back { position: fixed; inset: 0; background: rgba(15, 18, 40, .55); display: none; align-items: center; justify-content: center; z-index: 60; }
.modal-back.open { display: flex; }
.modal { background: #fff; border-radius: 16px; padding: 24px 28px; width: 620px; max-width: 92vw; max-height: 88vh; overflow: auto; box-shadow: 0 26px 80px rgba(0, 0, 0, .4); }
