/* INVOICE TOOL - STYLESHEET */


/* Site UI font (PDF uses embedded fonts below) */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600;700&display=swap');

/* PDF Google Fonts - loaded in HTML head for reliable PDF rendering */
.pdf-header-font {
  font-family: 'Rubik', Arial, sans-serif;
  font-weight: 700;
}

.pdf-body-font {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-weight: 300;
}

/* ====================== TYPOGRAPHY SCALE ====================== */
/* Consistent font sizing system - minimum 10px for readability */
:root {
  --font-size-h1: 20px;      /* Page title (INVOICE TOOL) - increased for prominence */
  --font-size-h3: 12px;      /* Section headers (FROM, BILL TO, LINE ITEMS) */
  --font-size-h4: 11px;      /* Subsection headers (Page Setup, File Upload) */
  --font-size-body: 12px;    /* Input fields, normal text, form content */
  --font-size-label: 10px;   /* Form labels, helper text - MINIMUM READABLE SIZE */
  --font-size-button: 11px;  /* Buttons, interactive elements */
}

/* ====================== RESPONSIVE LAYOUT ====================== */

.app-container {
  max-width: 1400px;
  margin: 0 auto;
}

.content-section {
  display: grid;
  gap: 24px;
  grid-template-areas: "left right";
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto;
}

.content-left {
  grid-area: left;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.content-right {
  grid-area: right;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 20px;
  align-self: start;
}

/* Narrow screen layout - stack vertically */
@media (max-width: 1199px) {
  .app-container {
    margin: 0 15%;
  }

  .content-section {
    grid-template-areas:
      "left"
      "right";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .content-right {
    position: static;
  }
}

@media (max-width: 768px) {
  .app-container {
    margin: 0 5%;
  }
}

/* Preview actions - buttons side by side */
.preview-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  justify-content: flex-start;
}

@media (max-width: 768px) {
  .preview-actions {
    flex-direction: column;
  }
}

.preview-actions .go {
  background: var(--accent);
  color: var(--bg);
  border: none;
  padding: 16px 32px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
}

.preview-actions .dl-btn {
  background: var(--border);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 12px 24px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.preview-actions .dl-btn:hover {
  background: var(--panel-bg);
  border-color: var(--fg);
}

.preview-actions .go:hover {
  opacity: 0.8;
}

/* === COLLAPSIBLE SECTIONS (PDF Settings & CSV Import) === */
/* Both use identical styling for consistency */

details.pdf-settings,
details.csv-import-settings {
  width: 100%;
  margin-bottom: 16px;
}

/* Summary buttons - identical styling */
details.pdf-settings summary,
details.csv-import-settings summary {
  padding: 12px 16px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  cursor: pointer;
  text-transform: uppercase;
  font-size: var(--font-size-h3);  /* 11px */
  font-weight: 600;
  letter-spacing: 1px;
  font-family: 'IBM Plex Mono', monospace;
  transition: background 0.2s;
}

details.pdf-settings summary:hover,
details.csv-import-settings summary:hover {
  background: var(--border);
}

details.pdf-settings[open] summary,
details.csv-import-settings[open] summary {
  border-bottom: none;
}

/* Content areas - identical styling */
.pdf-content,
.csv-import-content {
  padding: 20px 16px;
  border: 1px solid var(--border);
  border-top: none;
  background: var(--panel-bg);
}

/* Import-specific button styling */
.csv-import-content .import-btn {
  width: 100%;
  min-height: 40px;
  padding: 10px 20px;
  font-size: var(--font-size-button);  /* 10px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid var(--ui-fg);
  background: var(--ui-fg);
  color: var(--ui-bg);
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
}

.csv-import-content .import-btn:hover {
  background: var(--border);
  color: var(--ui-fg);
}

.csv-import-content .clear-items-btn {
  width: 100%;
  min-height: 40px;
  padding: 10px 20px;
  font-size: var(--font-size-button);  /* 10px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid #dc2626;
  background: transparent;
  color: #dc2626;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
}

.csv-import-content .clear-items-btn:hover {
  background: #dc2626;
  color: white;
  border-color: #dc2626;
}

.csv-import-content input[type="file"] {
  padding: 8px;
  font-size: var(--font-size-body);  /* 11px */
  font-family: 'IBM Plex Mono', monospace;
}

.csv-import-content textarea {
  font-family: 'IBM Plex Mono', monospace;
  font-size: var(--font-size-body);  /* 11px */
  min-height: 80px;
  line-height: 1.4;
}

/* Theme toggle styling */

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: var(--panel-bg);
  border-color: var(--ui-fg);
}

/* Template system */
.templates {
  padding: 16px;  /* Standardized */
}

.templates h3 {
  font-size: var(--font-size-h3);  /* 11px */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  border-bottom: 0.5px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 15px;
}

/* Quick Access Row */
.template-quick-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}

