/* ==========================================================================
   Bill Maker - Modern, Clean Invoice Web Application
   ========================================================================== */

:root {
  --primary-navy: #1a365d;
  --primary-navy-dark: #0f223d;
  --primary-navy-light: #2b4c7e;
  --accent-blue: #2563eb;
  --accent-blue-hover: #1d4ed8;
  --highlight-blue: #c9daf8;
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --border-light: #e2e8f0;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --shadow-paper: 0 12px 30px rgba(15, 23, 42, 0.15);
  --font-sans: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary-navy), var(--accent-blue));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 2px 4px rgba(26, 54, 93, 0.3);
}

.brand-text h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary-navy);
  letter-spacing: -0.3px;
}

.brand-text p {
  font-size: 11px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  background: #ffffff;
  color: var(--text-main);
}

.btn:hover {
  filter: brightness(0.96);
}

.btn-primary {
  background: var(--primary-navy);
  color: #ffffff;
  border-color: var(--primary-navy);
}

.btn-primary:hover {
  background: var(--primary-navy-dark);
}

.btn-accent {
  background: var(--accent-blue);
  color: #ffffff;
  border-color: var(--accent-blue);
}

.btn-accent:hover {
  background: var(--accent-blue-hover);
}

.btn-outline {
  border-color: var(--border-color);
  background: #ffffff;
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fecaca;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
}

/* Layout */
.app-container {
  display: grid;
  grid-template-columns: 580px 1fr;
  height: calc(100vh - 61px);
  overflow: hidden;
}

@media (max-width: 1200px) {
  .app-container {
    grid-template-columns: 500px 1fr;
  }
}

@media (max-width: 992px) {
  .app-container {
    display: block;
    height: auto;
    overflow: visible;
  }
}

/* Left Panel: Editor */
.editor-panel {
  background: #ffffff;
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  padding: 20px 24px 60px;
  height: 100%;
}

/* Right Panel: Preview Area */
.preview-panel {
  background: #475569;
  background-image: radial-gradient(#64748b 1px, transparent 1px);
  background-size: 20px 20px;
  overflow-y: auto;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  position: relative;
  height: 100%;
}

/* Preview Toolbar */
.preview-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.preview-toolbar span {
  font-size: 12px;
  color: #94a3b8;
}

.preview-toolbar .btn-tool {
  background: transparent;
  border: none;
  color: #e2e8f0;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}

.preview-toolbar .btn-tool:hover {
  background: rgba(255,255,255,0.15);
  color: #ffffff;
}

.preview-toolbar .btn-tool.active {
  background: var(--accent-blue);
  color: #ffffff;
}

/* Sections & Accordions */
.editor-section {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.2s;
}

.editor-section:focus-within {
  border-color: #93c5fd;
}

.section-header {
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.section-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-navy);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header .section-icon {
  color: var(--accent-blue);
  font-size: 15px;
}

.section-body {
  padding: 16px;
}

/* Form Controls */
.form-group {
  margin-bottom: 14px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #475569;
  margin-bottom: 4px;
}

label.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 0;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text-main);
  background: #ffffff;
  transition: all 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
  min-height: 54px;
}

/* Switch Component */
.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: .2s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: var(--primary-navy);
}

input:checked + .slider:before {
  transform: translateX(14px);
}

/* Quick Chips */
.chip-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.chip {
  padding: 4px 10px;
  background: #f1f5f9;
  border: 1px solid var(--border-light);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  background: #e2e8f0;
  color: var(--primary-navy);
}

.chip.active {
  background: var(--primary-navy);
  border-color: var(--primary-navy);
  color: #ffffff;
}

/* Items Table Editor in Sidebar */
.item-card {
  background: #f8fafc;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 10px;
  position: relative;
  transition: all 0.2s;
}

.item-card:hover {
  border-color: #cbd5e1;
  background: #f1f5f9;
}

.item-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 12px;
  color: #64748b;
  font-weight: 500;
}

.item-card-actions {
  display: flex;
  gap: 4px;
}

.item-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
  gap: 8px;
}

@media (max-width: 600px) {
  .item-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Custom Field Item */
.custom-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

/* Toolbar Select Row for Profiles & Customers */
.toolbar-select-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  align-items: center !important;
  width: 100% !important;
}

