:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #172033;
  --muted: #6d7890;
  --line: #e6ebf3;
  --green: #16a34a;
  --green-dark: #12803c;
  --green-soft: #e8f7ee;
  --shadow: 0 12px 32px rgba(23, 32, 51, 0.06);
  --amber: #9a6700;
  --amber-bg: #fff6e8;
  --red: #c24141;
  --blue: #3b6d9a;
  --radius: 18px;
  --sidebar: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Manrope, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
a.name-link { color: var(--blue); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
a.name-link:hover { color: var(--green-dark); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.45; }
.right { text-align: right; }
.neg { color: var(--red); }
.pos { color: var(--green-dark); }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 400px at 10% -10%, #e7f8ee, transparent 50%),
    var(--bg);
}
.login-card, .card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card {
  width: min(420px, 100%);
  padding: 32px;
}
.login-card h1 { margin: 14px 0 4px; font-size: 28px; }
.login-card label, .form label { display: block; font-size: 13px; color: var(--muted); margin-top: 14px; }
.login-card input, .form input, .form select, .form textarea, .filters input, .filters select, .search-wrap input, .setup-add input, .setup-add select {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
.login-card input:focus, .form input:focus, .form select:focus, .filters input:focus, .filters select:focus, .search-wrap input:focus, .setup-add input:focus, .setup-add select:focus {
  border-color: #b7e4c7;
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.12);
}
.form-error { color: var(--red); min-height: 1.2em; font-size: 13px; }

