/* ============================================================
   MAHADIR — Full stylesheet
   ============================================================ */
:root {
  --primary: #17365d;
  --primary-light: #244b78;
  --accent: #c49a50;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #253247;
  --muted: #8491a3;
  --border: #e7ebf0;
  --green: #198754;
  --red: #dc5555;
  --orange: #d99435;
  --blue: #3978c5;
  --sidebar-w: 260px;
  --preview-w: 460px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }

/* ===== LOGIN / SETUP ===== */
#login-screen, #setup-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
}
.login-card {
  background: var(--surface); padding: 38px; border-radius: 12px;
  width: 400px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-card .logo { text-align: center; font-size: 44px; color: var(--primary); margin-bottom: 8px; }
.login-card h1 { text-align: center; font-size: 18px; color: var(--primary); margin-bottom: 6px; }
.login-card p { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: 12px; }
.login-card label { display: block; font-weight: bold; margin-bottom: 5px; font-size: 12px; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 12px; outline: none;
}
.login-card input:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(36,75,120,.1); }
.login-card button {
  width: 100%; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: 6px; font-weight: bold; margin-top: 8px;
}
.login-error {
  background: #ffeded; color: var(--red); padding: 10px;
  border-radius: 6px; margin-bottom: 12px; font-size: 12px; display: none;
}