.template-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  max-height: 40px;  /* Prevent growing */
  padding: 10px 16px;
  font-size: var(--font-size-button);  /* 11px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ui-fg);
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-chip:hover {
  background: var(--border);
  border-color: var(--ui-fg);
}

.filter-chip.active {
  background: var(--ui-fg);
  color: var(--ui-bg);
  border-color: var(--ui-fg);
}

.recent-chip {
  opacity: 0.7;
}

.load-btn {
  min-height: 40px;
  max-height: 40px;  /* Prevent growing */
  padding: 10px 20px;
  font-size: var(--font-size-button);  /* 11px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--ui-fg);
  color: var(--ui-bg);
  border: 1px solid var(--ui-fg);
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.load-btn:hover {
  background: var(--border);
  color: var(--ui-fg);
}

/* Management Section */
.template-manage-section {
  padding-top: 16px;
  border-top: 0.5px solid var(--border);
  margin-top: 4px;
}

.template-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.template-input-group {
  position: relative;  /* For absolute positioned dropdown */
  flex: 1;
}

/* Template input wrapper - flex container for input + toggle button */
.template-input-wrapper {
  display: flex;
  gap: 4px;
  width: 100%;
  align-items: stretch;  /* Ensure equal height */
}

.template-input-wrapper input {
  flex: 1;
  min-height: 36px;  /* Match all inputs */
}

.template-input-group input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ui-fg);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  min-height: 36px;  /* Standardized */
}

/* Dropdown toggle button */
.template-dropdown-toggle {
  min-height: 36px;  /* Match input height exactly */
  min-width: 40px;   /* Consistent width */
  padding: 8px 12px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-fg);
}

.template-dropdown-toggle:hover {
  background: var(--border);
  border-color: var(--ui-fg);
}

.template-dropdown-toggle:active {
  background: var(--ui-fg);
  color: var(--ui-bg);
}

.dropdown-icon {
  font-size: 10px;
  line-height: 1;
}

/* Custom dropdown container */
.template-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  max-height: 340px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  font-family: 'IBM Plex Mono', monospace;
}

/* Dropdown sections */
.template-dropdown-section {
  border-bottom: 1px solid var(--border);
}

.template-dropdown-section:last-child {
  border-bottom: none;
}

/* Section titles with icons */
.template-dropdown-section-title {
  font-size: var(--font-size-label);  /* 10px - minimum readable size */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 10px 14px 6px 14px;
  color: var(--ui-fg);
  opacity: 0.7;
  background: var(--ui-bg);
}

/* Dropdown items */
.template-dropdown-item {
  font-size: var(--font-size-button);  /* 10px */
  padding: 9px 18px;
  cursor: pointer;
  transition: all 0.12s ease;
  color: var(--ui-fg);
}

.template-dropdown-item:hover {
  background: var(--ui-fg);
  color: var(--ui-bg);
}

/* Starred items get gold star */
.template-dropdown-item.starred::before {
  content: '★ ';
  color: #f59e0b;
  margin-right: 4px;
}

.template-actions-row {
  display: flex;
  gap: 4px;
}

.action-icon {
  min-width: 40px;
  max-width: 40px;
  min-height: 40px;
  max-height: 40px;  /* Match all template section buttons */
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 14px;  /* Slightly larger emoji */
}

.action-icon:hover {
  background: var(--border);
}

.action-icon.active {
  background: var(--ui-fg);
  color: var(--ui-bg);
}

.action-icon.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .template-quick-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .template-input-row {
    flex-direction: column;
    gap: 8px;
  }

  .template-actions-row {
    justify-content: center;
  }
}

/* PDF Settings styling */
.pdf-settings {
  width: 100%;
}

.pdf-settings summary {
  padding: 12px 16px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
}

