/* ==========================================================================
   Modern HTML Invoice System - Main Stylesheet
   Features: Dual View, 7 Themes (including IT Professional Themes),
   A4 Single-Page Optimization, Zero-Form Outline Document View, Client Link View
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-alt: #f8fafc;
  
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-light: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-dark: #cbd5e1;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --transition-fast: all 0.15s ease-in-out;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.45;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 40px;
}

/* Header & Controls */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 10px 20px;
  margin-bottom: 20px;
}

.header-container {
  max-width: 1300px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.brand-logo svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.action-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Mode Switcher Group */
.view-mode-toggle {
  display: flex;
  background: var(--bg-main);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border-color);
}

.view-mode-btn {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.view-mode-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background-color: var(--bg-alt);
  border-color: var(--border-dark);
}

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

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

.btn-success { background-color: #10b981; border-color: #10b981; color: #ffffff; }
.btn-success:hover { background-color: #059669; }
.btn-danger { background-color: #ef4444; border-color: #ef4444; color: #ffffff; }
.btn-danger:hover { background-color: #dc2626; }
.btn-sm { padding: 4px 8px; font-size: 11px; }

/* Main Workspace Layout */
.main-wrapper {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 16px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  align-items: start;
}

.edit-panel {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 20px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.edit-panel-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.edit-panel-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 10px;
}

/* Form Controls */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="tel"],
select,
textarea {
  font-family: inherit;
  font-size: 12px;
  color: var(--text-main);
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  width: 100%;
  outline: none;
  transition: var(--transition-fast);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

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

/* Document Paper Sheet (A4 Proportions) */
.doc-preview-container {
  display: flex;
  justify-content: center;
}

.invoice-paper {
  background: #ffffff;
  width: 100%;
  max-width: 210mm;
  min-height: 297mm;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm);
  padding: 36px 40px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  box-sizing: border-box;
}

/* Document Header Elements */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.doc-company-logo {
  max-width: 160px;
  max-height: 65px;
  object-fit: contain;
  margin-bottom: 8px;
}

.doc-company-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 2px;
}

.doc-text-muted {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.doc-invoice-title {
  font-size: 28px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  text-align: right;
  margin-bottom: 8px;
}

.doc-meta-table {
  font-size: 12px;
  margin-left: auto;
}

.doc-meta-table td {
  padding: 3px 0 3px 12px;
}

.doc-meta-label {
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.doc-billing-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}

.doc-bill-to {
  max-width: 50%;
}

.doc-section-heading {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-paid { background-color: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.badge-unpaid { background-color: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.badge-partially_paid { background-color: #fef3c7; color: #b45309; border: 1px solid #fde68a; }
.badge-overdue { background-color: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.badge-due { background-color: #dbeafe; color: #1d4ed8; border: 1px solid #93c5fd; }

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.doc-table th {
  background-color: var(--bg-alt);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-top: 1px solid var(--border-dark);
  border-bottom: 2px solid var(--border-dark);
  text-align: left;
}

.doc-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  vertical-align: top;
}

.doc-item-title { font-weight: 600; color: var(--text-main); }
.doc-item-desc { font-size: 11px; color: var(--text-muted); }

.doc-summary-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.doc-payment-box {
  background-color: var(--bg-alt);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 11px;
  border: 1px solid var(--border-color);
  max-width: 340px;
}

.doc-totals-box {
  width: 280px;
  font-size: 12px;
}

.doc-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  color: var(--text-muted);
}

.doc-total-row.grand-total {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
  border-top: 2px solid var(--primary);
  border-bottom: 2px solid var(--primary);
  padding: 8px 0;
  margin-top: 4px;
}

.doc-total-row.balance-due {
  font-size: 13px;
  font-weight: 700;
  color: #dc2626;
  background: #fef2f2;
  padding: 6px 8px;
  border-radius: 4px;
  margin-top: 6px;
}

.doc-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 16px;
}

.doc-notes-terms { max-width: 55%; font-size: 11px; }
.doc-signature-block { text-align: right; }
.doc-signature-img { max-width: 140px; max-height: 50px; object-fit: contain; margin-bottom: 4px; }
.doc-footer-bar { border-top: 1px solid var(--border-color); padding-top: 12px; text-align: center; font-size: 11px; color: var(--text-muted); }

/* ==========================================================================
   7 Professional Invoice Templates (Including IT Professional Themes)
   ========================================================================== */

/* Theme 1: Modern Blue (Default) */
.template-modern { --primary: #2563eb; }

/* Theme 2: Corporate Executive Banner */
.template-corporate { --primary: #0f172a; }
.template-corporate .doc-header {
  background: #0f172a; color: #ffffff;
  margin: -36px -40px 24px -40px; padding: 30px 40px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.template-corporate .doc-company-title, .template-corporate .doc-invoice-title { color: #ffffff; }
.template-corporate .doc-text-muted { color: #94a3b8; }

/* Theme 3: Minimalist Mono */
.template-minimalist { --primary: #000000; font-family: 'Courier New', Courier, monospace; }
.template-minimalist .doc-table th { background: transparent; border-top: 2px solid #000; border-bottom: 2px solid #000; }

/* Theme 4: Classic Business */
.template-classic { --primary: #1e3a8a; border: 3px double #1e3a8a; }
.template-classic .doc-table th { background-color: #1e3a8a; color: #ffffff; }

/* Theme 5 (IT Professional): Tech Cyan / SaaS Agency */
.template-it-tech { --primary: #0891b2; }
.template-it-tech .doc-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #ffffff;
  margin: -36px -40px 24px -40px; padding: 30px 40px;
  border-bottom: 3px solid #0891b2;
}
.template-it-tech .doc-company-title { color: #ffffff; font-weight: 900; }
.template-it-tech .doc-invoice-title { color: #22d3ee; }
.template-it-tech .doc-text-muted { color: #94a3b8; }
.template-it-tech .doc-table th { background-color: #0f172a; color: #38bdf8; border-top: none; }

/* Theme 6 (IT Professional): Midnight Agency Dark Mode */
.template-it-dark {
  --primary: #10b981;
  background: #0f172a !important;
  color: #f8fafc !important;
}
.template-it-dark .doc-company-title, .template-it-dark .doc-item-title { color: #ffffff !important; }
.template-it-dark .doc-text-muted, .template-it-dark .doc-item-desc { color: #94a3b8 !important; }
.template-it-dark .doc-table th { background-color: #1e293b !important; color: #34d399 !important; border-color: #334155 !important; }
.template-it-dark td, .template-it-dark div, .template-it-dark span { border-color: #334155 !important; }
.template-it-dark .doc-payment-box { background-color: #1e293b !important; border-color: #334155 !important; }

/* Theme 7 (IT Professional): Silicon Valley Indigo Minimalist */
.template-it-minimal { --primary: #4f46e5; }
.template-it-minimal .doc-header { border-bottom: 2px solid #6366f1; padding-bottom: 16px; }
.template-it-minimal .doc-invoice-title { color: #4f46e5; letter-spacing: 0.1em; }
.template-it-minimal .doc-table th { background: #e0e7ff; color: #3730a3; }

/* Client View Mode Styling (When client opens ?inv=... link) */
body.client-view .edit-panel,
body.client-view .view-mode-toggle,
body.client-view #templateSelect,
body.client-view #createNewBtn,
body.client-view #saveInvoiceBtn,
body.client-view #loadInvoiceBtn,
body.client-view #duplicateInvoiceBtn,
body.client-view #shareLinkBtn,
body.client-view a[href="settings.html"],
body.client-view #resetInvoiceBtn {
  display: none !important;
}

body.client-view .workspace-grid { grid-template-columns: 1fr !important; }
body.client-view .client-pay-bar { display: flex !important; }

.client-pay-bar {
  display: none;
  align-items: center;
  gap: 10px;
}

/* Modals & Toast */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-fast);
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%; max-width: 580px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: var(--bg-alt); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-alt); }

.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 6px; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; }
.toast-success { background: #059669; }
.toast-error { background: #dc2626; }
.toast-info { background: #2563eb; }

/* Print Styles */
@media print {
  body { background: #ffffff !important; padding: 0 !important; }
  .app-header, .edit-panel, .action-toolbar, .view-mode-toggle, .hide-on-print { display: none !important; }
  .main-wrapper { max-width: 100% !important; padding: 0 !important; }
  .workspace-grid { display: block !important; }
  .invoice-paper {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    width: 100% !important;
    min-height: auto !important;
  }
}

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