:root {
  --side: #232155;
  --side-2: #2B2870;
  --side-active: #4F46E5;
  --accent: #4F46E5;
  --accent-dark: #4338CA;
  --accent-soft: #EEF0FF;
  --text: #101828;
  --muted: #667085;
  --border: #E4E7EC;
  --bg: #F6F7FB;
  --card: #FFFFFF;
  --ok: #059669;
  --ok-bg: #ECFDF5;
  --bad: #DC2626;
  --bad-bg: #FEF3F2;
  --warn: #D97706;
  --warn-bg: #FFFAEB;
  --r: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, 'Cascadia Mono', monospace; }
.right { text-align: right; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 244px; flex: none;
  background: linear-gradient(180deg, var(--side) 0%, var(--side-2) 100%);
  color: #C7C9E8; position: fixed; inset: 0 auto 0 0; z-index: 40;
  display: flex; flex-direction: column; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, #6366F1, #8B5CF6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 17px;
}
.brand-name { color: #fff; font-weight: 700; font-size: 15.5px; line-height: 1.15; }
.brand-sub { font-size: 11px; color: #8E8FD0; }
.side-cta { margin: 4px 14px 14px; }
.side-cta a {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: #fff; color: var(--accent-dark); font-weight: 700; font-size: 13px;
  padding: 10px 12px; border-radius: 10px; width: 100%;
}
.side-cta a:hover { background: #F4F3FF; }
.nav-label { font-size: 10.5px; letter-spacing: .8px; text-transform: uppercase; color: #7A7ABF; padding: 14px 20px 6px; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10.5px 20px;
  color: #C7C9E8; font-size: 13.5px; font-weight: 500; border-radius: 0;
  margin: 1px 10px; border-radius: 9px;
}
.nav a i { width: 17px; text-align: center; font-size: 14px; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,.4); }
.nav a.active i { opacity: 1; }
.side-foot { margin-top: auto; padding: 14px 20px; font-size: 11px; color: #6E6DB4; border-top: 1px solid rgba(255,255,255,.07); }

.main { flex: 1; margin-left: 244px; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 13px 26px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 17.5px; margin: 0; font-weight: 700; }
.topbar .spacer { flex: 1; }
.userchip { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.userchip .av {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent-dark); font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.userchip .rl { font-size: 11px; color: var(--muted); }
.burger { display: none; background: none; border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; cursor: pointer; font-size: 15px; }

.page-body { padding: 22px 26px 44px; max-width: 1400px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-h h3 { margin: 0; font-size: 15px; font-weight: 700; }
.card-h .spacer { flex: 1; }
.card-b { padding: 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--r);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat .lab { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.stat .val { font-size: 26px; font-weight: 800; margin-top: 7px; letter-spacing: -.5px; }
.stat.green { background: var(--ok-bg); border-color: #A7F3D0; } .stat.green .lab, .stat.green .val { color: var(--ok); }
.stat.red { background: var(--bad-bg); border-color: #FECACA; } .stat.red .lab, .stat.red .val { color: var(--bad); }
.stat.blue { background: var(--accent-soft); border-color: #C7D2FE; } .stat.blue .lab, .stat.blue .val { color: var(--accent-dark); }
.stat.amber { background: var(--warn-bg); border-color: #FDE68A; } .stat.amber .lab, .stat.amber .val { color: var(--warn); }

.grid2 { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.grid2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 1080px) { .grid2, .grid2.even { grid-template-columns: 1fr; } }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 700; padding: 11px 14px; background: #FAFAFC;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 12px 14px; border-bottom: 1px solid #EFF1F6; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: #FAFBFF; }
.tbl .amt { font-weight: 700; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3.5px 9px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.mut { background: #F2F4F7; color: var(--muted); }
.badge.info { background: var(--accent-soft); color: var(--accent-dark); }

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  border: 1px solid transparent; border-radius: 9px; cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 600; padding: 9px 15px;
  transition: .12s; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: #344054; }
.btn-ghost:hover:not(:disabled) { background: #F9FAFB; border-color: #D0D5DD; }
.btn-danger { background: #fff; border-color: #FECACA; color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad-bg); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 12px 20px; font-size: 14.5px; }

.search { position: relative; }
.search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }
input, select, textarea {
  font-family: inherit; font-size: 13.5px; color: var(--text);
  border: 1.5px solid var(--border); border-radius: 9px; padding: 9.5px 12px;
  background: #fff; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
input[type=color] { padding: 4px; height: 42px; }
input[type=file] { display: none; }
label { display: block; font-size: 12.5px; font-weight: 600; color: #344054; margin-bottom: 6px; }
.fg { margin-bottom: 14px; }
.fg .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } }

.modal-back {
  position: fixed; inset: 0; background: rgba(16,24,40,.5); backdrop-filter: blur(2px);
  display: none; align-items: flex-start; justify-content: center; z-index: 90; padding: 40px 16px; overflow-y: auto;
}
.modal-back.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 50px rgba(16,24,40,.25); animation: pop .16s ease;
}
.modal.wide { max-width: 780px; }
@keyframes pop { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-h { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-h h3 { margin: 0; font-size: 15.5px; font-weight: 700; display: flex; gap: 9px; align-items: center; }
.modal-x { margin-left: auto; background: none; border: 0; font-size: 17px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.modal-b { padding: 18px 20px; max-height: 65vh; overflow-y: auto; }
.modal-f { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px; border-top: 1px solid var(--border); }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty i { font-size: 30px; opacity: .4; display: block; margin-bottom: 10px; }
.loading { text-align: center; padding: 40px; color: var(--muted); }
.hintbar { background: var(--accent-soft); border: 1px solid #C7D2FE; color: var(--accent-dark); padding: 11px 14px; border-radius: 10px; font-size: 13px; }
.warnbar { background: var(--warn-bg); border: 1px solid #FDE68A; color: #92400E; padding: 11px 14px; border-radius: 10px; font-size: 13px; }
.errbar { background: var(--bad-bg); border: 1px solid #FECACA; color: var(--bad); padding: 11px 14px; border-radius: 10px; font-size: 13px; }

#toastBox { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: #101828; color: #fff; padding: 11px 16px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500; box-shadow: 0 8px 24px rgba(16,24,40,.3);
  display: flex; gap: 9px; align-items: center; animation: pop .15s ease; max-width: 380px;
}
.toast.ok { background: #047857; }
.toast.err { background: #B91C1C; }
.toast.warn { background: #B45309; }

.row-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; cursor: pointer; color: var(--muted); background: #fff; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs .tab {
  padding: 8px 15px; border-radius: 999px; border: 1.5px solid var(--border);
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; color: #344054;
}
.tabs .tab.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }

.inv-lines { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.inv-lines th { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
.inv-lines td { padding: 7px 6px; border-bottom: 1px solid #F0F1F5; }
.inv-lines input, .inv-lines select { padding: 7px 9px; font-size: 13px; }
.inv-lines .ln-tot { font-weight: 700; white-space: nowrap; text-align: right; }
.totals-box { background: #FAFAFC; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.totals-box .tr { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
.totals-box .tr.grand { border-top: 1.5px dashed #D0D5DD; margin-top: 6px; padding-top: 11px; font-size: 17px; font-weight: 800; }

.party-pick { position: relative; }
.party-pick input { font-weight: 600; }
.party-drop {
  position: absolute; top: calc(100% + 5px); left: 0; right: 0; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(16,24,40,.15);
  max-height: 230px; overflow-y: auto; z-index: 50; display: none;
}
.party-drop.open { display: block; }
.party-drop div { padding: 10px 13px; cursor: pointer; font-size: 13.5px; display: flex; justify-content: space-between; gap: 8px; }
.party-drop div:hover { background: var(--accent-soft); }
.party-drop .muted { font-size: 12px; }

.login-wrap { min-height: 100vh; display: flex; }
.login-side {
  flex: 1; background: linear-gradient(150deg, #232155 0%, #4F46E5 90%); color: #fff;
  display: flex; flex-direction: column; justify-content: center; padding: 60px; position: relative; overflow: hidden;
}
.login-side::after {
  content: ''; position: absolute; right: -120px; bottom: -120px; width: 380px; height: 380px;
  background: rgba(255,255,255,.07); border-radius: 50%;
}
.login-side h2 { font-size: 32px; margin: 18px 0 12px; }
.login-side p { color: #C7D2FE; font-size: 15px; line-height: 1.7; max-width: 420px; }
.login-side ul { list-style: none; padding: 0; margin: 22px 0 0; }
.login-side li { display: flex; gap: 10px; align-items: center; padding: 7px 0; color: #E0E7FF; font-size: 14px; }
.login-form { width: 460px; flex: none; background: #fff; display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-form .inner { width: 100%; max-width: 360px; }
.login-form h1 { font-size: 23px; margin: 0 0 6px; }
@media (max-width: 900px) { .login-side { display: none; } .login-form { width: 100%; } }

.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(16,24,40,.16); min-width: 170px; z-index: 60; padding: 5px;
}
.menu-pop a, .menu-pop button {
  display: flex; gap: 9px; align-items: center; width: 100%; padding: 9px 11px; font-size: 13.5px;
  background: none; border: 0; border-radius: 7px; cursor: pointer; color: var(--text); text-align: left; font-family: inherit;
}
.menu-pop a:hover, .menu-pop button:hover { background: #F4F4FE; }
.menu-pop .danger { color: var(--bad); }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .burger { display: block; }
  .page-body { padding: 16px 14px 40px; }
}

@media print {
  .sidebar, .topbar, .no-print, .row-actions, #toastBox { display: none !important; }
  .main { margin: 0; }
  body { background: #fff; }
  .page-body { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; }
}