.pdf-settings summary:hover {
  background: var(--border);
}

.pdf-settings[open] summary {
  border-bottom: none;
}

.pdf-content {
  border: 1px solid var(--border);
  border-top: none;
  padding: 16px;
  background: var(--panel-bg);
}

.settings-grid {
  display: grid;
  gap: 24px;
}

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

.settings-group h4 {
  font-size: var(--font-size-h4);  /* 10px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  color: var(--ui-fg);
}

.setting-row {
  margin-bottom: 12px;
}

.setting-row label {
  display: block;
  font-size: var(--font-size-label);  /* 9px */
  font-weight: 500;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ui-fg);
}

.color-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-control input[type="text"] {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  padding: 4px 6px;
  border: 1px solid var(--border);
  background: var(--ui-bg);
  color: var(--ui-fg);
  width: 70px;
  text-align: center;
}

/* Manual theme switching */
[data-theme='light'] {
  --ui-bg: #fff;
  --ui-fg: #000;
  --panel-bg: #fff;
  --border: #666;
  --grid: #ccc;
}

[data-theme='dark'] {
  --ui-bg: #000;
  --ui-fg: #fff;
  --panel-bg: #111;
  --border: #888;
  --grid: #555;
}

body {
  background: var(--ui-bg);
  color: var(--ui-fg);
}

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

body {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  line-height: 1.35;
}

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

@media (max-width: 768px) {
  .main {
    padding: 15px;
  }
}

.card {
  background: var(--panel-bg);
  border: 0.5px solid var(--border);
  padding: 16px;  /* Standardized base padding */
}

.header {
  padding: 16px;  /* Standardized */
  margin-bottom: 20px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-text {
  flex: 1;
}

.header h1 {
  font-size: var(--font-size-h1);  /* 18px - consistent with technical design */
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.subtitle {
  font-size: var(--font-size-body);  /* 11px - consistent with body text */
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.8;
}

@media (max-width: 768px) {
  .header h1 {
    font-size: 18px;  /* Slightly smaller than desktop 20px but still prominent */
    letter-spacing: 1px;
  }
  .subtitle {
    font-size: 11px;  /* Maintain readability on mobile */
    letter-spacing: 1.5px;
  }
}

.settings {
  padding: 16px;
  margin-bottom: 20px;
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(12, 1fr);
}

@media (max-width: 768px) {
  .grid {
    gap: 12px;
  }
}

fieldset.panel {
  grid-column: span 12;
  border: 0.5px solid var(--border);
  padding: 12px;
}

fieldset.panel legend {
  padding: 0 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 10px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

.group {
  min-width: 260px;
}

@media (max-width: 768px) {
  .row {
    flex-direction: column;
    align-items: stretch;
    gap: 15px;
  }
  .group {
    min-width: auto;
    width: 100%;
  }
}

label {
  display: block;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

select,
input[type='color'],
input[type='checkbox'],
input[type='file'],
input[type='text'] {
  border: 0.5px solid var(--border);
  background: transparent;
  color: inherit;
  padding: 6px;
  min-width: 160px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
}

@media (max-width: 768px) {
  select,
  input[type='color'],
  input[type='checkbox'],
  input[type='file'],
  input[type='text'] {
    min-width: auto;
    width: 100%;
    padding: 10px;
    font-size: 12px;
    border-width: 1px;
  }
}

input[type='text'] {
  cursor: text;
}

.swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 0.5px solid var(--border);
  margin-left: 6px;
  vertical-align: middle;
}

.note {
  font-size: 10px;
  opacity: 0.8;
  margin-top: 6px;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  margin-left: 6px;
  vertical-align: middle;
}

.ok {
  background: #27ae60;
}

.warn {
  background: #f39c12;
}

.err {
  background: #e74c3c;
}

.logo-box {
  border: 0.5px dashed var(--border);
  padding: 10px;
  text-align: center;
}

.logo-box input[type='file'] {
  display: none;
}

.logo-btn {
  cursor: pointer;
  padding: 8px 15px;
  background: #000;
  color: #fff;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 10px;
  display: inline-block;
}

#logoPreview {
  max-width: 180px;
  max-height: 60px;
  margin-top: 10px;
  display: none;
}

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

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

.section {
  padding: 16px;  /* Standardized */
}

.section h3 {
  font-size: var(--font-size-h3);  /* 11px */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  border-bottom: 0.5px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 15px;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 2fr;
  align-items: center;
  margin-bottom: 8px;
}

.label {
  font-size: var(--font-size-label);  /* 9px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-right: 10px;
}

/* Invoice number group styling */
.invoice-number-group {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: 'IBM Plex Mono', monospace;
}

.invoice-prefix,
.invoice-separator {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-fg);
}

.invoice-number-group input {
  padding: 4px 6px;
  border: 0.5px solid var(--grid);
  background: transparent;
  color: inherit;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
}

.invoice-number-group #companyAbbrev {
  width: 80px;
}

.invoice-number-group #invoiceSequence {
  width: 60px;
}

