:root {
  --brand: #14a35a;
  --brand-dark: #0d7d45;
  --brand-light: #e7fbf0;
  --lime: #bfe23f;
  --red: #d1373f;
  --border: #e3e8ee;
  --bg: #f5f7fa;
  --text: #1b2430;
  --muted: #6b7684;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Layout / Topbar ---------- */
.topbar {
  background: #fff;
  color: var(--text);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(20,30,50,0.04);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: nowrap;
}

.topbar .brand {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .2px;
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.topbar .brand .dot { color: var(--lime); }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}
.nav-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text);
  margin: 0 auto;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.topbar nav a {
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.topbar nav a:hover { background: var(--brand-light); color: var(--brand-dark); text-decoration: none; }

.topbar .user-box {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; }
  .nav-toggle { display: flex; }
  .topbar nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    order: 3;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    gap: 2px;
  }
  .topbar nav.open { display: flex; }
  .topbar nav a { padding: 10px 12px; }
  .topbar .user-box { order: 2; margin-left: auto; }
}

.container {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
}
@media (max-width: 600px) {
  .container { margin: 14px auto; padding: 0 10px; }
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(20,30,50,0.04);
}
@media (max-width: 600px) {
  .card { padding: 14px; border-radius: 8px; }
}

.card h2, .card h1 { margin-top: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 800px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- Forms ---------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #444;
}

input[type=text], input[type=number], input[type=date], input[type=password],
input[type=search], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
textarea { resize: vertical; min-height: 50px; }

.field { margin-bottom: 14px; }

