* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; background: #f4f5f7; color: #1c2430; font-size: 14px; }
.hidden { display: none !important; }
.error { color: #c0392b; min-height: 1em; }
.ok { color: #1e8449; }

#login-screen { display: flex; height: 100vh; }
.login-left { flex: 1.2; position: relative; overflow: hidden; display: flex; flex-direction: column;
  justify-content: center; padding: 56px 64px; color: #eaf2fb;
  background: linear-gradient(140deg, #101d33 0%, #16304f 55%, #1b4468 100%); }
.login-mark { position: absolute; right: -110px; bottom: -110px; width: 460px; opacity: .14;
  transform: rotate(-8deg); pointer-events: none; }
.login-left-text { position: relative; max-width: 480px; }
.login-left-text h1 { margin: 0 0 14px; font-size: 38px; line-height: 1.15; color: #fff; letter-spacing: -.5px; }
.login-left-text p { margin: 0 0 26px; font-size: 16px; color: #b7c8dd; line-height: 1.55; }
#login-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
#login-points li { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.09);
  border-radius: 10px; padding: 11px 16px; font-size: 14px; backdrop-filter: blur(2px); }
.login-foot { position: absolute; bottom: 20px; left: 64px; font-size: 12px; color: #6f83a0; margin: 0; }
.login-right { flex: 1; display: flex; align-items: center; justify-content: center;
  background: #f4f7fb; padding: 24px; }
.login-box { background: #fff; padding: 38px 36px 30px; border-radius: 16px;
  box-shadow: 0 12px 40px rgba(16,29,51,.12); width: 360px; display: flex; flex-direction: column; gap: 13px; }
.login-word { width: 210px; margin: 0 auto 6px; display: block; }
.login-box h1 { margin: 0 0 4px; font-size: 19px; text-align: center; color: #16304f; }
.login-box label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; color: #33415a; }
.login-box input { padding: 10px 12px; border: 1px solid #cbd5e3; border-radius: 8px; font-size: 14px; }
.login-box input:focus { outline: none; border-color: #2d75bb; box-shadow: 0 0 0 3px rgba(45,117,187,.14); }
.login-box button { padding: 11px; border-radius: 8px; font-size: 14px; margin-top: 4px;
  background: linear-gradient(120deg, #2d75bb, #3bbfad); }
@media (max-width: 860px) {
  #login-screen { flex-direction: column; }
  .login-left { flex: none; padding: 34px 26px 30px; }
  .login-left-text h1 { font-size: 26px; }
  #login-points, .login-foot, .login-mark { display: none; }
  .login-right { flex: 1; align-items: flex-start; padding-top: 30px; }
  .login-box { width: 100%; max-width: 380px; }
}

#app { display: flex; min-height: 100vh; }
#sidebar { width: 190px; background: #182234; color: #dfe6f0; padding: 16px 0; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; z-index: 60; }
#sidebar h2 { margin: 0 16px 14px; font-size: 17px; color: #fff; }
#sidebar a { color: #b9c4d6; text-decoration: none; padding: 9px 16px; display: block; }
#sidebar a.active, #sidebar a:hover { background: #24334d; color: #fff; }
.nav-item.has-fly { position: relative; }
.nav-group-h { padding: 9px 16px; color: #b9c4d6; cursor: pointer; user-select: none;
  display: flex; justify-content: space-between; align-items: center; }
.has-fly:hover > .nav-group-h, .has-fly.open > .nav-group-h, .has-fly.active > .nav-group-h {
  background: #24334d; color: #fff; }
.has-fly.active > .nav-group-h { box-shadow: inset 3px 0 0 #4d8be8; }
.nav-fly { display: none; position: absolute; left: 100%; top: 0; min-width: 195px;
  background: #20304a; border-radius: 0 8px 8px 0; box-shadow: 4px 4px 16px rgba(0,0,0,.35);
  padding: 4px 0 6px; z-index: 200; }
.nav-fly-title { padding: 8px 16px 6px; font-size: 10.5px; letter-spacing: .09em;
  text-transform: uppercase; color: #7d8aa3; }
.has-fly:hover > .nav-fly, .has-fly.open > .nav-fly { display: block; }
.nav-fly a { padding: 8px 16px; }
.nav-bottom { margin-top: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; font-size: 12px; }

main { flex: 1; padding: 20px 24px; max-width: calc(100vw - 190px); }
h1.page { font-size: 20px; margin: 0 0 14px; }

.cards { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.card { background: #fff; border-radius: 8px; padding: 14px 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06); min-width: 170px; }
.card .k { font-size: 12px; color: #6b7686; }
.card .v { font-size: 19px; font-weight: 700; margin-top: 4px; }
.card .v.neg { color: #c0392b; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=text], .toolbar select { padding: 6px 8px; border: 1px solid #cbd3dd; border-radius: 6px; }
button { background: #2456a6; color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; cursor: pointer; font-size: 13px; }
button.secondary { background: #e4e9f0; color: #1c2430; }
button.danger { background: #c0392b; }
button:disabled { opacity: .5; cursor: default; }

.tbl-wrap { background: #fff; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.06); overflow: auto; max-height: 72vh; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 9px; border-bottom: 1px solid #edf0f4; text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: #f0f3f7; font-weight: 600; z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.neg { color: #c0392b; }
tr.total td { font-weight: 700; background: #f7f9fb; }
tr:hover td { background: #f7fafd; }
.badge { padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.badge.yes { background: #d9f2e2; color: #1e8449; }
.badge.no { background: #fbdedb; color: #c0392b; }
.badge.st-red { background: #fbdedb; color: #b03a2e; }
.badge.st-amber { background: #fdf0d3; color: #9a6d00; }
.badge.st-green { background: #d9f2e2; color: #1e8449; }
.badge.st-blue { background: #dbe9fb; color: #21618c; }
.badge.st-grey { background: #e9edf2; color: #5d6b7c; }

/* rows with missing info */
tr.warn td { background: #fff7e8; }
tr.warn:hover td { background: #fdefd2; }
.sticky-cols tr.warn td:nth-child(-n+3) { background: #fff7e8; }
.sticky-cols tr.warn:hover td:nth-child(-n+3) { background: #fdefd2; }

.form-panel { background: #fff; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.06); padding: 14px 16px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: #46505e; }
.form-grid input, .form-grid select { padding: 6px 8px; border: 1px solid #cbd3dd; border-radius: 6px; font-size: 13px; width: 100%; }
.form-actions { margin-top: 12px; display: flex; gap: 8px; align-items: center; }

.section { margin-bottom: 26px; }
.section h2 { font-size: 16px; margin: 0 0 8px; }
.muted { color: #6b7686; font-size: 12px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.settings-lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.list-box { background: #fff; border-radius: 8px; padding: 12px 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.list-box ul { list-style: none; margin: 8px 0; padding: 0; max-height: 260px; overflow: auto; }
.list-box li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid #f0f3f7; }
.list-box li button { padding: 0 8px; font-size: 12px; }
.inline-add { display: flex; gap: 6px; }
.inline-add input { flex: 1; padding: 5px 8px; border: 1px solid #cbd3dd; border-radius: 6px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .grid2 { grid-template-columns: 1fr; } }
.panel { background: #fff; border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.panel h3 { margin: 0 0 10px; font-size: 14px; color: #46505e; }

.hbars { display: flex; flex-direction: column; gap: 7px; }
.hbar-row { display: grid; grid-template-columns: 150px 1fr 100px; gap: 8px; align-items: center; font-size: 12px; }
.hbar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: #f0f3f7; border-radius: 4px; height: 14px; }
.hbar-fill { height: 100%; border-radius: 4px; min-width: 2px; }
.hbar-val { text-align: right; font-variant-numeric: tabular-nums; }

/* frozen identity columns (SR No, date, whom) while scrolling wide tables */
.sticky-cols th:nth-child(-n+3), .sticky-cols td:nth-child(-n+3) { position: sticky; z-index: 2; }
.sticky-cols th:nth-child(-n+3) { z-index: 4; }
.sticky-cols td:nth-child(-n+3) { background: #fff; }
.sticky-cols tr:hover td:nth-child(-n+3) { background: #f7fafd; }
.sticky-cols th:nth-child(-n+3) { overflow: hidden; text-overflow: ellipsis; }
.sticky-cols th:nth-child(1), .sticky-cols td:nth-child(1) { left: 0; min-width: 56px; max-width: 56px; }
.sticky-cols th:nth-child(2), .sticky-cols td:nth-child(2) { left: 56px; min-width: 96px; max-width: 96px; }
.sticky-cols th:nth-child(3), .sticky-cols td:nth-child(3) { left: 152px; min-width: 160px; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; border-right: 2px solid #dde3ea; }

/* autocomplete dropdown under the Particulars input */
.ac-list { position: absolute; top: 100%; left: 0; min-width: 340px; max-width: 480px; background: #fff;
  border: 1px solid #cbd3dd; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12);
  z-index: 30; max-height: 240px; overflow: auto; font-weight: 400; }
.ac-item { padding: 7px 10px; cursor: pointer; font-size: 12px; border-bottom: 1px solid #f0f3f7; }
.ac-item:hover { background: #eef4fb; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 38, .45); z-index: 100;
  display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 10px; padding: 20px 22px; width: 420px; max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 8px; font-size: 15px; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; margin-top: 8px; }
.modal input[type=date] { padding: 7px 9px; border: 1px solid #cbd3dd; border-radius: 6px; }

.doc-link { white-space: nowrap; text-decoration: none; color: #2456a6; }
.multi-ref { white-space: normal; display: inline-block; line-height: 1.5; }
.doc-link:hover { text-decoration: underline; }

td.cellclick { cursor: pointer; }
td.cellclick:hover { background: #e8f0fb !important; text-decoration: underline; }
#drill-panel { border-left: 4px solid #2456a6; }

/* account chooser */
#chooser-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.chooser-box { background: #fff; padding: 34px 38px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.08);
  width: 460px; max-width: 94vw; text-align: center; }
.chooser-box h1 { margin: 0 0 18px; font-size: 20px; }
.chooser-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.chooser-item { display: flex; flex-direction: column; gap: 3px; padding: 14px 18px; border-radius: 10px;
  border: 1px solid #dbe2ea; background: #f7f9fc; cursor: pointer; text-align: left; color: #1c2430; }
.chooser-item:hover { background: #eaf1fa; border-color: #2456a6; }
.chooser-name { font-size: 16px; font-weight: 700; }
.chooser-sub { font-size: 12px; color: #6b7686; }
.switch-btn { margin: 0 16px 12px; background: #24334d; font-size: 12px; padding: 5px 10px; }

/* dashboard extras */
.card.clickable { cursor: pointer; }
.card.clickable:hover { box-shadow: 0 2px 10px rgba(36,86,166,.25); }
.card .v.amb { color: #b9770e; }
.modal-wide { width: 640px; }

a.btn-link { display: inline-block; background: #e4e9f0; color: #1c2430; border-radius: 6px;
  padding: 7px 14px; font-size: 13px; text-decoration: none; margin-left: auto; }
a.btn-link:hover { background: #d5dde8; }
.pending-tag { color: #b9770e; font-weight: 600; }
.chooser-mini { padding: 9px 14px; background: #eef7f0; border-color: #bfe3c8; }
.chooser-mini:hover { background: #ddf0e2; border-color: #1e8449; }

/* dashboard v2: headline numbers + needs-attention list */
.card.hero { min-width: 210px; border-left: 4px solid #2456a6; }
.card.hero .v { font-size: 24px; }
.card.hero.good { border-left-color: #1e8449; }
.card.hero.warn { border-left-color: #b9770e; }
.card.hero.bad { border-left-color: #c0392b; }
.attn { display: flex; flex-direction: column; gap: 8px; }
.attn-item { display: flex; align-items: center; gap: 10px; padding: 9px 13px; border-radius: 8px;
  background: #fdf3e7; border: 1px solid #f0dcbc; font-size: 13.5px; }
.attn-item.bad { background: #fbeceb; border-color: #efc4c0; }
.attn-item.ok { background: #edf7ef; border-color: #c4e3cb; }
.attn-item .act { margin-left: auto; white-space: nowrap; }
.attn-item.linky { cursor: pointer; }
.attn-item.linky:hover { filter: brightness(.97); }

/* inline loading spinner */
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid #cbd3dd;
  border-top-color: #2456a6; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* freeze the first column (invoice register etc.) */
.sticky-first th:nth-child(1), .sticky-first td:nth-child(1) {
  position: sticky; left: 0; z-index: 2; background: #fff; min-width: 250px; max-width: 330px; }
.sticky-first th:nth-child(1) { z-index: 4; background: #eef2f7; }
.sticky-first tr:hover td:nth-child(1) { background: #f7fafd; }

/* unpaid ledger rows stand out a little (light red) */
tr.unpaid:not(.warn) td { background: #fdf0ee; }
tr.unpaid:not(.warn):hover td { background: #fae1dd; }
.sticky-cols tr.unpaid:not(.warn) td:nth-child(-n+3) { background: #fdf0ee; }
.sticky-cols tr.unpaid:not(.warn):hover td:nth-child(-n+3) { background: #fae1dd; }

/* full-screen busy overlay: blocks every click while a slow action runs */
#busy-overlay { position: fixed; inset: 0; z-index: 3000; background: rgba(24, 34, 52, .45);
  display: flex; align-items: center; justify-content: center; cursor: wait; }
#busy-overlay .busy-box { background: #fff; border-radius: 10px; padding: 18px 26px; font-size: 14.5px;
  box-shadow: 0 6px 30px rgba(0,0,0,.25); display: flex; align-items: center; gap: 12px; }
#busy-overlay .spin.big { width: 20px; height: 20px; border-width: 3px; }

/* frozen invoice column: wrap long labels/chips inside the column width */
.sticky-first td:nth-child(1) { white-space: normal; overflow-wrap: anywhere; }

/* ---------- mobile / responsive ---------- */
.side-head { display: flex; align-items: center; justify-content: space-between; }
#nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 22px; padding: 0 16px; }

@media (max-width: 768px) {
  /* sidebar becomes a top bar; ☰ opens the links */
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 50; padding: 10px 0; }
  #sidebar h2 { margin: 0 0 0 14px; font-size: 16px; }
  #nav-toggle { display: block; }
  #sidebar #nav-links, #sidebar .switch-btn, #sidebar .nav-bottom { display: none; }
  #sidebar.open #nav-links { display: block; padding-top: 6px; }
  .nav-fly { display: block; position: static; box-shadow: none; background: transparent;
    border-radius: 0; min-width: 0; padding: 0; }
  .nav-fly-title { display: none; }
  .nav-group-h { pointer-events: none; padding: 10px 16px 2px; font-size: 10.5px;
    letter-spacing: .09em; text-transform: uppercase; color: #7d8aa3; }
  .nav-group-h .chev { display: none; }
  .nav-fly a { padding: 8px 16px 8px 24px; }
  #sidebar.open .switch-btn { display: block; margin: 10px 14px 0; }
  #sidebar.open .nav-bottom { display: flex; }
  #sidebar a { padding: 11px 16px; font-size: 15px; border-bottom: 1px solid #22304a; }

  main { max-width: 100vw; padding: 12px 10px 40px; }
  h1.page { font-size: 18px; }

  /* touch-friendlier inputs; 16px stops iOS auto-zoom on focus */
  input, select, textarea { font-size: 16px !important; }
  button { padding: 9px 14px; }

  /* cards fill the row in pairs; hero cards full width */
  .card { min-width: calc(50% - 6px); flex: 1; padding: 10px 12px; }
  .card.hero { min-width: 100%; }
  .card .v { font-size: 17px; }
  .card.hero .v { font-size: 21px; }

  .form-grid { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .settings-lists { grid-template-columns: 1fr; }
  .hbar-row { grid-template-columns: 90px 1fr 84px; }

  /* wide tables: keep only the first two frozen columns, narrower */
  .tbl-wrap { max-height: none; }
  .sticky-cols th:nth-child(3), .sticky-cols td:nth-child(3) {
    position: static; min-width: 0; max-width: none; border-right: none; }
  .sticky-cols th:nth-child(1), .sticky-cols td:nth-child(1) { min-width: 46px; max-width: 46px; }
  .sticky-cols th:nth-child(2), .sticky-cols td:nth-child(2) { left: 46px; min-width: 84px; max-width: 84px; }
  .sticky-first th:nth-child(1), .sticky-first td:nth-child(1) { min-width: 150px; max-width: 170px; }

  .modal, .modal-wide { width: 96vw; padding: 14px; max-height: 92vh; overflow: auto; }
  .toolbar { gap: 6px; }
  .attn-item { flex-wrap: wrap; }
  .attn-item .act { margin-left: 0; }
  a.btn-link { margin-left: 0; }
  .chooser-box { padding: 22px 16px; }
  .login-box { width: 92vw; max-width: 340px; }
  .ac-list { min-width: 260px; max-width: 90vw; }
  .pager { justify-content: center; }
}

/* frozen register column: links/badges inside must wrap too */
.sticky-first td:nth-child(1) .doc-link { white-space: normal; overflow-wrap: anywhere; }

/* add-user form table */
#nu-roles table select { padding: 5px 7px; border: 1px solid #cbd3dd; border-radius: 6px; }
#nu-roles td, #nu-roles th { white-space: nowrap; }

#toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: #1f2c3a; color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 3000; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