input[type='text'],
input[type='date'],
input[type='number'],
select,
textarea {
  width: 100%;
  min-height: 36px;  /* Standardized height for all inputs */
  padding: 8px 10px;  /* Consistent padding */
  border: 1px solid var(--border);  /* Consistent border */
  background: transparent;
  color: inherit;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
}

textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.4;
}

/* Due date button selection controls */
.due-date-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.due-date-buttons {
  display: flex;
  gap: 6px;
}

.due-date-btn {
  flex: 1;
  min-height: 40px;  /* Standardized with all primary buttons */
  padding: 10px 16px;
  font-size: var(--font-size-button);  /* 10px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--ui-fg);
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
}

.due-date-btn:hover {
  background: var(--border);
  border-color: var(--ui-fg);
}

.due-date-btn.active {
  background: var(--ui-fg);
  color: var(--ui-bg);
  border-color: var(--ui-fg);
}

.due-date-controls input[type="date"] {
  padding: 6px 10px;
  min-height: 36px;
  cursor: default;
  background: var(--ui-bg);
  opacity: 0.8;
  font-size: 11px;
  text-align: center;
}

/* Notes position radio buttons */
.notes-position-controls {
  display: flex;
  gap: 16px;
}

.notes-position-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-label);  /* 10px */
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s;
}

.notes-position-option:hover {
  opacity: 0.8;
}

.notes-position-option input[type="radio"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

.items {
  padding: 16px;  /* Standardized */
  margin-bottom: 20px;
}

.items h3 {
  font-size: var(--font-size-h3);  /* 11px */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 0 0 16px 0;
  border-bottom: 0.5px solid var(--border);
  padding-bottom: 8px;
}

/* Items footer - Add button (left) + Checkbox (right) */
.items-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  gap: 16px;
}

.items-footer .add {
  flex-shrink: 0;
  margin-top: 0;  /* Override default margin */
}

.items-footer .save-items-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-label);  /* 10px */
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s;
  white-space: nowrap;
  margin-left: auto;  /* Force to far right */
  flex-shrink: 0;     /* Prevent shrinking */
}

.items-footer .save-items-checkbox:hover {
  opacity: 0.8;
}

.items-footer .save-items-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}

table#itemsTable {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

#itemsTable thead th {
  border: 0.5px solid var(--grid);
  padding: 8px 6px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  max-width: 0;
  overflow: hidden;
}

/* Header alignment - match PDF exactly (with drag handle column) */
#itemsTable thead th:nth-child(1) {
  text-align: center;  /* DRAG HANDLE - empty */
}

#itemsTable thead th:nth-child(2) {
  text-align: center;  /* TYPE - centered */
}

#itemsTable thead th:nth-child(3) {
  text-align: left;  /* DESCRIPTION - left */
}

#itemsTable thead th:nth-child(4) {
  text-align: center;  /* QTY/HRS - centered */
}

#itemsTable thead th:nth-child(5) {
  text-align: right;  /* RATE - right */
}

#itemsTable thead th:nth-child(6) {
  text-align: right;  /* AMOUNT - right */
}

#itemsTable thead th:nth-child(7) {
  text-align: center;  /* ACTION - empty */
}

#itemsTable tbody td {
  border: 0.5px solid var(--grid);
  padding: 0;
  max-width: 0;  /* Force column width constraints */
  overflow: hidden;  /* Clip any overflow content */
}

#itemsTable tbody td input {
  border: none;
  width: 100%;
  max-width: 100%;  /* Prevent overflow */
  padding: 6px 4px;  /* Tighter horizontal padding */
  font-size: 11px;
  background: transparent;
  color: inherit;
  box-sizing: border-box;  /* Include padding in width */
  overflow: hidden;
  text-overflow: ellipsis;  /* Show ... for long text */
  margin: 0;
}

