/* =====================================================================
   Business Management System - interface stylesheet
   Corporate, quiet, desktop-first. No animation beyond 120ms state
   changes; nothing here competes with the documents the app produces.
   ===================================================================== */

:root {
  /* --- palette ------------------------------------------------------ */
  --navy-900: #0e1c30;   /* sidebar */
  --navy-800: #16283f;
  --navy-700: #21374f;
  --ink:      #16202e;   /* body text */
  --ink-soft: #5a6a7f;   /* secondary text */
  --line:     #dfe5ed;   /* hairline borders */
  --line-soft:#eef2f7;
  --canvas:   #f4f6f9;   /* page background */
  --surface:  #ffffff;

  --accent:      #1b4db1;
  --accent-dark: #163e8e;
  --accent-soft: #eaf0fb;

  --green: #12704a;  --green-soft: #e7f4ee;
  --amber: #96620b;  --amber-soft: #fdf3e2;
  --red:   #a8261a;  --red-soft:   #fdecea;

  /* --- type --------------------------------------------------------- */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", "Consolas", "Liberation Mono", Menlo, monospace;

  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 32, 51, .06);
  --shadow-md: 0 4px 16px rgba(16, 32, 51, .10);

  --sidebar-w: 248px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

/* Amounts and IDs use tabular figures so columns of numbers line up. */
.num, td.num, .stat-value, .amount {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* =====================================================================
   Application shell
   ===================================================================== */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--navy-900);
  color: #cdd7e4;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
}