.toolbar-select-row select {
  flex: 1 1 auto !important;
  width: auto !important;
  min-width: 0 !important;
  height: 34px !important;
  box-sizing: border-box !important;
  padding: 6px 10px !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-sm) !important;
  background-color: #ffffff !important;
  font-size: 13px !important;
}

.toolbar-select-row .btn {
  height: 34px !important;
  padding: 0 10px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

/* ==========================================================================
   A4 INVOICE SHEET (Visual Reference: Rama Excavators PDF & Dalmia Excel)
   ========================================================================== */

.invoice-sheet-wrapper {
  transform-origin: top center;
  transition: transform 0.2s ease;
}

.invoice-sheet {
  width: 210mm;
  min-height: 297mm;
  background: #ffffff;
  box-shadow: var(--shadow-paper);
  padding: 12mm 14mm 14mm 14mm;
  margin: 0 auto;
  color: #000000;
  font-family: 'Roboto', 'Arial', sans-serif;
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Header Area */
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.sheet-company-details {
  flex: 1;
}

.sheet-company-title {
  font-size: 20px;
  font-weight: 700;
  color: #1a365d;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: -0.2px;
  margin-bottom: 6px;
}

.sheet-company-meta {
  font-size: 10.5px;
  line-height: 1.45;
  color: #1e293b;
}

.sheet-company-meta .address-line {
  white-space: pre-line;
}

.sheet-company-meta .strong-label {
  font-weight: 600;
  color: #0f172a;
}

.sheet-logo-container {
  margin-left: 20px;
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.sheet-logo {
  max-width: 340px;
  max-height: 180px;
  height: auto;
  width: auto;
  object-fit: contain;
}

/* Horizontal Top Header if enabled */
.sheet-top-title-bar {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #1a365d;
  letter-spacing: 1px;
  border-bottom: 2px solid #1a365d;
  padding-bottom: 4px;
  margin-bottom: 12px;
}

/* Middle Meta Block (Vertical Badge + Bill To + Ship To + Inv Details) */
.sheet-meta-wrapper {
  display: flex;
  border-top: 1px solid #94a3b8;
  border-bottom: 1px solid #94a3b8;
  margin-bottom: 14px;
  min-height: 105px;
}

/* Vertical Side Title Badge (Matching Rama Excavators PDF) */
.sheet-vertical-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 18px;
  font-weight: 700;
  color: #1a365d;
  letter-spacing: 2px;
  padding: 8px 6px;
  border-right: 1px solid #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

.sheet-address-block {
  flex: 1;
  padding: 8px 12px;
  font-size: 10px;
  line-height: 1.4;
  border-right: 1px solid #e2e8f0;
}

.sheet-address-block:last-child {
  border-right: none;
}

.sheet-block-title {
  font-size: 11px;
  font-weight: 700;
  color: #0f172a;
  text-transform: uppercase;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: 2px;
  margin-bottom: 4px;
  display: inline-block;
}

.sheet-party-name {
  font-size: 11px;
  font-weight: 700;
  color: #000;
  margin-bottom: 2px;
}

.sheet-party-address {
  white-space: pre-line;
  color: #334155;
  margin-bottom: 2px;
}

/* Invoice Info Details Block */
.sheet-invoice-meta {
  width: 175px;
  flex-shrink: 0;
  padding: 8px 10px;
  font-size: 10.5px;
}

.sheet-meta-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sheet-meta-row .meta-lbl {
  font-weight: 600;
  color: #1e293b;
  margin-right: 6px;
}

.sheet-meta-row .meta-val {
  font-weight: 600;
  color: #000000;
  text-align: right;
  word-break: break-all;
}

/* Items Table */
.sheet-table-wrapper {
  margin-bottom: 12px;
  width: 100%;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}

.sheet-table th {
  background-color: #1a365d !important;
  color: #ffffff !important;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  padding: 6px 8px;
  border: 1px solid #000000;
  letter-spacing: 0.3px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.sheet-table td {
  border: 1px solid #000000;
  padding: 4px 8px;
  font-size: 10px;
  line-height: 1.35;
  color: #000000;
  vertical-align: top;
}

.sheet-table .text-left { text-align: left; }
.sheet-table .text-center { text-align: center; }
.sheet-table .text-right { text-align: right; }

.sheet-table .col-desc {
  white-space: pre-wrap;
  word-break: break-word;
}

.sheet-table tr.item-row:hover {
  background-color: #f8fafc;
}

.sheet-table tfoot,
.print-top-spacer-row {
  display: none !important;
}

/* Totals Area */
.sheet-totals-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 4px;
  margin-bottom: 16px;
  page-break-inside: avoid;
}

.sheet-totals-left {
  flex: 1;
  padding-right: 20px;
}

.sheet-thankyou {
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 6px;
}

.sheet-amount-words {
  font-size: 10.5px;
  color: #1e293b;
  font-style: italic;
  line-height: 1.4;
  margin-top: 4px;
  padding: 4px 8px;
  background: #f8fafc;
  border-left: 2px solid #1a365d;
}

.sheet-totals-right {
  width: 240px;
  flex-shrink: 0;
}

.totals-table {
  width: 100%;
  font-size: 10.5px;
  border-collapse: collapse;
}

.totals-table td {
  padding: 3px 6px;
}

.totals-table .tot-label {
  text-align: right;
  font-weight: 600;
  color: #1e293b;
  text-transform: uppercase;
}

.totals-table .tot-val {
  text-align: right;
  font-weight: 500;
  color: #000000;
  width: 100px;
}

.totals-table tr.grand-total-row {
  background-color: #c9daf8 !important;
  border-top: 1px solid #000000;
  border-bottom: 1px solid #000000;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.totals-table tr.grand-total-row td {
  padding: 5px 6px;
  font-weight: 700;
  font-size: 11.5px;
  color: #000000;
}

/* Summary & Footer Group */
.sheet-summary-group {
  margin-top: auto;
  display: flex;
  flex-direction: column;
}

/* Footer & Signatory Area */
.sheet-footer-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #cbd5e1;
  font-size: 10px;
  page-break-inside: avoid;
}

.sheet-footer-left {
  flex: 1;
  padding-right: 24px;
}

.sheet-terms-block {
  margin-bottom: 10px;
}

.sheet-terms-title {
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 2px;
}

.sheet-terms-content {
  white-space: pre-line;
  color: #334155;
  line-height: 1.4;
}

.sheet-contact-query {
  margin-top: 8px;
  color: #334155;
  line-height: 1.4;
  white-space: pre-line;
}

.sheet-computer-gen {
  margin-top: 10px;
  font-size: 9.5px;
  color: #64748b;
  font-style: italic;
}

.sheet-footer-right {
  width: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sheet-bank-details {
  margin-bottom: 16px;
  line-height: 1.4;
}

.sheet-bank-title {
  font-weight: 700;
  color: #0f172a;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.sheet-bank-info {
  white-space: pre-line;
  color: #334155;
}

.sheet-signatory-block {
  margin-top: auto;
  text-align: right;
}

.sheet-signatory-for {
  font-weight: 700;
  font-size: 10.5px;
  color: #0f172a;
  margin-bottom: 6px;
}

.sheet-signature-box {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.sheet-signature-box img {
  max-height: 46px;
  max-width: 140px;
  object-fit: contain;
}

.sheet-signatory-title {
  font-weight: 600;
  color: #0f172a;
  font-size: 10px;
}

.sheet-jurisdiction {
  font-size: 9.5px;
  color: #475569;
  margin-top: 2px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2), 0 8px 10px -6px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary-navy);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* History List inside Modal */
.history-item {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s;
}

.history-item:hover {
  border-color: #93c5fd;
  background: #f8fafc;
}

.history-meta h4 {
  font-size: 14px;
  color: var(--primary-navy);
  font-weight: 600;
}

.history-meta p {
  font-size: 12px;
  color: var(--text-muted);
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s ease-out;
}

.toast-success { background: #065f46; border-left: 4px solid #10b981; }
.toast-error { background: #881337; border-left: 4px solid #ef4444; }
.toast-info { background: #1e293b; border-left: 4px solid var(--accent-blue); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