.type-cell {
  padding: 0;
  max-width: 12%;
  overflow: hidden;
}

.item-type {
  width: 100%;
  max-width: 100%;
  padding: 6px 4px;
  border: none;
  background: transparent;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  box-sizing: border-box;
  text-overflow: ellipsis;
}

.item-type:focus {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
  z-index: 10;
}

/* Specific input styling for each column */
.item-desc {
  width: 100%;
  max-width: 100%;
  padding: 6px;
  box-sizing: border-box;
  text-overflow: ellipsis;
}

.item-qty {
  width: 100%;
  max-width: 100%;
  padding: 6px 4px;
  box-sizing: border-box;
  text-align: center;
}

.item-rate {
  width: 100%;
  max-width: 100%;
  padding: 6px 4px;
  box-sizing: border-box;
  text-align: right;
}

.item-amt {
  width: 100%;
  max-width: 100%;
  padding: 6px 4px;
  box-sizing: border-box;
  text-align: right;
  font-weight: 600;
  cursor: default;
}

.center input {
  text-align: center;
  box-sizing: border-box;
}

.right input {
  text-align: right;
  box-sizing: border-box;
}

.rm {
  width: 100%;
  height: 100%;
  min-height: 44px;  /* Fill entire row */
  background: #000;
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  transition: all 0.2s;
}

.rm:hover {
  background: #dc2626;
}

/* === DRAG AND DROP REORDERING === */

/* Drag handle column - clear visual indicator */
.drag-handle {
  padding: 0;
  text-align: center;
  cursor: grab;
  background: var(--panel-bg);
  user-select: none;
  vertical-align: middle;
  transition: background 0.2s;
  border-right: 1px solid var(--grid);
}

.drag-handle:hover {
  background: var(--border);
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-icon {
  font-size: 14px;
  color: var(--ui-fg);
  opacity: 0.4;
  display: inline-block;
  line-height: 44px;  /* Match row height */
  font-weight: 700;
  transition: opacity 0.2s;
}

.drag-handle:hover .drag-icon {
  opacity: 0.8;
}

/* Visual feedback when dragging */
#itemsTable tbody tr.dragging {
  opacity: 0.4;
}

/* Drop target highlight */
#itemsTable tbody tr.drag-over {
  border-top: 3px solid var(--accent);
}

button {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  text-transform: uppercase;
  padding: 8px 16px;
  background: #000;
  color: #fff;
  border: 0.5px solid var(--border);
  cursor: pointer;
  letter-spacing: 1px;
  font-size: 11px;
}

@media (max-width: 768px) {
  button {
    padding: 12px 20px;
    font-size: 12px;
    border-width: 1px;
  }
  .go {
    font-size: 16px !important;
    padding: 16px 24px !important;
  }
}

.add {
  min-height: 40px;
  padding: 10px 20px;
  font-size: var(--font-size-button);  /* 10px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--ui-fg);
  color: var(--ui-bg);
  border: 1px solid var(--ui-fg);
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 10px;
}

.add:hover {
  background: var(--border);
  color: var(--ui-fg);
}

.go {
  min-height: 40px;
  padding: 10px 24px;
  font-size: var(--font-size-button);  /* 10px */
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 100%;
  font-family: 'IBM Plex Mono', monospace;
}

.preview {
  display: none;
}

