/* ── Password Gate ── */
#auth-gate {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #1e3068 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.auth-card {
  background: #fff;
  border-radius: 20px;
  padding: 44px 40px 40px;
  width: 360px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.4);
}

.auth-logo {
  width: auto;
    height: 100px;
  object-fit: contain;
  margin-bottom: 16px;
}

.auth-title {
  font-family: 'DM Serif Display', serif;
  font-size: 26px;
  font-weight: 400;
  margin-bottom: 4px;
}

.auth-title .orange { color: #e8720c; }
.auth-title .navy   { color: #1e3a8a; }

.auth-sub {
  font-size: 13px;
  color: #9099b8;
  margin-bottom: 28px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.auth-field-wrap {
  display: flex;
  border: 1.5px solid #d0d5e8;
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-field-wrap:focus-within {
  border-color: #e8720c;
  box-shadow: 0 0 0 3px rgba(232,114,12,0.12);
}

.auth-input {
  flex: 1;
  padding: 12px 14px;
  border: none;
  outline: none;
  font-size: 15px;
  font-family: 'Outfit', sans-serif;
  color: #1a1f36;
  background: #f7f8fb;
  letter-spacing: 0.08em;
}

.auth-btn {
  padding: 0 16px;
  background: #e8720c;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.auth-btn:hover { background: #c2410c; }
.auth-btn svg { width: 22px; height: 22px; fill: #fff; }

.auth-error {
  margin-top: 12px;
  font-size: 13px;
  color: #dc2626;
  min-height: 18px;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-5px); }
  80%       { transform: translateX(5px); }
}

.auth-card.shake { animation: shake 0.4s ease; }

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Light theme */
  --bg:        #f0f2f7;
  --bg2:       #ffffff;
  --bg3:       #f7f8fb;
  --border:    #e2e6f0;
  --border2:   #d0d5e8;
  --text:      #1a1f36;
  --text2:     #4a5272;
  --text3:     #9099b8;

  /* Brand colors from BharatWebWorks logo */
  --orange:    #e8720c;
  --orange-lt: #f4974a;
  --navy:      #1e3a8a;
  --navy-lt:   #2d55c7;
  --blue:      #3b82f6;
  --green:     #16a34a;
  --red:       #dc2626;
  --gold:      #d97706;

  --sidebar-w: 248px;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

body { display: flex; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  padding: 0;
  flex-shrink: 0;
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  box-shadow: 2px 0 12px rgba(30,58,138,0.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 12px;
  flex-direction: column;
}

.brand-logo {
  width: auto;
  height: 100px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  padding: 2px;
  flex-shrink: 0;
}

.brand-name {
  display: block;
  font-weight: 700;
  font-size: 18px;
  color: #ffffff;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.brand-sub {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-top: 2px;
}

.nav { padding: 0 10px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: all 0.15s;
}

.nav-item svg {
  width: 18px; height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-item.active {
  background: var(--orange);
  color: #fff;
  box-shadow: 0 2px 8px rgba(232,114,12,0.4);
}

.sidebar-footer {
  padding: 16px 18px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.client-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
}

.client-dot {
  width: 7px; height: 7px;
  background: #4ade80;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px #4ade80;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Main ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

.page-title {
  font-family: 'DM Serif Display', serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* ── Views ── */
.view { display: none; padding: 24px 28px; overflow-y: auto; flex: 1; height: calc(100vh - 65px); }
.view.active { display: block; }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 21px; height: 21px; }

.stat-icon--blue   { background: #eff6ff; }
.stat-icon--blue   svg { fill: var(--blue); }
.stat-icon--orange { background: #fff7ed; }
.stat-icon--orange svg { fill: var(--orange); }
.stat-icon--green  { background: #f0fdf4; }
.stat-icon--green  svg { fill: var(--green); }
.stat-icon--red    { background: #fef2f2; }
.stat-icon--red    svg { fill: var(--red); }

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 3px;
}

.stat-value {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* ── Cards ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn svg { width: 14px; height: 14px; fill: currentColor; }
.btn:hover { background: var(--border); color: var(--text); }

.btn-outline { border-color: var(--border2); background: transparent; }

.btn-primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
  font-weight: 700;
}
.btn-primary:hover {
  background: var(--orange-lt);
  border-color: var(--orange-lt);
  color: #fff;
}

.btn-cancel {
  background: #fff;
  border-color: var(--border2);
  color: var(--text2);
}
.btn-cancel:hover {
  background: #fef2f2;
  border-color: #fca5a5;
  color: var(--red);
}

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-print { background: #eff6ff; border-color: #bfdbfe; color: var(--blue); }
.btn-print:hover { background: #dbeafe; color: var(--navy); }

.btn-action { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-view   { color: var(--blue); border-color: #bfdbfe; background: #eff6ff; }
.btn-view:hover { background: #dbeafe; color: var(--navy); }
.btn-edit   { color: var(--orange); border-color: #fed7aa; background: #fff7ed; }
.btn-edit:hover { background: #ffedd5; color: #c2410c; }
.btn-delete { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.btn-delete:hover { background: #fee2e2; color: #b91c1c; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }

.invoice-table { width: 100%; border-collapse: collapse; }

.invoice-table th {
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}

.invoice-table td {
  padding: 13px 16px;
  font-size: 13.5px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
}

.invoice-table tr:last-child td { border-bottom: none; }
.invoice-table tbody tr:hover td { background: #fafbff; }

.invoice-num {
  font-family: 'DM Mono', monospace;
  font-weight: 600;
  color: var(--navy);
  font-size: 13px;
  background: #eef2ff;
  padding: 2px 8px;
  border-radius: 4px;
}

.amount-cell { font-family: 'DM Mono', monospace; color: var(--text); font-size: 13px; }
.tds-cell    { font-family: 'DM Mono', monospace; color: var(--red);  font-size: 13px; }
.net-cell    { font-family: 'DM Mono', monospace; color: var(--green); font-size: 13px; font-weight: 600; }

.td-actions { display: flex; gap: 5px; }

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--navy-lt);
}

/* ── Generate layout ── */
.generate-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 22px;
  align-items: start;
}

.form-group {
  padding: 0 20px;
  margin-bottom: 16px;
}

.form-section-label {
  padding: 10px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--navy-lt);
  background: #eef2ff;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.form-group:first-of-type { margin-top: 20px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text3);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 9px 13px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: 'Outfit', sans-serif;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(232,114,12,0.1);
}

.amount-preview {
  margin: 0 20px 18px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.amount-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
}

.amount-row:last-child { border-bottom: none; }
.amount-row.total { background: #f0fdf4; }

.amount-val { font-family: 'DM Mono', monospace; font-weight: 500; }
.amount-val.neg { color: var(--red); }
.amount-val.highlight { color: var(--green); font-weight: 700; }

.form-actions {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gen-msg {
  margin: 0 20px 12px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}

.gen-msg.error   { background: #fef2f2; border: 1px solid #fecaca; color: var(--red); display: block; }
.gen-msg.success { background: #f0fdf4; border: 1px solid #86efac; color: #15803d; display: block; }

/* ── Invoice preview wrapper ── */
#invoice-html-preview {
  padding: 28px;
  background: #fff;
  color: #111;
  font-family: 'Outfit', sans-serif;
  min-height: 500px;
}

/* ── INVOICE DOCUMENT ── */
.inv-doc { max-width: 760px; margin: 0 auto; }

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 3px solid var(--orange);
  margin-bottom: 22px;
}

.inv-logo-block { display: flex; align-items: center; gap: 12px; }
.inv-logo { width: 54px; height: 54px; object-fit: contain; }

.inv-brand-name { font-family: 'DM Serif Display', serif; font-size: 22px; color: #1a1f36; }
.inv-brand-name span.orange { color: #e8720c; }
.inv-brand-name span.navy   { color: #1e3a8a; }
.inv-brand-tagline { font-size: 11px; color: #888; margin-top: 2px; }

.inv-meta { text-align: right; }
.inv-meta-title { font-size: 26px; font-weight: 700; color: #1a1f36; letter-spacing: -0.03em; }
.inv-meta-num   { font-family: 'DM Mono', monospace; font-size: 14px; color: #e8720c; font-weight: 600; margin-top: 4px; }
.inv-meta-date  { font-size: 13px; color: #666; margin-top: 2px; }

.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 26px; }
.inv-party-label  { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: #999; margin-bottom: 5px; }
.inv-party-name   { font-size: 15px; font-weight: 700; color: #1a1f36; }
.inv-party-detail { font-size: 13px; color: #555; line-height: 1.7; }

.inv-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.inv-table th {
  background: #1e3a8a;
  color: #fff;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
}
.inv-table th:last-child { text-align: right; }
.inv-table td {
  padding: 12px 14px;
  font-size: 14px;
  color: #333;
  border-bottom: 1px solid #e8e8e8;
}
.inv-table td:last-child { text-align: right; font-family: 'DM Mono', monospace; }

.inv-totals { display: flex; justify-content: flex-end; margin-bottom: 26px; }
.inv-totals-box { min-width: 280px; }

.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  color: #555;
  border-bottom: 1px solid #eee;
}
.inv-total-row.final {
  border-bottom: 3px double #e8720c;
  padding-bottom: 10px;
}
.inv-total-row.final span:first-child { color: #1a1f36; font-weight: 700; font-size: 15px; }
.inv-total-row.final span:last-child  { color: #16a34a; font-weight: 700; font-size: 17px; font-family: 'DM Mono', monospace; }
.inv-total-row.tds-row span:last-child { color: #dc2626; font-family: 'DM Mono', monospace; }
.inv-total-row span:last-child { font-family: 'DM Mono', monospace; }

.inv-footer {
  text-align: center;
  font-size: 12px;
  color: #aaa;
  padding-top: 14px;
  border-top: 1px solid #eee;
}

/* ── Print ── */
@media print {
  body { background: white; }
  .sidebar, .topbar, .generate-form-card, .card-header { display: none !important; }
  .invoice-preview-card { border: none !important; }
  #invoice-html-preview { padding: 0 !important; }
  .main { margin-left: 0; }
  .view { padding: 0; height: auto; overflow: visible; }
  #view-generate { display: block !important; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px)  { .generate-layout { grid-template-columns: 1fr; } }
@media (max-width: 700px) {
  :root { --sidebar-w: 60px; }
  .brand-text, .nav-item span, .sidebar-footer { display: none; }
  .nav-item { justify-content: center; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .main { margin-left: 60px; }
}