/* ===== LAYOUT ===== */
#app { display: none; }
#app.logged-in { display: block; }
.app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); background: var(--primary); color: #fff;
  display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
}
.brand {
  padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex; align-items: center; gap: 12px;
}
.brand-logo {
  width: 44px; height: 44px; border-radius: 11px;
  background: var(--accent); display: grid; place-items: center; font-size: 24px;
}
.brand h1 { font-size: 17px; margin-bottom: 3px; }
.brand small { color: #b5c5d8; font-size: 10px; }

.demo-pill {
  margin: 12px 14px 4px; padding: 8px 12px;
  background: var(--orange); color: #fff; border-radius: 8px;
  font-size: 11px; font-weight: bold; text-align: center; cursor: pointer;
}
.demo-pill:hover { background: #c47f1f; }
.demo-pill.limit-reached { background: var(--red); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.65;} }

.sidebar h2 {
  padding: 16px 18px 8px; color: #94a9c1; font-size: 10px; font-weight: normal;
}
.cat-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px; background: none; border: none; color: #d2dce9;
  font-family: inherit; font-size: 13px; text-align: right; width: 100%;
  cursor: pointer; border-right: 3px solid transparent; transition: .15s;
}
.cat-btn:hover { background: var(--primary-light); color: #fff; }
.cat-btn.active { background: var(--primary-light); color: #fff; border-right-color: var(--accent); font-weight: bold; }
.cat-btn .icon { font-size: 15px; width: 20px; }
.cat-btn .count {
  margin-right: auto; background: rgba(255,255,255,.15);
  padding: 2px 7px; border-radius: 10px; font-size: 10px;
}

.sidebar-footer {
  margin-top: auto; padding: 14px; border-top: 1px solid rgba(255,255,255,.1);
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-footer .user { color: #b5c5d8; font-size: 11px; padding: 4px 2px; }
.sidebar-footer button {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15);
  color: #fff; padding: 9px 12px; border-radius: 6px;
  font-family: inherit; font-size: 12px; cursor: pointer; text-align: right;
}
.sidebar-footer button:hover { background: rgba(255,255,255,.2); }

/* Main */
.main { flex: 1; display: flex; overflow: hidden; min-width: 0; }
.view-container { flex: 1; display: flex; overflow: hidden; min-width: 0; }

/* ===== FAST FORM LAYOUT ===== */
.fastform-layout { display: flex; flex: 1; overflow: hidden; }
.form-col {
  flex: 1; overflow-y: auto; padding: 22px; min-width: 0;
  display: flex; justify-content: center;
}
.form-inner { max-width: 820px; width: 100%; }
.preview-col {
  width: var(--preview-w); background: #e6eaf0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.preview-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 16px; display: flex; justify-content: space-between; align-items: center;
}
.preview-header h3 { font-size: 13px; color: var(--primary); }
.preview-header button {
  background: none; border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 5px; font-size: 11px; cursor: pointer;
}
.preview-scroll { flex: 1; overflow-y: auto; padding: 16px; }

/* A4 */
.a4 {
  background: #fff; width: 100%; min-height: 660px;
  padding: 26px 22px; font-size: 11px; line-height: 1.6;
  box-shadow: 0 2px 12px rgba(0,0,0,.08); color: #000;
}
.a4 .doc-head { text-align: center; font-size: 10px; line-height: 1.7; margin-bottom: 12px; font-weight: bold; }
.a4 .doc-title { text-align: center; font-size: 14px; font-weight: bold; text-decoration: underline; margin: 12px 0 4px; }
.a4 .doc-sub { text-align: center; font-size: 10px; text-decoration: underline; margin-bottom: 12px; }
.a4 .meta-row { display: flex; justify-content: space-between; font-size: 10px; font-weight: bold; margin: 6px 0; }
.a4 .body-text { text-align: justify; font-size: 10.5px; line-height: 1.9; margin: 10px 0; }
.a4 .items { width: 100%; border-collapse: collapse; margin: 10px 0; }
.a4 .items td { padding: 3px 4px; font-size: 10px; vertical-align: top; }
.a4 .items .num { width: 20px; text-align: center; }
.a4 .items .amt { width: 80px; text-align: left; direction: ltr; white-space: nowrap; }
.a4 .items .total { border-top: 1.5px solid #000; font-weight: bold; padding-top: 6px; }
.a4 .sign { display: flex; justify-content: space-between; margin-top: 40px; font-size: 10.5px; font-weight: bold; }

/* ===== FORM STYLES ===== */
.page-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; }
.page-title h2 { font-size: 18px; color: var(--primary); }
.page-title p { color: var(--muted); font-size: 12px; margin-top: 3px; }

.section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 18px; margin-bottom: 16px;
}
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: bold; color: var(--primary);
  margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.section-title .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; background: var(--primary); color: #fff;
  border-radius: 50%; font-size: 11px; margin-left: 8px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 5px; position: relative; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-weight: bold; font-size: 12px; }
.form-group label .req { color: var(--red); }
.form-group input, .form-group select, .form-group textarea {
  padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 6px; font-family: inherit; font-size: 13px;
  outline: none; background: #fff; width: 100%;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(36,75,120,.08);
}
.form-group input.readonly { background: #f7f8fa; color: var(--muted); }
.hint { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

/* Autocomplete */
.autocomplete {
  position: absolute; top: 100%; right: 0; left: 0;
  background: #fff; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 6px 24px rgba(0,0,0,.08);
  z-index: 20; max-height: 240px; overflow-y: auto;
  display: none; margin-top: 4px;
}
.autocomplete.show { display: block; }
.ac-item {
  padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); font-size: 12px;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: #eef4fa; }
.ac-item .name { font-weight: bold; }
.ac-item .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.ac-item.new { color: var(--green); font-weight: bold; }
.ac-item .badge-existing {
  display: inline-block; padding: 1px 6px; background: #e8f6ed;
  color: var(--green); border-radius: 8px; font-size: 9px; margin-right: 6px;
}

/* Info banner */
.info-banner {
  padding: 10px 12px; background: #eaf1fc; border: 1px solid #c5d8ef;
  border-radius: 6px; font-size: 11.5px; color: var(--primary);
  margin-top: 8px; display: flex; justify-content: space-between; align-items: center;
}
.info-banner .tag { background: var(--primary); color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 10px; }

.warn-banner {
  padding: 10px 12px; background: #fff4df; border: 1px solid #f4d4a0;
  border-radius: 6px; font-size: 11.5px; color: #8a5d00;
  margin-top: 8px; display: none;
}
.warn-banner.show { display: block; }

/* Items table */
.items-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.items-table th {
  background: #f7f8fa; color: var(--muted); font-weight: bold;
  font-size: 11px; padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border);
}
.items-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  font-size: 12px; vertical-align: middle;
}
.items-table input {
  padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; font-family: inherit; font-size: 12px; width: 100%;
}
.items-table .n { text-align: left; direction: ltr; white-space: nowrap; font-weight: bold; }
.items-table .amt-col { width: 130px; }
.items-table .status-col { width: 90px; text-align: center; }
.items-table .del-col { width: 34px; }

.btn-add {
  background: none; border: 1px dashed var(--border);
  padding: 9px 14px; border-radius: 6px; color: var(--muted);
  cursor: pointer; font-family: inherit; font-size: 12px; width: 100%;
}
.btn-add:hover { border-color: var(--primary); color: var(--primary); background: #f7fafd; }

/* Payment toggle */
.pay-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.pay-toggle label {
  flex: 1; padding: 10px; border: 2px solid var(--border);
  border-radius: 6px; cursor: pointer; text-align: center;
  font-weight: bold; font-size: 12px; transition: .15s;
}
.pay-toggle input { display: none; }
.pay-toggle input:checked + span { color: var(--primary); }
.pay-toggle label:has(input:checked) { border-color: var(--primary); background: #f0f6fc; }

/* Total summary */
.total-summary {
  background: linear-gradient(135deg, #f0f6fc, #e6f0f9);
  border: 2px solid var(--primary); border-radius: 9px;
  padding: 18px; margin-top: 16px;
}
.total-summary .row {
  display: flex; justify-content: space-between;
  padding: 6px 0; font-size: 12.5px;
}
.total-summary .row.sub { color: var(--muted); font-size: 11.5px; }
.total-summary .row.grand {
  border-top: 2px solid var(--primary); margin-top: 10px;
  padding-top: 14px; font-size: 18px; font-weight: bold; color: var(--primary);
}
.total-summary .row.grand .val { font-size: 22px; }
.words-line {
  background: #fff; border-radius: 6px; padding: 10px 12px;
  margin-top: 10px; font-size: 11.5px; font-weight: bold; text-align: center;
}

/* Actions */
.actions {
  display: flex; gap: 10px; margin-top: 16px;
  padding: 12px 0; background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.btn-action {
  flex: 1; padding: 13px 18px; border: none; border-radius: 7px;
  font-family: inherit; font-size: 13px; font-weight: bold; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: .15s;
}
.btn-print { background: var(--primary); color: #fff; flex: 2; }
.btn-print:hover { background: var(--primary-light); }
.btn-preview { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-preview:hover { background: #f0f6fc; }
.btn-save { background: var(--accent); color: #fff; }
.btn-save:hover { background: #b08a42; }

/* Confirm party */
.confirm-party {
  background: #f7f8fa; border: 1px solid var(--border);
  border-radius: 6px; padding: 12px 14px; margin-top: 8px; display: none;
}
.confirm-party.show { display: block; }
.confirm-party .label { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.confirm-party .existing {
  background: #fff; border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 5px; margin-bottom: 10px;
}
.confirm-party .existing .name { font-weight: bold; font-size: 12px; }
.confirm-party .existing .addr { color: var(--muted); font-size: 10.5px; margin-top: 2px; }
.confirm-party .actions-row { display: flex; gap: 8px; }
.confirm-party .actions-row button {
  flex: 1; padding: 8px 12px; border-radius: 5px;
  font-family: inherit; font-size: 11.5px; font-weight: bold;
  cursor: pointer; border: none;
}
.confirm-party .btn-use { background: var(--primary); color: #fff; }
.confirm-party .btn-new { background: #fff; color: var(--text); border: 1px solid var(--border); }

/* ===== MANAGEMENT MODE ===== */
#view-management { flex-direction: column; }
.topbar-mgmt {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 16px 24px;
}
.topbar-mgmt h2 { font-size: 16px; color: var(--primary); }
.content { padding: 22px; overflow-y: auto; flex: 1; }

.page-heading {
  display: flex; justify-content: space-between; align-items: center;
  gap: 15px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-heading h2 { font-size: 19px; margin-bottom: 6px; }
.page-heading p { color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 16px; }
.stats-grid { grid-template-columns: repeat(4, 1fr); margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 18px;
}
.stat-card { display: flex; align-items: center; justify-content: space-between; }
.stat-info small { color: var(--muted); }
.stat-number { font-size: 24px; font-weight: bold; margin: 8px 0; color: var(--primary); }
.stat-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: grid; place-items: center; font-size: 22px; background: #edf2f8;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; gap: 10px;
}
.card-header h3 { font-size: 14px; }
.muted { color: var(--muted); }

.btn {
  border: none; padding: 9px 15px; border-radius: 6px;
  background: var(--primary); color: #fff; font-weight: bold; transition: .2s;
}
.btn:hover { background: var(--primary-light); }
.btn-gold { background: var(--accent); }
.btn-light { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: #fff0f0; color: var(--red); }
.btn-success { background: var(--green); }
.btn-sm { padding: 6px 10px; font-size: 11px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th {
  background: #f7f8fa; color: #6f7d8e; font-weight: bold;
  font-size: 11px; text-align: right; padding: 12px; border-bottom: 1px solid var(--border);
}
td { font-size: 12px; padding: 12px; border-bottom: 1px solid var(--border); text-align: right; }
tbody tr:hover { background: #fafbfd; }

.badge {
  display: inline-block; border-radius: 20px; padding: 4px 9px;
  font-size: 10px; font-weight: bold;
}
.badge-green { background: #e8f6ed; color: var(--green); }
.badge-orange { background: #fff4df; color: #b77a1e; }
.badge-red { background: #ffeded; color: var(--red); }
.badge-blue { background: #eaf1fc; color: var(--blue); }
.badge-gray { background: #eff1f4; color: #667085; }

/* Modal */
.modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 1000;
  align-items: center; justify-content: center; padding: 20px;
}
.modal.show { display: flex; }
.modal-box {
  background: #fff; border-radius: 10px; max-width: 640px;
  width: 100%; max-height: 90vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h3 { font-size: 15px; color: var(--primary); }
.modal-head button {
  background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted);
}
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}
.modal-foot button {
  padding: 9px 20px; border-radius: 6px; font-family: inherit;
  font-size: 13px; font-weight: bold; cursor: pointer; border: none;
}
.modal-foot .primary { background: var(--primary); color: #fff; }
.modal-foot .secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.modal-foot .success { background: var(--green); color: #fff; }
.modal-foot .danger { background: var(--red); color: #fff; }

/* Toast */
.toast {
  position: fixed; bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--green); color: #fff;
  padding: 14px 24px; border-radius: 8px;
  font-weight: bold; font-size: 13px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  opacity: 0; transition: all .3s; z-index: 2000;
  display: flex; align-items: center; gap: 10px;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.warning { background: var(--orange); }
.toast.error { background: var(--red); }

/* Responsive */
@media (max-width: 1100px) {
  .preview-col { width: 380px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 850px) {
  .preview-col { display: none; }
  .form-col { padding: 14px; }
}