.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: #fff;
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
  letter-spacing: .5px;
}
.brand-text { font-size: 13.5px; font-weight: 600; line-height: 1.2; }
.brand-text small { display: block; font-weight: 400; font-size: 11px; color: #8ba0b9; }

.nav { padding: 14px 10px; flex: 1; overflow-y: auto; }
.nav-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #6d829c;
  padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: #c3cfdd;
  font-size: 13.5px;
  border-left: 2px solid transparent;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.is-active {
  background: rgba(255,255,255,.09);
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav-item .ico { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item .tag {
  margin-left: auto;
  font-size: 10px;
  color: #8ba0b9;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 3px;
  padding: 1px 5px;
}

.sidebar-foot {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 12px;
}
.who { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.who-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--navy-700); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
}
.who-name { font-size: 13px; color: #fff; font-weight: 500; }
.who-role { font-size: 11px; color: #8ba0b9; }

/* --- main column ---------------------------------------------------- */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 16px; }
.topbar .crumb { color: var(--ink-soft); font-size: 12.5px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.page { padding: 24px; max-width: 1360px; width: 100%; }
.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 18px;
}
.page-head .sub { color: var(--ink-soft); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }

/* =====================================================================
   Cards, tables, forms
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 18px; }
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 12px;
}
.card-head .sub { color: var(--ink-soft); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
  background: #fbfcfe;
  display: flex; align-items: center; gap: 8px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-soft);
}
.stat-value { font-size: 26px; font-weight: 600; margin-top: 6px; letter-spacing: -.02em; }
.stat-note { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  white-space: nowrap;
}
table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tbody tr:hover { background: #fafbfd; }
table.data td.right, table.data th.right { text-align: right; }
table.data .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-soft);
}
.empty .ico { width: 34px; height: 34px; color: #b6c1d0; margin-bottom: 10px; }
.empty h3 { color: var(--ink); margin-bottom: 4px; }

/* --- forms ---------------------------------------------------------- */
.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  margin-bottom: 5px;
  color: #2c3a4c;
}
.field .hint { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }
.field .err  { font-size: 11.5px; color: var(--red); margin-top: 4px; }

input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input.has-error, select.has-error, textarea.has-error { border-color: var(--red); }
textarea { min-height: 82px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #7b8798 50%), linear-gradient(135deg, #7b8798 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 18px; }

/* --- buttons -------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px;
  font: inherit; font-size: 13.5px; font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn:hover { text-decoration: none; }
.btn .ico { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-default { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-default:hover { background: #f7f9fc; border-color: #c9d3e0; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: #f0f3f8; color: var(--ink); }
.btn-danger { background: #fff; color: var(--red); border-color: #f0c9c5; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* --- badges --------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid transparent;
}
.badge-green { background: var(--green-soft); color: var(--green); border-color: #cbe6da; }
.badge-grey  { background: #f1f4f8; color: var(--ink-soft); border-color: var(--line); }
.badge-blue  { background: var(--accent-soft); color: var(--accent-dark); border-color: #cfdcf6; }
.badge-amber { background: var(--amber-soft); color: var(--amber); border-color: #f0dcb8; }

/* --- notices -------------------------------------------------------- */
.notice {
  display: flex; gap: 11px;
  padding: 13px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fbfcfe;
  font-size: 13px;
  margin-bottom: 16px;
}
.notice .ico { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice strong { display: block; margin-bottom: 2px; }
.notice-amber { background: var(--amber-soft); border-color: #f0dcb8; color: #6b460a; }
.notice-blue  { background: var(--accent-soft); border-color: #cfdcf6; color: #12336f; }
.notice-red   { background: var(--red-soft); border-color: #f0c9c5; color: #7d1c13; }

/* --- toasts --------------------------------------------------------- */
.toast-stack {
  position: fixed; top: 16px; right: 16px;
  z-index: 90;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 380px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 12px 14px;
  font-size: 13px;
}
.toast .ico { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.toast.success { border-left-color: var(--green); color: #10432f; }
.toast.error   { border-left-color: var(--red);   color: #7d1c13; }
.toast.warning { border-left-color: var(--amber); color: #6b460a; }
.toast.info    { border-left-color: var(--accent); color: #12336f; }
.toast button { background: none; border: 0; cursor: pointer; color: inherit; opacity: .5; margin-left: auto; font-size: 15px; line-height: 1; }
.toast button:hover { opacity: 1; }

/* --- search & pagination -------------------------------------------- */
.searchbar { position: relative; }
.searchbar .ico {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--ink-soft);
}
.searchbar input { padding-left: 32px; min-width: 260px; }

.pagination {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px; color: var(--ink-soft);
}
.pagination .pages { margin-left: auto; display: flex; gap: 4px; }
.pagination a, .pagination span.cur {
  padding: 4px 9px; border-radius: 4px;
  border: 1px solid var(--line); color: var(--ink);
}
.pagination a:hover { background: #f5f8fc; text-decoration: none; }
.pagination span.cur { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- permission matrix ---------------------------------------------- */
.perm-group { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.perm-group > header {
  padding: 9px 14px;
  background: #fbfcfe;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: #35465c;
  display: flex; align-items: center; gap: 10px;
}
.perm-group > header .btn { margin-left: auto; }
.perm-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 2px 18px;
  padding: 12px 14px;
}
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* --- placeholder module screen -------------------------------------- */
.placeholder {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 56px 32px;
  text-align: center;
}
.placeholder .ico { width: 36px; height: 36px; color: #aab6c6; }
.placeholder h2 { margin: 14px 0 6px; font-size: 17px; }
.placeholder p { color: var(--ink-soft); max-width: 460px; margin: 0 auto; }

/* --- utility -------------------------------------------------------- */
.muted { color: var(--ink-soft); }
.small { font-size: 12.5px; }
.mt-0 { margin-top: 0; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.divider { height: 1px; background: var(--line-soft); margin: 18px 0; }
form.inline { display: inline; }

/* =====================================================================
   Responsive - the app is desktop-first, tablet-friendly
   ===================================================================== */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .15s ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-md); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex !important; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .searchbar input { min-width: 0; width: 100%; }
}
.menu-toggle { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* =====================================================================
   Tabs
   ===================================================================== */
.tabs { display: flex; gap: 2px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab {
  padding: 9px 16px;
  font-size: 13.5px; font-weight: 500;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* =====================================================================
   Filter bar
   ===================================================================== */
.card-head.filters { padding: 12px 18px; }
.filter-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; }
.filter-form input[type=date],
.filter-form input[type=number],
.filter-form select { width: auto; min-width: 130px; }

/* =====================================================================
   Cash Bill editor
   ===================================================================== */
.editor-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 236mm;
  gap: 22px;
  align-items: start;
}
@media (max-width: 1500px) {
  .editor-split { grid-template-columns: minmax(0, 1fr); }
  .editor-preview { display: none; }   /* the form comes first on smaller screens */
}

.editor-form .card + .card { margin-top: 16px; }
.editor-actions { margin-top: 16px; display: flex; gap: 8px; }

table.items-table th { background: #fbfcfe; }
table.items-table td { padding: 6px 8px; vertical-align: middle; }
table.items-table input {
  padding: 7px 9px;
  font-size: 13px;
}
table.items-table input.right { text-align: right; }
table.items-table .i-amount { font-weight: 600; white-space: nowrap; }
table.items-table .drag-cell {
  cursor: grab; color: #b3becd; text-align: center; user-select: none; font-size: 15px;
}
table.items-table .item-row.dragging { opacity: .45; background: var(--accent-soft); }
.running-total { margin-left: auto; display: flex; align-items: baseline; gap: 10px; font-size: 15px; }
.running-total strong { font-size: 18px; }

/* --- customer autocomplete --- */
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 260px; overflow-y: auto;
}
.ac-item {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; cursor: pointer;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  font: inherit;
}
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item:focus { background: var(--accent-soft); }
.ac-name { display: block; font-size: 13.5px; font-weight: 500; color: var(--ink); }
.ac-address { display: block; font-size: 12px; color: var(--ink-soft); }

/* --- live preview pane --- */
.editor-preview { position: sticky; top: calc(var(--topbar-h) + 16px); }
.preview-head {
  display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 8px;
}
.preview-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft); }
.preview-frame {
  background: #e8ecf2;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  max-height: calc(100vh - 190px);
  overflow: auto;
}
.preview-frame .sheet {
  transform: scale(.62);
  transform-origin: top left;
  margin-bottom: -113mm;   /* pull the page up after scaling */
  box-shadow: 0 2px 12px rgba(16,32,51,.14);
}
.preview-note { margin: 8px 0 0; }

/* =====================================================================
   Diagnostics
   ===================================================================== */
.check-row { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.check-row:last-child { border-bottom: 0; }
.check-icon { width: 20px; flex: none; }
.check-icon.ok  { color: var(--green); }
.check-icon.bad { color: var(--red); }
.check-icon.warn{ color: var(--amber); }
.check-body { flex: 1; }
.check-label { font-size: 13.5px; font-weight: 500; }
.check-value { font-size: 12.5px; color: var(--ink-soft); }
.check-fix {
  font-size: 12.5px; color: #6b460a;
  background: var(--amber-soft); border: 1px solid #f0dcb8;
  border-radius: 5px; padding: 7px 10px; margin-top: 6px;
}
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }

/* Clickable settings tiles */
a.stat.tile { display: block; color: inherit; text-decoration: none; transition: border-color .12s ease, box-shadow .12s ease; }
a.stat.tile:hover { border-color: #c3d0e4; box-shadow: var(--shadow-sm); text-decoration: none; }
a.stat.tile .ico { width: 18px; height: 18px; color: var(--ink-soft); }
