/* ==========================================================================
   MD PARTS 4X4 - INVOICE & PROFORMA MAKER STYLESHEET
   ========================================================================== */

:root {
  --font-primary: 'Poppins', 'Inter', system-ui, sans-serif;
  --font-heading: 'Poppins', 'Outfit', system-ui, sans-serif;

  /* mdparts4x4.com Theme Palette (Deep Slate & Signature Red #BF2626) */
  --bg-app: #0d1117;
  --bg-sidebar: #161b22;
  --bg-card: #21262d;
  --bg-input: #0d1117;
  
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --border-color: #30363d;

  --accent-red: #BF2626;
  --accent-red-hover: #9e1f1f;
  --accent-amber: #BF2626;
  --accent-hover: #9e1f1f;
  
  --color-success: #238636;
  --color-danger: #da3633;
  --color-info: #388bfd;

  /* Printable Sheet Variables */
  --sheet-bg: #ffffff;
  --sheet-text: #0d1117;
  --sheet-border: #d0d7de;
  --sheet-header-bg: #f6f8fa;
  --sheet-accent: #BF2626;
}

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

body.app-body {
  font-family: var(--font-primary);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   SECURITY LOCK OVERLAY
   ========================================================================== */
.lock-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(13, 17, 23, 0.96);
  backdrop-filter: blur(12px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lock-overlay.unlocked {
  display: none !important;
}

.lock-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 90%;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8);
}

