:root {
  --primary: #1a237e;
  --accent: #0d47a1;
  --gold: #c8a84b;
  --surface: #f5f7fa;
  --border: #dde3f0;
  --text: #1c2340;
  --muted: #6b7280;
  --success: #166534;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(26, 35, 126, 0.1);
}
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: "Source Sans 3", sans-serif;
  background: #e8ecf5;
  color: var(--text);
  min-height: 100vh;
}

/* ─── APP SHELL ─── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    #283593 60%,
    #1565c0 100%
  );
  color: #fff;
  padding: 18px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 4px 16px rgba(26, 35, 126, 0.3);
}
header h1 {
  font-family: "Playfair Display", serif;
  font-size: 1.5rem;
  letter-spacing: 0.5px;
}
header p {
  font-size: 0.85rem;
  opacity: 0.75;
  margin-top: 2px;
}
header .logo-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
}
.header-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
}
.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 10px 22px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 7px;
}
.btn-primary {
  background: var(--gold);
  color: #1a1a1a;
}
.btn-primary:hover {
  background: #dbb94e;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(200, 168, 75, 0.4);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.25);
}
.btn-danger {
  background: #dc2626;
  color: #fff;
}
.btn-danger:hover {
  background: #b91c1c;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}
.btn-success {
  background: #16a34a;
  color: #fff;
}
.btn-success:hover {
  background: #15803d;
}

/* ─── TABS ─── */
.tabs {
  display: flex;
  background: var(--primary);
  padding: 0 32px;
  gap: 2px;
}
.tab {
  padding: 12px 24px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}
.tab.active {
  color: #fff;
  border-bottom-color: var(--gold);
}
.tab:hover {
  color: #fff;
}