.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 7px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, transform .1s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--brand-dark); }
.btn.secondary:hover { background: var(--brand-light); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: #fdeaea; }
.btn.small { padding: 6px 12px; font-size: 12px; }

@media (max-width: 600px) {
  .btn { width: 100%; text-align: center; padding: 12px 16px; }
  .btn.small { width: auto; padding: 6px 12px; }
}

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}
th { background: #f1f6f2; font-weight: 700; }
tbody tr:hover { background: #fafcfb; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.muted { color: var(--muted); font-size: 13px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--brand-light);
  color: var(--brand-dark);
}

.alert {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert.error { background: #fdeaea; color: var(--red); border: 1px solid #f2b8b8; }
.alert.success { background: var(--brand-light); color: var(--brand-dark); border: 1px solid #b7e3c6; }

.item-row td { vertical-align: top; }
.item-row .amt { text-align: right; }

.totals-box { max-width: 380px; margin-left: auto; }
.totals-box .row {
  display: flex; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.totals-box .row.grand {
  font-weight: 700; font-size: 17px; border-bottom: none;
  border-top: 2px solid var(--text); margin-top: 4px; padding-top: 10px;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #f3fbf6 0%, #ffffff 55%, #f3fbf6 100%);
  padding: 20px;
}
.login-wrap::before, .login-wrap::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(10px);
  opacity: .55;
  z-index: 0;
}
.login-wrap::before {
  width: 420px; height: 420px;
  background: radial-gradient(circle, var(--brand-light) 0%, transparent 70%);
  top: -160px; left: -140px;
}
.login-wrap::after {
  width: 380px; height: 380px;
  background: radial-gradient(circle, #f2fadd 0%, transparent 70%);
  bottom: -160px; right: -120px;
}
.login-card {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(20,60,40,.12);
  border: 1px solid var(--border);
}
.login-card .login-logo {
  display: block;
  max-width: 220px;
  height: auto;
  margin: 0 auto 18px;
}
.login-card h1 {
  font-size: 19px;
  text-align: center;
  color: var(--text);
  margin: 0 0 4px;
}
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card .field { margin-bottom: 16px; }
.login-card .pw-wrap { position: relative; }
.login-card .pw-wrap input { padding-right: 42px; }
.login-card .pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 12px;
  color: var(--muted); padding: 6px 8px;
}
.login-card .foot-note { text-align: center; margin-top: 18px; font-size: 12px; color: var(--muted); }

/* ---------- Dashboard stat cards ---------- */
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-card .icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--brand-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-card.alt { border-left-color: var(--lime); }
.stat-card.alt .icon { background: #f6fbe3; }
.stat-card .num { font-size: 24px; font-weight: 800; color: var(--text); line-height: 1.2; }
.stat-card .label { color: var(--muted); font-size: 12.5px; }

/* ---------- Invoice editor (form, then live preview below) ---------- */
.invoice-editor {
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.invoice-editor .editor-form { min-width: 0; }
.invoice-editor .editor-preview { min-width: 0; }

.preview-panel {
  background: linear-gradient(180deg, #f4fbf7 0%, #eef7f1 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
@media (max-width: 600px) {
  .preview-panel { padding: 12px; border-radius: 12px; }
}
.preview-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.preview-panel-head h2 {
  margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px;
}
.preview-panel-head .live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 0 rgba(20,163,90,.5);
  animation: livePulse 1.8s infinite;
}
.preview-panel-head .badge { background: #fff; color: var(--brand-dark); border: 1px solid var(--border); }

@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(20,163,90,.45); }
  70% { box-shadow: 0 0 0 8px rgba(20,163,90,0); }
  100% { box-shadow: 0 0 0 0 rgba(20,163,90,0); }
}

.live-preview { border-radius: 10px; overflow: hidden; transition: box-shadow .3s ease; }
.live-preview.flash { box-shadow: 0 0 0 3px var(--brand-light); }

/* ---------- Invoice print sheet ---------- */
.invoice-sheet {
  background: #fff;
  max-width: 850px;
  margin: 0 auto;
  padding: 30px;
  border: 1px solid var(--border);
}
.invoice-title {
  text-align: center;
  color: var(--red);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 2px;
  margin-bottom: 14px;
}
.invoice-head {
  display: flex;
  border: 2px solid #222;
}
.invoice-head .logo-block {
  flex: 1;
  padding: 12px 16px;
  border-right: 2px solid #222;
  min-width: 0;
}
.invoice-head .logo-block .invoice-logo {
  display: block;
  max-width: 280px;
  width: 100%;
  height: auto;
  margin-bottom: 6px;
}
.invoice-head .logo-block p { margin: 2px 0; font-size: 13px; }
.invoice-head .meta {
  width: 210px;
  padding: 12px 16px;
  font-size: 14px;
  flex-shrink: 0;
}
.invoice-head .meta div { margin-bottom: 10px; }

.invoice-parties { margin: 16px 0; font-size: 14px; }
.invoice-parties .line { display: flex; border-bottom: 1px dotted #999; padding: 4px 0; }
.invoice-parties .line b { width: 90px; flex-shrink: 0; }

.invoice-sheet table.items th, .invoice-sheet table.items td {
  border: 1px solid #222;
  font-size: 13px;
  padding: 6px 8px;
}
.invoice-sheet table.items th { background: #f0f0f0; }
.invoice-sheet table.items td.num { text-align: right; }

.invoice-foot-totals {
  display: flex;
  justify-content: flex-end;
  margin-top: -1px;
}
.invoice-foot-totals table { width: 300px; max-width: 100%; }
.invoice-foot-totals td { border: 1px solid #222; padding: 6px 10px; }
.invoice-foot-totals tr td:last-child { text-align: right; font-weight: 700; }

.invoice-words { margin-top: 14px; font-size: 14px; }
.invoice-words .line { border-bottom: 1px dotted #999; padding: 6px 0; min-height: 20px; }

.invoice-bottom {
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
  font-size: 13px;
  flex-wrap: wrap;
  gap: 16px;
}
.invoice-bottom .gstin { color: var(--red); font-weight: 700; margin-bottom: 10px; }
.invoice-bottom .bank b { color: var(--red); }
.invoice-bottom .sign { text-align: right; }
.invoice-bottom .sign .for { color: var(--text); font-weight: 700; margin-bottom: 40px; }
.invoice-bottom .sign .for .for-name { color: var(--brand); }

@media (max-width: 600px) {
  .invoice-sheet { padding: 14px; }
  .invoice-head { flex-direction: column; }
  .invoice-head .logo-block { border-right: none; border-bottom: 2px solid #222; }
  .invoice-head .meta { width: auto; }
  .invoice-sheet table.items { font-size: 11px; }
  .invoice-sheet table.items th, .invoice-sheet table.items td { padding: 4px; }
}

/* Compact scaled-down variant used inside the live preview panel */
.live-preview .invoice-sheet {
  padding: 16px;
  font-size: 12px;
  border-radius: 8px;
}
.live-preview .invoice-title { font-size: 16px; margin-bottom: 8px; }
.live-preview .invoice-head .logo-block .invoice-logo { max-width: 170px; }
.live-preview .invoice-head .logo-block p { font-size: 11px; }
.live-preview .invoice-head .meta { font-size: 12px; width: 150px; }
.live-preview .invoice-parties { font-size: 12px; margin: 10px 0; }
.live-preview .invoice-sheet table.items th,
.live-preview .invoice-sheet table.items td { font-size: 11px; padding: 4px 6px; }
.live-preview .invoice-foot-totals table { width: 220px; }
.live-preview .invoice-words { font-size: 12px; }

/* ---------- AI-style chat wizard ---------- */
.wizard-shell { display: flex; flex-direction: column; gap: 24px; }

.chat-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 3px rgba(20,30,50,0.04);
}
.chat-panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f4fbf7 0%, #ffffff 100%);
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-panel-head .bot-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.chat-panel-head h2 { margin: 0; font-size: 15px; }
.chat-panel-head .muted { font-size: 12px; }
.chat-panel-head .restart-link { margin-left: auto; font-size: 12px; }

.chat-log {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 480px;
  overflow-y: auto;
}
@media (max-width: 600px) {
  .chat-log { max-height: 360px; padding: 12px; }
}

.chat-msg { display: flex; gap: 10px; max-width: 85%; }
.chat-msg.bot { align-self: flex-start; }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.chat-msg.bot .avatar { background: var(--brand-light); color: var(--brand-dark); }
.chat-msg.user .avatar { background: #eef1f5; color: var(--text); }
.chat-msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.chat-msg.bot .bubble { background: #f2f6f4; color: var(--text); border-bottom-left-radius: 4px; }
.chat-msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.bot .bubble.error { background: #fdeaea; color: #a12; }

.chat-quick {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 18px 12px;
}
.chat-quick .chip {
  border: 1px solid var(--brand);
  color: var(--brand-dark);
  background: #fff;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chat-quick .chip:hover { background: var(--brand-light); }

.chat-input-row {
  display: flex; gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
}
.chat-input-row.disabled { opacity: .5; pointer-events: none; }

.typing-dots span {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--muted); margin-right: 3px;
  animation: typingBounce 1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.wizard-generate-box {
  text-align: center;
  padding: 16px;
  border-top: 1px dashed var(--border);
  margin-top: 12px;
}

.no-print { }
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .invoice-sheet { border: none; padding: 0; margin: 0; max-width: 100%; }
  .container { margin: 0; padding: 0; max-width: 100%; }
}