.lock-logo-wrapper {
  margin: 0 auto 1rem auto;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lock-logo-img {
  height: 100%;
  width: auto;
  object-fit: contain;
}

.lock-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.lock-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.lock-input {
  text-align: center;
  font-size: 1rem;
  letter-spacing: 0.1em;
  padding: 0.75rem 1rem;
}

.lock-error-msg {
  display: none;
  font-size: 0.8rem;
  color: #ef4444;
  margin-top: 0.75rem;
  font-weight: 600;
}

/* ==========================================================================
   Top Header Navigation
   ========================================================================== */
.app-header {
  background-color: #0b1120;
  border-bottom: 1px solid var(--border-color);
  padding: 0.6rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo-wrapper {
  height: 44px;
  max-width: 180px;
  border-radius: 6px;
  overflow: hidden;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logo-img {
  height: 100%;
  width: auto;
  object-fit: contain;
  border-radius: 4px;
}

.brand-title h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #fff;
  line-height: 1.1;
}

.brand-title span {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent-amber);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.doc-type-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-sidebar);
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.doc-type-selector label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-select-header {
  background: transparent;
  border: none;
  color: var(--accent-amber);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.95rem;
  outline: none;
  cursor: pointer;
}

.form-select-header option {
  background-color: var(--bg-sidebar);
  color: var(--text-main);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1.1rem;
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #BF2626, #9e1f1f);
  color: #fff;
  box-shadow: 0 2px 8px rgba(191, 38, 38, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #d32f2f, #BF2626);
  transform: translateY(-1px);
}

.btn-success {
  background-color: var(--color-success);
  color: #fff;
}

.btn-success:hover {
  background-color: #059669;
}

.btn-outline-light {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline-light:hover {
  background: var(--bg-card);
}

.btn-outline-primary {
  background: transparent;
  border: 1px solid var(--accent-amber);
  color: var(--accent-amber);
}

.btn-outline-primary:hover {
  background: rgba(245, 158, 11, 0.15);
}

.btn-accent {
  background: #38bdf8;
  color: #0f172a;
  font-weight: 700;
}

.btn-accent:hover {
  background: #7dd3fc;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-xs {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-block {
  width: 100%;
}

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }

/* Main Workspace Layout */
.app-workspace {
  display: flex;
  flex: 1;
  max-width: 1800px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

/* Sidebar */
.app-sidebar {
  width: 530px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 65px);
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background-color: #0f172a;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
  color: var(--accent-amber);
  border-bottom-color: var(--accent-amber);
  background: var(--bg-sidebar);
}

.tab-content-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.panel-section {
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.section-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent-amber);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.section-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-header-flex .section-title {
  margin-bottom: 0;
}

/* Form Controls */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.form-grid.compact {
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-group.full-width {
  grid-column: span 2;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.45rem 0.75rem;
  color: var(--text-main);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-control:focus {
  border-color: var(--accent-amber);
}

textarea.form-control {
  resize: vertical;
}

/* Logo Upload Row */
.logo-upload-box {
  background: var(--bg-card);
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.logo-preview-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.5rem;
}

.logo-preview-thumb {
  height: 50px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--accent-amber);
  background: #000;
}

/* Line Items Editor Card */
.editor-line-items {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  position: relative;
}

.item-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.item-number-badge {
  font-size: 0.75rem;
  font-weight: 800;
  background: var(--accent-amber);
  color: #fff;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
}

.btn-remove-item {
  background: transparent;
  border: none;
  color: var(--color-danger);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem;
}

.btn-remove-item:hover {
  opacity: 0.8;
}

/* Catalog & History Lists */
.search-box {
  position: relative;
}

.search-box i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-box .form-control {
  padding-left: 2.2rem;
  width: 100%;
}

.catalog-add-new {
  background: var(--bg-sidebar);
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-top: 0.75rem;
}

.catalog-add-new h4 {
  font-size: 0.85rem;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.catalog-list, .history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.catalog-item-card, .history-item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.cat-details h5 {
  font-size: 0.85rem;
  color: #fff;
}

.cat-details p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cat-price {
  font-weight: 700;
  color: var(--accent-amber);
  font-size: 0.9rem;
}

.history-controls {
  display: flex;
  gap: 0.5rem;
}

/* Right Live Preview Sheet Canvas */
.app-preview-area {
  flex: 1;
  background-color: #070b14;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: calc(100vh - 65px);
}

.preview-toolbar {
  width: 100%;
  max-width: 800px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  background: var(--bg-sidebar);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.preview-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-amber);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
}

/* Printable A4 Invoice Sheet */
.invoice-sheet {
  width: 800px;
  min-height: 1060px;
  background-color: var(--sheet-bg);
  color: var(--sheet-text);
  border-radius: 4px;
  padding: 2.5rem 2.5rem 2rem 2.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
}

.sheet-logo {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.5rem;
}

.sheet-logo-img {
  height: 52px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  border-radius: 4px;
}

.sheet-logo .logo-text h2 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--sheet-accent);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.sheet-logo .tagline {
  font-size: 0.73rem;
  color: #64748b;
  font-weight: 700;
}

.comp-meta {
  font-size: 0.75rem;
  color: #475569;
  line-height: 1.4;
}

.comp-meta span {
  color: #64748b;
}

.header-right {
  text-align: right;
}

.doc-badge-container {
  margin-bottom: 0.5rem;
}

.doc-title {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 900;
  color: #0f172a;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.meta-table {
  margin-left: auto;
  font-size: 0.78rem;
  border-collapse: collapse;
}

.meta-table th {
  text-align: right;
  padding: 0.15rem 0.5rem;
  color: #64748b;
  font-weight: 600;
}

.meta-table td {
  text-align: right;
  padding: 0.15rem 0;
  color: #0f172a;
}

.sheet-divider {
  height: 3px;
  background: linear-gradient(to right, #0f172a, var(--accent-amber), #cbd5e1);
  margin: 1.25rem 0;
}

/* Customer Billing Section */
.sheet-parties {
  margin-bottom: 1.25rem;
}

.party-box {
  background-color: var(--sheet-header-bg);
  border: 1px solid var(--sheet-border);
  border-left: 4px solid #BF2626;
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.party-heading {
  font-size: 0.7rem;
  font-weight: 800;
  color: #64748b;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.client-name {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 800;
  color: #0f172a;
}

.client-address {
  font-size: 0.8rem;
  color: #334155;
  margin-bottom: 0.2rem;
}

.party-box p {
  font-size: 0.78rem;
  color: #475569;
}

/* Items Table */
.sheet-table-section {
  flex: 1;
  margin-bottom: 1.25rem;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
}

.items-table th {
  background-color: #BF2626;
  color: #ffffff;
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0.65rem 0.6rem;
  letter-spacing: 0.03em;
}

.items-table th:first-child {
  border-top-left-radius: 4px;
}

.items-table th:last-child {
  border-top-right-radius: 4px;
}

.items-table td {
  padding: 0.6rem 0.6rem;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.82rem;
  color: #1e293b;
  vertical-align: top;
}

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

.item-sku {
  font-weight: 800;
  color: #0f172a;
  font-size: 0.78rem;
}

.item-desc-text {
  font-weight: 500;
}

/* Summary Breakdown Section */
.sheet-summary-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.summary-left {
  flex: 1;
}

.words-box {
  background-color: #f1f5f9;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  border: 1px solid #cbd5e1;
}

.words-box label {
  font-size: 0.68rem;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
}

.words-text {
  font-size: 0.82rem;
  font-weight: 700;
  color: #0f172a;
  font-style: italic;
}

.bank-box label {
  font-size: 0.72rem;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.2rem;
}

.bank-pre {
  font-family: var(--font-primary);
  font-size: 0.73rem;
  color: #334155;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  padding: 0.5rem;
  border-radius: 4px;
  white-space: pre-wrap;
}

.summary-right {
  width: 290px;
}

.totals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.totals-table th {
  text-align: right;
  padding: 0.35rem 0.5rem;
  color: #64748b;
  font-weight: 600;
}

.totals-table td {
  text-align: right;
  padding: 0.35rem 0;
  color: #0f172a;
}

.grand-total-row th, .grand-total-row td {
  border-top: 2px solid #BF2626;
  border-bottom: 2px solid #BF2626;
  padding: 0.5rem 0.5rem;
  font-size: 0.95rem;
  font-weight: 900;
  color: #0f172a;
}

.balance-row th, .balance-row td {
  color: #BF2626;
  font-size: 0.9rem;
}

/* Footer Section */
.sheet-footer {
  border-top: 1px solid #e2e8f0;
  padding-top: 1rem;
}

.notes-container h4 {
  font-size: 0.72rem;
  color: #64748b;
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.notes-container p {
  font-size: 0.75rem;
  color: #475569;
}

.signatures-container {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  gap: 2rem;
}

.sig-box {
  width: 220px;
  text-align: center;
}

.sig-line {
  border-bottom: 1px dashed #94a3b8;
  height: 40px;
  margin-bottom: 0.3rem;
}

.sig-box p {
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
}

/* Modal Overlay & Footers */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

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

.modal-content {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 90%;
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

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

.modal-header h3 {
  font-size: 1rem;
  color: var(--accent-amber);
  font-family: var(--font-heading);
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-app);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

.modal-catalog-grid {
  display: grid;
  grid-template-columns: repeat(1, 1fr);
  gap: 0.5rem;
}

.checklist-item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.checklist-item-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-amber);
  cursor: pointer;
}

/* ==========================================================================
   PRINT MEDIA STYLES (@media print)
   ========================================================================== */
@media print {
  body, html {
    background-color: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .no-print, .no-print-layout > aside, .preview-toolbar, .lock-overlay {
    display: none !important;
  }

  .app-workspace {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .app-preview-area {
    padding: 0 !important;
    background: transparent !important;
    height: auto !important;
    overflow: visible !important;
  }

  .invoice-sheet {
    width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }

  .sheet-header, .sheet-parties, .sheet-table-section, .sheet-summary-section, .sheet-footer {
    page-break-inside: avoid;
  }
}
