@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700;800;900&family=Outfit:wght@300;400;500;600;700&family=Playfair+Display:wght@700&display=swap');

:root {
  --primary: #0f172a;
  --primary-light: #1e293b;
  --accent: #d97706;
  --accent-gold: #f59e0b;
  --accent-gradient: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  --brand-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  --bg-dark: #090d16;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --danger: #ef4444;
  --success: #10b981;
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bg-card-border);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: var(--accent-gradient);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 22px;
  color: #fff;
  box-shadow: 0 4px 15px rgba(217, 119, 6, 0.35);
}

.brand-title {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #ffffff 0%, #fcd34d 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(217, 119, 6, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
}

.btn-danger-outline {
  background: transparent;
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 6px 10px;
  border-radius: 8px;
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.15);
}

.btn-icon-only {
  padding: 8px;
  border-radius: 8px;
}

/* Layout */
.app-container {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1750px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

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

/* Panels */
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 12px;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Form Controls */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.form-label .optional {
  font-size: 11px;
  color: #64748b;
  font-weight: 400;
}

.form-input, .form-select, .form-textarea {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.form-textarea {
  resize: vertical;
  min-height: 60px;
}

/* Charges Table */
.charges-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.charge-row {
  display: grid;
  grid-template-columns: 1fr 180px 40px;
  gap: 12px;
  align-items: center;
  background: rgba(30, 41, 59, 0.4);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.charge-row-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 0 12px 6px;
  display: grid;
  grid-template-columns: 1fr 180px 40px;
  gap: 12px;
}

.charge-total-display {
  font-weight: 600;
  color: #cbd5e1;
  text-align: right;
  padding-right: 8px;
  font-size: 14px;
}

/* Totals Box */
.totals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 10px;
}

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

.summary-box {
  background: rgba(30, 41, 59, 0.6);
  padding: 16px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-line {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-muted);
}

.summary-line.grand-total {
  font-size: 18px;
  font-weight: 700;
  color: #fcd34d;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
  margin-top: 4px;
}

/* Preview Panel */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 90px;
  height: fit-content;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: 12px;
  padding: 12px 20px;
}

.preview-wrapper {
  overflow-x: auto;
  display: flex;
  justify-content: center;
  padding-bottom: 30px;
}

/* A4 Sheet Preview (210mm x 297mm) */
.a4-sheet {
  width: 210mm;
  min-height: 297mm;
  background: #ffffff;
  color: #1e293b;
  padding: 20mm 18mm;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  font-family: 'Outfit', sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-sizing: border-box;
}

/* Invoice Header in A4 */
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 18px;
  margin-bottom: 20px;
}

.sheet-brand-logo {
  font-family: 'Cinzel', serif;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #0f172a;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.sheet-brand-sub {
  font-size: 10px;
  letter-spacing: 2px;
  color: #d97706;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.sheet-brand-meta {
  font-size: 11px;
  color: #64748b;
  line-height: 1.4;
}

.sheet-invoice-title {
  text-align: right;
}

.sheet-title-text {
  font-family: 'Cinzel', serif;
  font-size: 28px;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: 1px;
}

.sheet-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.sheet-badge.pending {
  background: #fef3c7;
  color: #92400e;
}
.sheet-badge.paid {
  background: #d1fae5;
  color: #065f46;
}
.sheet-badge.draft {
  background: #f1f5f9;
  color: #475569;
}

.sheet-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.meta-block h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #94a3b8;
  margin-bottom: 6px;
  font-weight: 700;
}

.meta-block .party-name {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.meta-block p {
  font-size: 12px;
  color: #475569;
  line-height: 1.4;
}

.meta-details-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px dashed #e2e8f0;
}

.meta-details-row span:first-child {
  color: #64748b;
  font-weight: 500;
}

.meta-details-row span:last-child {
  color: #0f172a;
  font-weight: 600;
}

/* Sheet Table */
.sheet-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.sheet-table th {
  background: #0f172a;
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 10px 12px;
  text-align: left;
}

.sheet-table th:last-child, .sheet-table td:last-child {
  text-align: right;
}

.sheet-table th:nth-child(2), .sheet-table td:nth-child(2),
.sheet-table th:nth-child(3), .sheet-table td:nth-child(3) {
  text-align: center;
}

.sheet-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 12px;
  color: #334155;
}

.sheet-table tr:nth-child(even) td {
  background: #f8fafc;
}

.sheet-table .item-name {
  font-weight: 600;
  color: #0f172a;
}

/* Sheet Summary & Notes */
.sheet-footer-section {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
  margin-top: 10px;
}

.sheet-notes-box h4 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #64748b;
  margin-bottom: 6px;
}

.sheet-notes-box p {
  font-size: 11px;
  color: #64748b;
  line-height: 1.5;
}

.sheet-calc-table {
  width: 100%;
}

.sheet-calc-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 12px;
  color: #475569;
}

.sheet-calc-row.total {
  font-size: 16px;
  font-weight: 800;
  color: #0f172a;
  border-top: 2px solid #0f172a;
  padding-top: 8px;
  margin-top: 4px;
}

/* Signature */
.sheet-sign-area {
  margin-top: 36px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-top: 1px solid #e2e8f0;
  padding-top: 16px;
}

.sign-block {
  text-align: right;
  margin-left: auto;
}

.sign-line {
  width: 180px;
  border-bottom: 1px solid #0f172a;
  margin-bottom: 6px;
  margin-left: auto;
}

.sign-block p {
  font-size: 11px;
  color: #64748b;
  font-weight: 600;
}

.sign-block .sign-company {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
}

/* Modal for Saved Invoices */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

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

.modal-content {
  background: #0f172a;
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 800px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

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

.invoice-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: all 0.2s;
}

.invoice-list-item:hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: var(--accent-gold);
}

/* Print CSS */
@media print {
  body * {
    visibility: hidden;
  }
  .app-header, .editor-panel, .preview-toolbar, .modal-overlay {
    display: none !important;
  }
  .app-container {
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }
  .preview-wrapper {
    padding: 0 !important;
  }
  #invoiceSheet, #invoiceSheet * {
    visibility: visible;
  }
  #invoiceSheet {
    position: absolute;
    left: 0;
    top: 0;
    width: 210mm !important;
    min-height: 297mm !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 18mm !important;
  }
}
