/* ==========================================================================
   Design System & Styling Variables
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&family=Fira+Code:wght@400;500&display=swap');

:root {
  /* Dark Theme Palette (Default) */
  --bg-app: #070a13;
  --bg-gradient: radial-gradient(circle at 50% 0%, #151e36 0%, #070a13 80%);
  --bg-panel: rgba(13, 20, 38, 0.65);
  --bg-panel-hover: rgba(18, 27, 51, 0.8);
  --bg-input: rgba(7, 10, 19, 0.6);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);

  /* Accent Shades */
  --accent: #10b981;
  /* Emerald */
  --accent-rgb: 16, 185, 129;
  --accent-hover: #059669;
  --accent-secondary: #f59e0b;
  /* Amber */
  --accent-secondary-rgb: 245, 158, 11;
  --accent-danger: #ef4444;
  /* Rose */

  /* Text */
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-inverse: #070a13;

  /* Font Families */
  --font-sans: 'Inter', sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'Fira Code', monospace;

  /* Shadows & Glassmorphism */
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --glass-blur: blur(12px);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

/* Light Theme Overrides */
.light-theme {
  --bg-app: #f4f6fa;
  --bg-gradient: radial-gradient(circle at 50% 0%, #e0e6f3 0%, #f4f6fa 80%);
  --bg-panel: rgba(255, 255, 255, 0.8);
  --bg-panel-hover: rgba(255, 255, 255, 0.95);
  --bg-input: #ffffff;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.16);

  /* Text */
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --glass-shadow: 0 8px 32px 0 rgba(148, 163, 184, 0.18);
}

/* ==========================================================================
   Base Elements
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-app);
  background-image: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  transition: background var(--transition-smooth);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.light-theme ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
}

.light-theme ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Header Component
   ========================================================================== */
header {
  padding: 24px 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: var(--glass-blur);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo-container {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 0 15px var(--accent-glow);
}

.brand-title h1 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(to right, var(--text-main), var(--text-muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-title p {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

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

.btn-icon {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.btn-icon:hover {
  background: var(--bg-panel-hover);
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 15px var(--accent-glow);
  transition: var(--transition-smooth);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

/* ==========================================================================
   Layout & Container
   ========================================================================== */
.app-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 24px;
}

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

/* Pane Wrappers */
.editor-pane,
.preview-pane {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
  padding: 24px;
  transition: border-color var(--transition-smooth);
}

.panel-card:hover {
  border-color: var(--border-hover);
}

.panel-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.panel-title i {
  color: var(--accent);
}

/* ==========================================================================
   Form Styling (Left Editor Pane)
   ========================================================================== */
.form-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: rgba(0, 0, 0, 0.15);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 500;
  font-size: 0.85rem;
  transition: var(--transition-smooth);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.tab-btn.active {
  background: var(--bg-input);
  color: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Form Groups */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {

  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

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

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.form-control {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition-smooth);
  width: 100%;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-control::placeholder {
  color: rgba(255, 255, 255, 0.25);
}

.light-theme .form-control::placeholder {
  color: rgba(0, 0, 0, 0.3);
}

/* Product Image Upload Panel */
.uploader-area {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition-smooth);
  background: rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.uploader-area:hover {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.03);
}

.uploader-area i {
  font-size: 2.2rem;
  color: var(--text-muted);
  transition: var(--transition-smooth);
}

.uploader-area:hover i {
  color: var(--accent);
  transform: translateY(-2px);
}

.uploader-text p {
  font-size: 0.9rem;
  font-weight: 500;
}

.uploader-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.image-preview-container {
  margin-top: 15px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.image-preview-thumb {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border-color);
}

.image-preview-info {
  flex: 1;
}

.image-preview-name {
  font-size: 0.85rem;
  font-weight: 500;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-preview-size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-remove-image {
  background: transparent;
  border: none;
  color: var(--accent-danger);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition-smooth);
}

.btn-remove-image:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* Sizing Ratio Table Editor */
.sizing-grid-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.1);
}

.sizing-edit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.sizing-edit-table th,
.sizing-edit-table td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

.sizing-edit-table th:last-child,
.sizing-edit-table td:last-child {
  border-right: none;
}

.sizing-edit-table th {
  background: rgba(0, 0, 0, 0.2);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.sizing-edit-table tr:last-child td {
  border-bottom: none;
}

.sizing-edit-table .row-title {
  text-align: left;
  font-weight: 600;
  color: var(--text-main);
  padding-left: 12px;
  background: rgba(0, 0, 0, 0.1);
  width: 100px;
}

.sizing-edit-table input {
  width: 50px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  text-align: center;
  padding: 4px;
  border-radius: var(--radius-sm);
  outline: none;
  font-family: var(--font-sans);
  font-weight: 500;
}

.sizing-edit-table input:focus {
  border-color: var(--accent);
}

.sizing-edit-table .col-total {
  font-weight: 700;
  color: var(--accent-secondary);
  font-family: var(--font-mono);
}

/* Terms and Conditions Editor */
.terms-editor-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}

.term-item {
  display: flex;
  gap: 10px;
  background: var(--bg-input);
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  align-items: flex-start;
}

.term-number {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 4px;
}

.term-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  resize: vertical;
  outline: none;
  line-height: 1.4;
  min-height: 40px;
}

.btn-delete-term {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: var(--transition-smooth);
}

.btn-delete-term:hover {
  color: var(--accent-danger);
  background: rgba(239, 68, 68, 0.1);
}

.btn-add-term {
  background: transparent;
  border: 1px dashed var(--border-color);
  color: var(--accent);
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn-add-term:hover {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.05);
}

/* Debit Note Setup rules */
.debit-note-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.debit-note-rule {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.debit-note-rule span {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.debit-note-rule input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  outline: none;
  padding: 2px 0;
  width: 100%;
}

.debit-note-rule input:focus {
  border-color: var(--accent);
}

/* ==========================================================================
   Live Sheet Preview Pane (Right Column)
   ========================================================================== */
.preview-container {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: #ffffff;
  /* Explicitly white like Excel */
  box-shadow: var(--glass-shadow);
  overflow: hidden;
  color: #000000;
  /* Standard excel dark print text */
}

/* Excel Style Toolbar Header */
.excel-header-bar {
  background: #f3f2f1;
  border-bottom: 1px solid #d2d0ce;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.excel-tab-container {
  display: flex;
  gap: 16px;
}

.excel-tab {
  font-size: 0.75rem;
  font-weight: 600;
  color: #323130;
  padding: 4px 8px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.excel-tab.active {
  color: #107c41;
  /* Excel green */
  border-bottom-color: #107c41;
}

.excel-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: #605e5c;
  font-weight: 500;
}

.excel-indicator i {
  color: #107c41;
}

/* Excel Sheet Body Grid */
.excel-viewport {
  overflow: auto;
  max-height: 800px;
  padding: 20px;
  background: #e1dfdd;
  /* Subtle background margin */
  display: flex;
  justify-content: center;
}

.excel-sheet-paper {
  background: #ffffff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  width: 800px;
  min-height: 1050px;
  padding: 30px;
  position: relative;
  font-family: 'Calibri', 'Arial', sans-serif;
  box-sizing: border-box;
}

/* Print simulation lines */
.excel-grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  color: #000000;
  table-layout: fixed;
}

/* Simulated grid borders */
.excel-grid-table td {
  border: 1px solid #d0d0d0;
  padding: 4px 6px;
  vertical-align: middle;
  height: 22px;
  word-wrap: break-word;
  overflow: hidden;
}

/* Base Typography Styles for sheet */
.txt-center {
  text-align: center;
}

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

.txt-left {
  text-align: left;
}

.font-bold {
  font-weight: bold;
}

.border-double-bottom {
  border-bottom: 3px double #000000 !important;
}

.border-thick-bottom {
  border-bottom: 2px solid #000000 !important;
}

/* Special Styled PO Sections */
.po-main-title {
  font-size: 1.6rem;
  font-family: 'Georgia', serif;
  font-weight: bold;
  text-align: center;
  height: 40px !important;
  border: none !important;
}

.company-title {
  font-size: 0.95rem;
  font-weight: bold;
}

.company-subtext {
  font-size: 0.7rem;
  color: #333;
}

.po-meta-header {
  background: #f2f2f2;
  font-weight: bold;
}

.po-meta-highlight {
  background: #ffff00;
  /* Bright Yellow */
  font-weight: bold;
}

.product-image-cell {
  background: #ffffff;
  padding: 4px !important;
  text-align: center;
  position: relative;
}

.preview-product-img {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.image-placeholder-box {
  width: 100%;
  height: 180px;
  border: 1px dashed #a0a0a0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #707070;
  background: #fafafa;
}

.image-placeholder-box i {
  font-size: 1.5rem;
  margin-bottom: 6px;
}

/* Details and Sizes Header styling */
.header-row-excel {
  background: #f2f2f2;
  font-weight: bold;
}

.sizing-title-row {
  background: #e4e4e4;
  font-weight: bold;
  height: 25px !important;
  font-size: 0.85rem;
}

.sizing-label-cell {
  background: #f2f2f2;
  font-weight: bold;
}

.sizing-total-row {
  font-weight: bold;
  background: #ffff00;
}

/* Terms Table Style */
.terms-section-title {
  font-weight: bold;
  background: #b4c6e7;
  padding-left: 8px !important;
}

.terms-highlight-row {
  font-weight: bold;
  color: #c00000;
  /* Dark Red text */
}

.terms-debit-table td {
  border: none !important;
  padding: 2px 4px !important;
}

.terms-list-cell {
  border: none !important;
  padding: 2px 4px !important;
  font-size: 0.68rem;
  line-height: 1.25;
  color: #333;
}

.stamp-cell {
  border: none !important;
  text-align: center;
  padding: 10px 0 !important;
}

.stamp-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 10px;
}

.stamp-img {
  width: 60px;
  height: 60px;
  margin-bottom: 4px;
  opacity: 0.85;
}

.stamp-name {
  font-weight: bold;
  font-size: 0.75rem;
}

.stamp-title {
  font-size: 0.65rem;
  color: #555;
}

/* Bottom footer of Preview Card */
.preview-footer-bar {
  background: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.preview-status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* ==========================================================================
   Utility Classes & UI Decorations
   ========================================================================== */
.glow-text {
  text-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

/* Footer Credits */
footer.app-footer {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-color);
  margin-top: 40px;
}

footer.app-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

footer.app-footer a:hover {
  text-decoration: underline;
}