:root {
  --green: #1b6b3a;
  --green-dark: #14522c;
  --green-soft: #e8f5ec;
  --ink: #1a1a1a;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f4f6f5;
  --card: #ffffff;
  --danger: #b42318;
  --warn: #b54708;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(16, 24, 40, 0.06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: var(--green); }

.hidden { display: none !important; }

/* ── Login ── */
#login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, #d9f0e1 0%, transparent 40%),
    radial-gradient(circle at 90% 90%, #e8f0ea 0%, transparent 35%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  border: 1px solid var(--line);
}
.login-card .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.login-card .brand img { height: 42px; width: auto; }
.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  color: var(--green);
}
.login-card p.sub {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #344054;
}
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(27, 107, 58, 0.15);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: #f9fafb; }
.btn-ghost { background: transparent; color: var(--muted); border: none; }
.btn-danger { background: #fef3f2; color: var(--danger); border: 1px solid #fecdca; }
.btn-block { width: 100%; }
.error-banner {
  background: #fef3f2;
  color: var(--danger);
  border: 1px solid #fecdca;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.success-banner {
  background: var(--green-soft);
  color: var(--green-dark);
  border: 1px solid #b7e0c4;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── App shell ── */
#app-screen { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .left { display: flex; align-items: center; gap: 12px; }
.topbar img { height: 36px; }
.topbar .title { font-weight: 700; color: var(--green); font-size: 16px; }
.topbar .right { display: flex; align-items: center; gap: 8px; }
.topbar .user { font-size: 13px; color: var(--muted); margin-right: 4px; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--line);
}
.tab-btn {
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

.page {
  flex: 1;
  padding: 20px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 {
  margin: 0 0 16px;
  font-size: 18px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-head h2 { margin: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  .topbar { padding: 10px 12px; }
}

/* Autocomplete */
.ac-wrap { position: relative; }
.ac-list {
  position: absolute;
  left: 0; right: 0; top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(16,24,40,.12);
  max-height: 260px;
  overflow: auto;
  z-index: 30;
}
.ac-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f2f4f7;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: var(--green-soft); }
.ac-item .name { font-weight: 600; font-size: 14px; }
.ac-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Line items */
.table-wrap { overflow-x: auto; }
table.items {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.items th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.items td {
  padding: 8px 6px;
  border-bottom: 1px solid #f2f4f7;
  vertical-align: top;
}
table.items input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
table.items .col-sno { width: 40px; }
table.items .col-qty { width: 72px; }
table.items .col-rate { width: 110px; }
table.items .col-amt { width: 110px; text-align: right; font-weight: 600; }
table.items .col-hsn { width: 90px; }
table.items .col-act { width: 44px; }

.totals {
  margin-left: auto;
  width: min(320px, 100%);
  margin-top: 12px;
}
.totals .row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}
.totals .row.grand {
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 12px;
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
}
.words {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

/* Invoice list */
.inv-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.inv-table th, .inv-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
}
.inv-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.inv-table tr:hover td { background: #fafbfa; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-paid { background: var(--green-soft); color: var(--green-dark); }
.badge-draft { background: #fff6ed; color: var(--warn); }
.badge-unpaid { background: #fef3f2; color: var(--danger); }
.badge-submitted { background: #eff8ff; color: #175cd3; }

.pill-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-actions .btn { padding: 6px 10px; font-size: 12px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(16,24,40,.45);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 14px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  font-size: 14px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-soft);
  color: var(--green-dark);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}
.chip button {
  border: none;
  background: transparent;
  color: var(--green-dark);
  font-size: 16px;
  line-height: 1;
  padding: 0 0 0 4px;
}

.selected-box {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fafbfa;
  min-height: 48px;
}

.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.loading-dot::after {
  content: '';
  display: inline-block;
  width: 1em;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}