/* ─── LAYOUT ─── */
.workspace {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 24px;
  padding: 24px 32px;
  flex: 1;
}
.form-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ─── FORM SECTIONS ─── */
.section {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.section-header {
  background: linear-gradient(90deg, var(--primary), #283593);
  color: #fff;
  padding: 12px 18px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.section-header .chevron {
  transition: transform 0.2s;
}
.section-header.collapsed .chevron {
  transform: rotate(-90deg);
}
.section-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.section-body.hidden {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field input,
.field select,
.field textarea {
  border: 1.5px solid var(--border);
  border-radius: 7px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.field textarea {
  resize: vertical;
  min-height: 70px;
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

/* ─── ITEMS TABLE IN FORM ─── */
.items-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.items-table-wrapper {
  overflow-x: auto;
}
table.form-items {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 700px;
}
table.form-items th {
  background: var(--primary);
  color: #fff;
  padding: 8px 6px;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.3px;
}
table.form-items td {
  border-bottom: 1px solid var(--border);
  padding: 6px 4px;
}
table.form-items td input,
table.form-items td select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 6px;
  font-size: 0.78rem;
  background: var(--surface);
  font-family: inherit;
}
table.form-items td input:focus,
table.form-items td select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
table.form-items tr:hover td {
  background: #f0f4ff;
}
.del-btn {
  background: #fee2e2;
  border: none;
  color: #dc2626;
  cursor: pointer;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 0.8rem;
}
.del-btn:hover {
  background: #dc2626;
  color: #fff;
}

/* ─── PREVIEW PANEL ─── */
.preview-panel {
  display: flex;
  flex-direction: column;
}
.preview-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}
.preview-toolbar h2 {
  font-family: "Playfair Display", serif;
  font-size: 1.1rem;
  color: var(--primary);
}
.preview-toolbar .spacer {
  flex: 1;
}

/* ─── INVOICE PAPER ─── */
.paper-wrap {
  background: #8090a8;
  padding: 20px;
  border-radius: 10px;
  overflow: auto;
}
#invoice-paper {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11px;
  color: #000;
  padding: 15mm 12mm;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

/* ─── INVOICE STYLES (matching original) ─── */
.inv-header {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.inv-logo {
  width: 120px;
  flex-shrink: 0;
}
.inv-logo img {
  width: 100%;
}
.inv-logo-placeholder {
  width: 120px;
  height: 60px;
  background: #003366;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 9px;
  text-align: center;
  font-weight: bold;
}
.inv-company-center {
  flex: 1;
  text-align: center;
}
.inv-company-name {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 1.2;
}
.inv-addr-box {
  text-align: right;
  font-size: 9.5px;
  line-height: 1.5;
}
.inv-copy-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-left: 10px;
  flex-shrink: 0;
}
.inv-copy-label {
  border: 1px solid #000;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
}
.inv-copy-label.active {
  background: #000;
  color: #fff;
}

.inv-meta {
  display: flex;
  gap: 0;
  border: 1px solid #000;
  margin-bottom: 8px;
}
.inv-meta-col {
  flex: 1;
  padding: 6px 8px;
  font-size: 9.5px;
  line-height: 1.7;
  border-right: 1px solid #000;
}
.inv-meta-col:last-child {
  border-right: none;
}
.inv-meta-col strong {
  font-size: 10px;
}

/* Items table */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 6px;
  font-size: 9px;
}
.inv-table th {
  background: #fff;
  border: 1px solid #000;
  padding: 5px 4px;
  text-align: center;
  font-size: 8.5px;
  vertical-align: middle;
}
.inv-table td {
  border: 1px solid #000;
  padding: 5px 4px;
  vertical-align: middle;
  text-align: center;
}
.inv-table td.left {
  text-align: left;
}
.inv-table tr.total-row td {
  font-weight: bold;
  background: #f5f5f5;
}

/* Tax + Outstanding + Summary layout */
.inv-tax-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: flex-start;
}
.inv-tax-left {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.inv-tax-right {
  width: 220px;
  border: 1px solid #000;
}
.tax-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9px;
  border: 1px solid #000;
}
.tax-table th {
  border-bottom: 1px solid #000;
  border-right: 1px solid #000;
  padding: 4px 3px;
  text-align: center;
  background: #f5f5f5;
  font-size: 8.5px;
}
.tax-table td {
  border-bottom: 1px solid #000;
  border-right: 1px solid #000;
  padding: 4px 3px;
  text-align: center;
  font-size: 9px;
}
.tax-table tr:last-child td {
  border-bottom: none;
  font-weight: bold;
  background: #f0f0f0;
}
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9px;
}
.summary-table td {
  padding: 3px 6px;
  border-bottom: 1px solid #ddd;
}
.summary-table td:last-child {
  text-align: right;
  font-weight: 600;
}
.summary-table tr.total-final td {
  border-top: 2px solid #000;
  font-weight: bold;
  font-size: 10px;
  background: #f0f0f0;
}

/* Pending row */
.inv-pending {
  border: 1px solid #000;
}
.pending-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9px;
}
.pending-table th {
  border-bottom: 1px solid #000;
  border-right: 1px solid #000;
  padding: 4px;
  text-align: center;
  background: #f5f5f5;
}
.pending-table td {
  padding: 4px;
  text-align: center;
  border-right: 1px solid #000;
}
.pending-table td:last-child,
.pending-table th:last-child {
  border-right: none;
}

.inv-words {
  border: 1px solid #000;
  margin-top: 6px;
  padding: 5px 8px;
  font-size: 9.5px;
}
.inv-bank {
  display: flex;
  gap: 0;
  border: 1px solid #000;
  border-top: none;
}
.inv-bank div {
  flex: 1;
  padding: 5px 8px;
  font-size: 9.5px;
  border-right: 1px solid #000;
}
.inv-bank div:last-child {
  border-right: none;
}
.inv-terms {
  border: 1px solid #000;
  padding: 6px 8px;
  font-size: 9px;
  line-height: 1.7;
}
.inv-sign {
  text-align: right;
  font-size: 9px;
  margin-top: 8px;
  font-weight: bold;
}
.inv-section-title {
  font-weight: bold;
  text-decoration: underline;
  margin-bottom: 3px;
}
.inv-gstin-line {
  font-size: 11px;
  font-weight: bold;
  margin: 2px 0;
}
.inv-tax-invoice {
  font-size: 12px;
  font-weight: bold;
  text-decoration: underline;
  margin: 4px 0;
}

/* ─── PRINT ─── */
@page {
  size: A4;
  margin: 0;
}
@media print {
  body > *:not(#print-area) {
    display: none !important;
  }
  #print-area {
    display: block !important;
  }
  #invoice-paper {
    box-shadow: none;
    width: 100%;
    min-height: auto;
    padding: 10mm;
  }
  .paper-wrap {
    background: #fff;
    padding: 0;
  }
}

/* ─── RESPONSIVE ─── */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.tag {
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