.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 18px 14px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 18px; }
.brand strong, .brand span { display: block; }
.brand span, .nav-label { color: var(--muted); font-size: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px;
  background: var(--green); color: white;
  display: grid; place-items: center; font-weight: 800;
}
.nav-label { margin: 16px 10px 6px; letter-spacing: .04em; text-transform: uppercase; }
nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; margin: 2px 0;
  color: #334155; font-weight: 600; font-size: 14px;
}
nav a.active { background: var(--green-soft); color: var(--green-dark); }
nav a:hover { background: #f6f8fb; }
.ico { width: 22px; text-align: center; color: var(--muted); font-size: 13px; }
nav a.active .ico { color: var(--green-dark); }

.workspace, main, .card, .split, .triple, .kpis, .table-wrap { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 22px 0;
}
.search-wrap { position: relative; flex: 1; }
.search-wrap input { margin: 0; background: #fff; border-radius: 999px; padding: 12px 16px; }
.search-results {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px);
  background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 8px;
  max-height: 360px; overflow: auto;
}
.search-results a, .search-results button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 8px 10px; border-radius: 10px;
}
.search-results a:hover, .search-results button:hover { background: #f4f7fb; }
.search-results small { color: var(--muted); display: block; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: 999px; padding: 8px 12px 8px 8px;
  box-shadow: var(--shadow); white-space: nowrap;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--green-soft);
  color: var(--green-dark); display: grid; place-items: center; font-weight: 800;
  object-fit: cover; flex: none;
}
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.icon-btn { display: none; border: 0; background: #fff; border-radius: 12px; padding: 10px 12px; }

main { padding: 18px 22px 40px; }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 28px; letter-spacing: -0.03em; }
.page-head p { margin: 4px 0 0; }
.page-head .no-print { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 14px; font-weight: 700;
}
.btn.primary { background: var(--green); border-color: var(--green); color: white; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters.filters-top { align-items: flex-start; }
.filters label, .filters .filter-field { font-size: 12px; color: var(--muted); min-width: 140px; }
.filters .filter-field { display: flex; flex-direction: column; flex: 0 0 auto; width: max-content; min-width: 0; }
.filters .filter-field > span { display: block; }
.filters .checks {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 16px;
  margin: 6px 0 0;
  width: max-content;
  height: 41px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.filters .checks label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: none;
  width: auto;
  min-width: 0;
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  line-height: 1;
  color: var(--ink);
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
th.pick-col, td.pick-col { width: 36px; text-align: center; }
th.pick-col input, td.pick-col input { width: 16px; height: 16px; margin: 0; accent-color: var(--green); }
.bulk-apply { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 12px; }
.bulk-apply > input { width: 16px; height: 16px; flex: none; margin: 12px 0 0; accent-color: var(--green); }
.bulk-apply > span { flex: 1; min-width: 0; display: grid; gap: 6px; font-weight: 700; }
.filters .checks input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex: none;
  margin: 0;
  padding: 0;
  accent-color: var(--green);
}
.filters .grow { flex: 1; min-width: 180px; }

.kpis, .split, .triple { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, 1fr); margin-bottom: 14px; }
.kpis.cols-3 { grid-template-columns: repeat(3, 1fr); }
.kpis.cols-2 { grid-template-columns: repeat(2, 1fr); }
.kpis.cols-1 { grid-template-columns: 1fr; }
.card { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 700; }
.kpi .value { font-size: 28px; font-weight: 800; letter-spacing: -0.04em; margin: 6px 0; }
.kpi .foot { color: var(--muted); font-size: 12px; line-height: 1.45; }
.kpi .foot span { display: block; }
.kpi.open { background: linear-gradient(#fff, #fff) padding-box, linear-gradient(180deg, #f3d19a, transparent) border-box; border: 1px solid #f3d19a; }
.flag {
  display: inline-block; background: var(--amber-bg); color: var(--amber);
  border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 800; margin-left: 6px;
}
.note {
  background: var(--amber-bg); color: #7a5410; border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; font-size: 13px;
}
.triple { grid-template-columns: 1.1fr .9fr 1fr; margin-bottom: 14px; }
.split { grid-template-columns: 1.2fr .8fr; margin-bottom: 14px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.section-title h2 { margin: 0; font-size: 16px; }

.chart { width: 100%; max-width: 100%; height: auto; display: block; }
.money-in { color: var(--green-dark); }
.money-out { color: var(--red); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 99px; display: inline-block; margin-right: 6px; }
.donut-wrap { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 12px; align-items: center; }
.donut { width: 132px; height: 132px; border-radius: 50%; }
.cat-legend { min-width: 0; }
.legend-row {
  display: grid; grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: 8px; align-items: center; margin: 7px 0; font-size: 13px;
}
.legend-row .swatch { margin: 0; }
.legend-row span { min-width: 0; }
.donut-hole {
  width: 72px; height: 72px; border-radius: 50%; background: #fff; margin: 30px;
}
.bar-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(48px, 1fr) auto; gap: 8px; align-items: center; margin: 8px 0; font-size: 13px; }
.bar { height: 8px; background: #eef2f7; border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.gauge { width: 100%; height: 110px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.sortable { cursor: pointer; }
th.sortable .sort-head { display: inline-flex; align-items: center; gap: 6px; }
th.sortable .sort-arrows {
  display: inline-flex; flex-direction: column; align-items: center;
  font-size: 9px; line-height: 1; color: #8b95a8; font-weight: 700;
}
th.sortable:hover .sort-arrows { color: var(--ink); }
th.sortable.sorted { color: var(--ink); }
th.sortable.sorted .sort-arrows .on { color: var(--green-dark); }
td { padding: 9px 8px; border-bottom: 1px solid #f1f4f8; vertical-align: top; }
td.note { max-width: 240px; white-space: normal; color: var(--ink); }
tr:hover td { background: #fbfcfe; }
.table-wrap { overflow: auto; max-width: 100%; }
th.row-edit, td.row-edit { position: sticky; right: 0; background: #fff; z-index: 1; box-shadow: -8px 0 8px rgba(255,255,255,.9); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.tag { border-radius: 999px; padding: 2px 8px; background: #f3f6fb; font-size: 12px; font-weight: 700; }
.tag.sale { background: #e8f7ee; color: var(--green-dark); }
.tag.return, .tag.discount { background: #fdecec; color: var(--red); }

.modal-back {
  position: fixed; inset: 0; background: rgba(23, 32, 51, .35);
  display: grid; place-items: center; padding: 18px; z-index: 40;
}
.modal {
  width: min(760px, 100%); max-height: min(90vh, 860px); overflow: auto;
  background: #fff; border-radius: 20px; padding: 20px; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.line-table input, .line-table select { width: 100%; padding: 8px; border-radius: 10px; border: 1px solid var(--line); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.statement-head { display: flex; justify-content: space-between; gap: 12px; }
.statement-head h2 { margin: 0; }
.account-strip { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.account-strip h2 { margin: 0; font-size: 18px; }
.strip-metrics { display: flex; gap: 18px; flex-wrap: wrap; }
.strip-metrics small { display: block; color: var(--muted); font-size: 11px; }
.strip-metrics strong { font-size: 16px; }

.cash-entry .entry-date { display: block; max-width: 280px; margin: 0 0 14px; font-size: 13px; font-weight: 700; }
.cash-entry .bill-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-bottom: 14px;
}
.cash-entry .bill-fields label { margin-top: 0; color: var(--ink); font-weight: 700; }
.entry-date input, .entry-grid input, .entry-grid select {
  width: 100%;
  margin-top: 6px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.entry-grid td { vertical-align: middle; }
.entry-grid tr:hover td { background: transparent; }
.entry-grid input, .entry-grid select { margin-top: 0; }
.entry-actions { justify-content: flex-end; align-items: center; }
.entry-actions #add-line { margin-right: auto; }
.account-pick { position: relative; min-width: 0; }
.account-menu {
  position: fixed; z-index: 80; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; padding: 6px;
  overflow-anchor: none;
}
.account-group { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 800; padding: 8px 8px 2px; }
.account-option {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px; width: 100%;
  text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 7px 8px; font-size: 13px;
  cursor: pointer;
}
.account-option span { min-width: 0; }
.account-option small { color: var(--muted); flex: none; }
.account-option:hover { background: #f4f7fb; }
.account-option.active, .account-option.active:hover { background: var(--green-soft); }
.account-empty { padding: 8px; color: var(--muted); font-size: 13px; }
.form input[readonly], .entry-grid input[readonly] { background: #f4f7fb; color: var(--ink); }
.entry-grid input[name=qty],
.entry-grid input[name=rate],
.entry-grid input[name=amount] { text-align: right; font-weight: 700; }
.entry-grid input[name=moneyIn] { color: var(--green-dark); font-weight: 700; text-align: right; }
.entry-grid input[name=moneyOut] { color: var(--red); font-weight: 700; text-align: right; }
.entry-grid tfoot td { border-bottom: 0; font-weight: 800; }
.cash-entry .line-x { color: var(--muted); font-size: 16px; line-height: 1; padding: 6px 10px; }
.flow-section td { background: #f6f8fb; font-weight: 800; padding-top: 14px; }
.flow-line { padding-left: 18px !important; }
.flow-total td { font-weight: 800; border-top: 1px solid var(--line); }
.users-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(480px, 1fr);
  gap: 14px;
  align-items: start;
}
.user-card h2 { margin: 0 0 8px; font-size: 18px; }
.user-card th, .user-card td { padding: 8px 6px; }
.user-card .form label { margin-top: 6px; }
.user-card .form .grid-2 { gap: 6px 10px; }
.user-card .form input, .user-card .form select { margin-top: 3px; padding: 6px 10px; }
.user-line { display: flex; align-items: center; gap: 10px; }
.user-actions { white-space: nowrap; }
.user-actions .btn + .btn { margin-left: 6px; }
.photo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 0; }
.user-card .avatar.lg { width: 52px; height: 52px; font-size: 18px; }
.photo-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.photo-label { font-size: 13px; color: var(--muted); font-weight: 700; }
.photo-btn { position: relative; overflow: hidden; margin: 0; }
.form .photo-btn input, .photo-btn input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; border-radius: 0; opacity: 0; cursor: pointer;
}
.page-access { margin-top: 6px; overflow: visible; }
.page-access h3 { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 700; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: 8px 12px; }
.pick-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.form .pick-grid label, .pick-grid label {
  display: flex; align-items: center; gap: 8px; margin: 0; min-height: 24px; min-width: 0;
  color: var(--ink); font-weight: 650; line-height: 1.25;
}
.mode-switch { display: flex; flex: none; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.mode-switch button { border: 0; background: transparent; padding: 3px 8px; font-size: 11px; font-weight: 800; color: var(--muted); }
.mode-switch button.on { background: var(--green-soft); color: var(--green-dark); }
.mode-switch.off { opacity: 0.4; }
.setup-card { margin-bottom: 14px; }
.setup-card .section-title h2 { font-size: 18px; }
.setup-add {
  display: flex; align-items: flex-end; gap: 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}
.setup-add label { flex: 1; margin: 0; min-width: 140px; font-size: 13px; color: var(--muted); font-weight: 700; }
.setup-add .btn { flex: none; }
.form .pick-grid input, .pick-grid input {
  width: 16px; height: 16px; flex: none; margin: 0; padding: 0; border: 0; border-radius: 0;
}
.user-card .actions { justify-content: flex-start; margin-top: 8px; }
.cash-entry #total-in { color: var(--green-dark); }
.cash-entry #total-out { color: var(--red); }
.cash-entry .btn.primary { margin-top: 8px; }

@media (max-width: 1100px) {
  .kpis, .kpis.cols-3, .kpis.cols-2, .triple { grid-template-columns: 1fr 1fr; }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 30; transform: translateX(-105%);
    width: min(280px, 88vw); height: 100vh; transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .icon-btn { display: inline-flex; }
  .kpis, .kpis.cols-3, .kpis.cols-2, .triple, .grid-2, .split, .users-layout { grid-template-columns: 1fr; }
  .topbar, main { padding-left: 14px; padding-right: 14px; }
  .topbar { gap: 8px; }
  .filters label { flex: 1 1 calc(50% - 10px); min-width: 0; }
  .filters .filter-field { flex: 0 0 auto; width: max-content; max-width: 100%; min-width: 0; }
  .page-head h1 { font-size: 24px; }
  .page-head .no-print { display: flex; flex-wrap: wrap; gap: 8px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .kpi .value { font-size: 24px; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
}
@media (max-width: 640px) {
  .user-chip .user-meta { display: none; }
  .cash-entry .bill-fields { grid-template-columns: 1fr; }
  .setup-add { flex-direction: column; align-items: stretch; }
  .setup-add label { min-width: 0; }
}
@media print {
  .sidebar, .topbar, .filters, .no-print, .icon-btn { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  body { background: white; }
  .card { box-shadow: none; }
}