.preview.filled {
  --preview-bg: var(--accent-color);
  --preview-text: var(--lighter-text, #111111);
  --preview-accent: var(--preview-accent-color, #111111);
  --preview-fill: var(--accent-light);
  --preview-border: var(--preview-accent-color, #111111);
  color: var(--lighter-text, #111111); /* Use lighter text color in filled mode */
}

.preview.outline {
  --preview-bg: #ffffff;
  --preview-text: #111111;
  --preview-accent: var(--preview-accent-color, var(--accent-color));
  --preview-fill: #ffffff; /* Pure white, no fills for clean outline */
  --preview-border: var(--preview-accent-color, var(--accent-color));
}

.preview.ascii {
  --preview-bg: #000000;
  --preview-text: var(--preview-accent-color, var(--accent-color));
  --preview-accent: var(--preview-accent-color, var(--accent-color));
  --preview-fill: #000000; /* Black background for terminal look */
  --preview-border: var(--preview-accent-color, var(--accent-color));
  font-family: 'Courier New', 'Lucida Console', Monaco, monospace;
  font-weight: normal;
}

.out {
  background: var(--preview-bg, var(--panel-bg));
  border: 0.5px solid var(--preview-border, var(--border));
  padding: 40px;
  font-size: 9px;
  line-height: 1.3;
  color: var(--preview-text, inherit);
}

.invoice-head {
  min-height: 120px;
  border-bottom: 0.5px solid var(--preview-border, var(--border));
  margin-bottom: 20px;
  padding-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.invoice-head__meta {
  text-align: right;
  font-size: 8px;
  line-height: 1.2;
}

.invoice-head__title {
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 3px;
  font-size: 18px;
  color: var(--preview-accent, inherit);
}

.invoice-head__number {
  font-weight: 700;
  text-transform: uppercase;
  color: var(--preview-accent, inherit);
}

.invoice-head__subtitle {
  font-size: 9px;
  font-weight: 400;
  opacity: 0.8;
  margin-top: 4px;
  color: var(--preview-accent, inherit);
}

.invoice-head__meta > div {
  color: var(--preview-accent, inherit);
}

.invoice-meta {
  font-size: 8px;
}

.invoice-logo {
  max-height: 40px;
  max-width: 180px;
}

.invoice-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  margin-bottom: 15px;
}

.invoice-panel {
  border: 0.5px solid var(--preview-border, var(--border));
  padding: 8px;
}

.preview.outline .invoice-panel {
  background: transparent; /* No fills in outline mode */
}

.preview.filled .invoice-panel {
  background: var(--preview-fill, transparent); /* Show bright fills in filled mode */
}

.preview.outline .invoice-table th,
.preview.outline .invoice-table td {
  background: transparent; /* No fills in outline mode */
}

.preview.filled .invoice-table th {
  background: var(--preview-fill, transparent); /* Header gets bright fill */
  color: var(--box-header-color, #111111); /* Use black for box headers */
}

.preview.filled .invoice-table td {
  background: var(--table-light, transparent); /* Table rows get lighter fill */
  color: #111111; /* Force black text for readability */
}

.invoice-panel__title {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 7px;
  letter-spacing: 1px;
  border-bottom: 0.5px solid var(--preview-border, var(--border));
  padding-bottom: 3px;
  margin-bottom: 5px;
  color: var(--box-header-color, #111111); /* Use black for box headers */
}

.invoice-panel__pre {
  white-space: pre-line;
}

.invoice-notes-section {
  margin-bottom: 16px;
}

.invoice-notes-section .invoice-panel {
  border: 1px solid var(--preview-border, var(--border));
  padding: 12px;
  background: var(--accent-light, transparent);
}

.invoice-notes-section .invoice-panel__pre {
  white-space: pre-wrap;
  line-height: 1.5;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin: 15px 0;
  border: 0.5px solid var(--preview-border, var(--border));
  font-size: 8px;
  table-layout: fixed;
}

.invoice-table th,
.invoice-table td {
  border: 0.5px solid var(--preview-border, var(--grid));
  padding: 5px 8px;
}

/* === COLUMN WIDTHS - Without TYPE column === */
.invoice-table:not(.has-types) col:nth-child(1) { width: 50%; }  /* DESCRIPTION */
.invoice-table:not(.has-types) col:nth-child(2) { width: 15%; }  /* QTY/HRS */
.invoice-table:not(.has-types) col:nth-child(3) { width: 15%; }  /* RATE */
.invoice-table:not(.has-types) col:nth-child(4) { width: 20%; }  /* AMOUNT */

/* === COLUMN WIDTHS - With TYPE column === */
.invoice-table.has-types col:nth-child(1) { width: 13%; }  /* TYPE */
.invoice-table.has-types col:nth-child(2) { width: 42%; }  /* DESCRIPTION */
.invoice-table.has-types col:nth-child(3) { width: 10%; }  /* QTY/HRS */
.invoice-table.has-types col:nth-child(4) { width: 15%; }  /* RATE */
.invoice-table.has-types col:nth-child(5) { width: 20%; }  /* AMOUNT */

/* === COLUMN ALIGNMENT - Match PDF exactly === */

/* TYPE column (first when has-types) - CENTER */
.invoice-table.has-types th:nth-child(1),
.invoice-table.has-types td:nth-child(1) {
  text-align: center;
  padding: 5px 4px;
}

/* DESCRIPTION column - LEFT */
.invoice-table.has-types th:nth-child(2),
.invoice-table.has-types td:nth-child(2),
.invoice-table:not(.has-types) th:nth-child(1),
.invoice-table:not(.has-types) td:nth-child(1) {
  text-align: left;
  padding: 5px 8px;
}

/* QTY/HRS column - CENTER */
.invoice-table.has-types th:nth-child(3),
.invoice-table.has-types td:nth-child(3),
.invoice-table:not(.has-types) th:nth-child(2),
.invoice-table:not(.has-types) td:nth-child(2) {
  text-align: center;
  padding: 5px 6px;
}

/* RATE column - RIGHT (money) */
.invoice-table.has-types th:nth-child(4),
.invoice-table.has-types td:nth-child(4),
.invoice-table:not(.has-types) th:nth-child(3),
.invoice-table:not(.has-types) td:nth-child(3) {
  text-align: right;
  padding: 5px 8px;
}

/* AMOUNT column - RIGHT (money) + Emphasized */
.invoice-table.has-types th:nth-child(5),
.invoice-table.has-types td:nth-child(5),
.invoice-table:not(.has-types) th:nth-child(4),
.invoice-table:not(.has-types) td:nth-child(4) {
  text-align: right;
  padding: 5px 8px;
  font-weight: 600;
}

.invoice-table th {
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--box-header-color, #111111);
}

.invoice-cell--em {
  font-weight: 600;
}

.invoice-summary {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 15px;
  margin-top: 15px;
}

.invoice-summary__totals {
  margin-top: 5px;
  font-size: 8px;
}

.invoice-summary__line {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.invoice-summary__total {
  display: flex;
  justify-content: space-between;
  border-top: 0.5px solid var(--border);
  padding-top: 5px;
  margin-top: 5px;
  font-size: 10px;
  font-weight: 700;
}

.dl {
  text-align: center;
  margin-top: 30px;
}

.dl button {
  font-size: 14px;
  padding: 12px 40px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 768px) {
  .preset-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

.preset-btn {
  padding: 8px 12px;
  border: 0.5px solid var(--border);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.preset-btn.active {
  border-width: 2px;
  transform: translateY(-1px);
}

.template-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.template-actions button {
  flex: 1;
  min-width: 120px;
  font-size: 10px;
  padding: 6px 12px;
}

@media (max-width: 768px) {
  .template-actions {
    flex-direction: column;
  }
  .template-actions button {
    width: 100%;
  }
}

/* ====================== MOBILE RESPONSIVENESS ====================== */
/* Complete mobile-friendly design for all sections */

@media (max-width: 768px) {
  /* === TEMPLATE SECTION === */
  .template-quick-row {
    flex-direction: column;
    gap: 8px;
  }

  .template-chips {
    width: 100%;
  }

  .filter-chip {
    flex: 1;
    justify-content: center;
  }

  .load-btn {
    width: 100%;
  }

  .template-input-wrapper {
    width: 100%;
  }

  .template-dropdown {
    left: 0;
    right: 0;
  }

  /* === INVOICE NUMBER === */
  .invoice-number-group {
    flex-wrap: wrap;
  }

  .invoice-number-group input {
    min-width: 100px;
  }

  /* === DUE DATE BUTTONS === */
  .due-date-buttons {
    flex-direction: column;
    gap: 6px;
  }

  .due-date-btn {
    width: 100%;
  }

  /* === ITEMS FOOTER === */
  .items-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .items-footer .add {
    width: 100%;
  }

  .items-footer .save-items-checkbox {
    justify-content: center;
  }

  /* === PREVIEW ACTIONS === */
  .preview-actions {
    flex-direction: column;
  }

  .go,
  .dl-btn {
    width: 100%;
  }

  /* === SETTINGS GRIDS === */
  .settings-grid {
    grid-template-columns: 1fr !important;
  }

  /* === TABLE === */
  #itemsTable {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* === BUTTONS REMAIN SAME HEIGHT === */
  /* No height changes on mobile - 40px buttons remain 40px for easy tapping */
}