/* Loading Screen */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #282c34;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease-out;
}

.loading-content {
  text-align: center;
}

.christmas-tree {
  font-family: 'Courier New', 'Courier', monospace;
  font-size: 20px;
  font-weight: normal;
  line-height: 1;
  color: #2ecc71; /* Green color for the tree */
  margin-bottom: 20px;
  white-space: pre;
  letter-spacing: 0;
  word-spacing: 0;
  text-align: left;
  display: inline-block;
  margin-left: auto;
  margin-right: auto;
}

.loading-text {
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 2px;
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Base styles copied from original repository with minor additions */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* CSS Custom Properties for responsive breakpoints */
:root {
  --breakpoint-mobile: 768px;
  --breakpoint-tablet: 1024px;
  --touch-target-min: 44px;
}

/* Global overflow prevention for mobile devices */
html {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  max-width: 100vw;
  /* Text handling for long content */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.app-header {
  background-color: #282c34;
  color: white;
  padding: 20px;
  text-align: center;
}

.app-header h1 {
  font-size: clamp(1.2rem, 4vw, 1.5rem);
  word-break: break-word;
}

/* Responsive navigation */
.app-nav {
  background-color: #f5f5f5;
  padding: 10px;
  border-bottom: 2px solid #ddd;
  display: flex;
  gap: 10px;
  flex-wrap: wrap; /* Allow wrapping on mobile */
  overflow-x: auto; /* Fallback for very narrow screens */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Mobile navigation adjustments */
@media (max-width: 768px) {
  .app-nav {
    gap: 6px;
    padding: 8px;
  }
}

.settings-btn {
  margin-left: auto;
}

.nav-btn {
  padding: 10px 20px;
  background-color: white;
  border: 1px solid #ddd;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  transition: all 0.3s;
  min-height: var(--touch-target-min);
  white-space: nowrap;
}

/* Mobile: reduce button padding for better fit */
@media (max-width: 768px) {
  .nav-btn {
    padding: 8px 12px;
    font-size: 13px;
  }
}

.nav-btn:hover {
  background-color: #e9e9e9;
}

.nav-btn.active {
  background-color: #007bff;
  color: white;
  border-color: #007bff;
}

.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  background-color: #f8f9fa;
  max-width: 100vw;
}

/* Mobile: reduce content padding */
@media (max-width: 768px) {
  .app-content {
    padding: 12px;
  }
}

.tab-content {
  display: none;
}

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

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-header h2 {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  color: #333;
  word-break: break-word;
}

/* Mobile: stack section header vertically */
@media (max-width: 768px) {
  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s;
  min-height: var(--touch-target-min);
}

/* Mobile: ensure buttons are touch-friendly */
@media (max-width: 768px) {
  .btn {
    padding: 12px 16px;
    font-size: 14px;
  }
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: #007bff;
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: #0056b3;
}

.btn-success {
  background-color: #28a745;
  color: white;
}

.btn-success:hover:not(:disabled) {
  background-color: #218838;
}

.btn-danger {
  background-color: #dc3545;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background-color: #c82333;
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #5a6268;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* Responsive table container */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  background-color: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

table th,
table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;
  word-break: break-word;
  overflow-wrap: break-word;
}

table th {
  background-color: #f8f9fa;
  font-weight: 600;
  color: #495057;
}

table tr:hover {
  background-color: #f5f5f5;
}

/* Mobile: Convert tables to card-based list view */
@media (max-width: 768px) {
  /* Hide table headers on mobile */
  table thead {
    position: absolute;
    clip: rect(0 0 0 0);
    height: 1px;
    width: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    border: 0;
  }

  /* Make each table row a card */
  table tbody tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  }

  /* Remove default row hover on mobile cards */
  table tbody tr:hover {
    background-color: white;
  }

  /* Make each cell a block element with label */
  table tbody td {
    display: block;
    text-align: right;
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    position: relative;
    padding-left: 50%;
    min-height: 44px; /* Touch-friendly height */
  }

  /* Remove border from last cell in card */
  table tbody td:last-child {
    border-bottom: none;
  }

  /* Add labels before each cell using data-label attribute or nth-child */
  table tbody td::before {
    content: attr(data-label);
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 600;
    color: #495057;
    text-align: left;
    width: 45%;
    white-space: normal;
    word-wrap: break-word;
  }

  /* Specific labels for common tables */

  /* Employees table */
  #employees-table tbody td:nth-child(1)::before { content: "Name"; }
  #employees-table tbody td:nth-child(2)::before { content: "Email"; }
  #employees-table tbody td:nth-child(3)::before { content: "Phone"; }
  #employees-table tbody td:nth-child(4)::before { content: "Position"; }
  #employees-table tbody td:nth-child(5)::before { content: "Department"; }
  #employees-table tbody td:nth-child(6)::before { content: "Hire Date"; }
  #employees-table tbody td:nth-child(7)::before { content: "Actions"; }

  /* Registry table */
  #registry-table tbody td:nth-child(1)::before { content: "Doc Number"; }
  #registry-table tbody td:nth-child(2)::before { content: "Type"; }
  #registry-table tbody td:nth-child(3)::before { content: "Employee"; }
  #registry-table tbody td:nth-child(4)::before { content: "Template"; }
  #registry-table tbody td:nth-child(5)::before { content: "Created Date"; }
  #registry-table tbody td:nth-child(6)::before { content: "Status"; }
  #registry-table tbody td:nth-child(7)::before { content: "Actions"; }

  /* Dictionary types table */
  #dictionary-types-table tbody td:nth-child(1)::before { content: "Icon"; }
  #dictionary-types-table tbody td:nth-child(2)::before { content: "Name"; }
  #dictionary-types-table tbody td:nth-child(3)::before { content: "Description"; }
  #dictionary-types-table tbody td:nth-child(4)::before { content: "Entries"; }
  #dictionary-types-table tbody td:nth-child(5)::before { content: "Actions"; }

  /* Dictionary entries table - generic labels since structure varies */
  #dictionary-entries-table tbody td:nth-child(1)::before { content: "Name"; }
  #dictionary-entries-table tbody td:nth-child(2)::before { content: "Actions"; }

  /* Action buttons should be full width on mobile */
  table tbody td .action-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }

  table tbody td .action-buttons .btn-sm {
    width: 100%;
    text-align: center;
  }
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: #333;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
  font-family: inherit;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
  overflow-y: auto;
}

/* Mobile: adjust modal overlay padding */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 10px;
    align-items: flex-start;
  }
}

.modal {
  background-color: white;
  padding: 30px;
  border-radius: 8px;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-sizing: border-box;
}

/* Mobile: optimize modal sizing */
@media (max-width: 768px) {
  .modal {
    width: 95%;
    max-width: 100vw;
    max-height: 95vh;
    padding: 20px;
    margin: auto;
  }
}

.modal h3 {
  margin-bottom: 20px;
  color: #333;
  word-break: break-word;
  font-size: clamp(1.1rem, 4vw, 1.25rem);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* Mobile: stack modal actions vertically */
@media (max-width: 768px) {
  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }
}

.action-buttons {
  display: flex;
  gap: 5px;
}

.document-preview {
  background-color: white;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 4px;
  white-space: pre-wrap;
  font-family: 'Times New Roman', serif;
  line-height: 1.6;
  min-height: 300px;
  margin-top: 10px;
  word-break: break-word;
  overflow-wrap: break-word;
  overflow-x: auto;
  max-width: 100%;
}

/* Mobile: adjust document preview */
@media (max-width: 768px) {
  .document-preview {
    padding: 15px;
    font-size: 14px;
  }
}

.filter-section {
  background-color: white;
  padding: 15px;
  border-radius: 4px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  max-width: 100%;
  overflow-x: hidden;
}

/* Mobile: adjust filter section */
@media (max-width: 768px) {
  .filter-section {
    padding: 12px;
  }
}

.filter-section select {
  width: auto;
  min-width: 200px;
  max-width: 100%;
}

/* Mobile: make selects full width */
@media (max-width: 768px) {
  .filter-section select {
    width: 100%;
    min-width: 100%;
  }
}

.button-group {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  flex-wrap: wrap;
}

/* Mobile: stack button groups */
@media (max-width: 768px) {
  .button-group {
    flex-direction: column;
  }

  .button-group .btn {
    width: 100%;
  }
}

.info-box {
  background-color: #d4edda;
  padding: 15px;
  border-radius: 4px;
  margin-bottom: 20px;
  color: #155724;
  border: 1px solid #c3e6cb;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Mobile: reduce info box padding */
@media (max-width: 768px) {
  .info-box {
    padding: 12px;
    font-size: 14px;
  }
}

.success-message {
  background-color: #d4edda;
  color: #155724;
  padding: 10px;
  border-radius: 4px;
  margin-bottom: 10px;
}

/* Additional styling for dictionaries */
.dictionary-section {
  margin-bottom: 30px;
  background-color: #ffffff;
  padding: 15px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Mobile: adjust dictionary section */
@media (max-width: 768px) {
  .dictionary-section {
    padding: 12px;
  }
}

.dictionary-section h3 {
  margin-bottom: 10px;
  font-size: clamp(1rem, 4vw, 1.125rem);
}

/* Template Sections */
.template-section {
  margin-bottom: 30px;
  background-color: #ffffff;
  padding: 15px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Mobile: adjust template section */
@media (max-width: 768px) {
  .template-section {
    padding: 12px;
  }
}

.template-section h3 {
  margin-bottom: 15px;
  color: #333;
  font-size: clamp(1rem, 4vw, 1.125rem);
}

/* Rich Editor Styles */
.modal-large {
  max-width: 900px;
  width: 90%;
}

/* Mobile: make large modals full-width */
@media (max-width: 768px) {
  .modal-large {
    width: 95%;
    max-width: 100vw;
    padding: 15px;
  }
}

.rich-editor {
  min-height: 400px;
  background-color: white;
}

/* Quill editor specific styles */
.ql-toolbar {
  background-color: #f8f9fa;
  border: 1px solid #ddd !important;
  border-radius: 4px 4px 0 0;
}

.ql-container {
  border: 1px solid #ddd !important;
  border-radius: 0 0 4px 4px;
  font-family: 'Times New Roman', serif;
  line-height: 1.6;
  min-height: 400px;
}

.ql-editor {
  min-height: 400px;
}

.import-preview {
  max-height: 400px;
  overflow-y: auto;
  padding: 15px;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-top: 15px;
  background-color: #f8f9fa;
}
/* Settings styles */
.settings-section {
  background-color: #ffffff;
  padding: 20px;
  margin-bottom: 20px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.settings-section h3,
.settings-summary {
  margin-bottom: 15px;
  color: #282c34;
  border-bottom: 2px solid #007bff;
  padding-bottom: 10px;
  font-size: 1.17em;
  font-weight: bold;
}

.settings-summary {
  cursor: pointer;
  list-style: none;
  outline: none;
  display: flex;
  align-items: center;
  margin-bottom: 0;
}

.settings-summary::-webkit-details-marker {
  display: none;
}

.settings-summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 10px;
  font-size: 12px;
  transition: transform 0.2s;
  color: #007bff;
}

details[open] .settings-summary::before {
  transform: rotate(90deg);
}

details[open] .settings-summary {
  margin-bottom: 0;
}

.settings-section h4 {
  margin-top: 15px;
  margin-bottom: 10px;
  color: #495057;
}

.sync-provider {
  margin-bottom: 25px;
  padding: 15px;
  border: 1px solid #e9ecef;
  border-radius: 4px;
}

.provider-settings {
  margin-top: 15px;
  padding-left: 20px;
}

.info-text {
  color: #6c757d;
  font-size: 14px;
  margin-bottom: 15px;
}

.settings-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: #495057;
}

.form-group input[type="checkbox"] {
  margin-right: 8px;
  width: auto;
}

.form-group small {
  display: block;
  margin-top: 5px;
  color: #6c757d;
  font-size: 12px;
}
/* OAuth Connection Status Styles */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  padding: 10px;
  background-color: #f8f9fa;
  border-radius: 4px;
}

.status-indicator {
  font-size: 20px;
  line-height: 1;
}

.status-indicator.connected {
  color: #28a745;
}

.status-indicator.disconnected {
  color: #dc3545;
}

#onedrive-status-text,
#googledrive-status-text {
  font-weight: 500;
  font-size: 14px;
}

.button-group {
  display: flex;
  gap: 10px;
  margin: 10px 0;
}

/* Rich Text Editor Styles */
.modal-large {
  max-width: 900px;
  width: 90%;
}

#rich-template-editor {
  border: 1px solid #ccc;
  border-radius: 4px;
  min-height: 300px;
}

.ql-container {
  font-size: 14px;
}

.ql-editor {
  min-height: 250px;
}

.ql-toolbar {
  background-color: #f8f9fa;
  border-radius: 4px 4px 0 0;
}

/* Templates list (div-based rows, not a <table>) */
/* NOTE: replaced by the table-like styles below (.templates-list / .templates-list__head / .template-card). */

/* Template modal: keep Save/Cancel visible */
/* NOTE: replaced by the "Template modal footer" block below to avoid duplicate sticky rules. */

/* Templates list: make it look like the other tables */
.templates-list {
  background-color: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  border-radius: 0; /* tables are square in this app */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.templates-list__head {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 180px) 1fr auto;
}

/* Mobile: stack template grid vertically */
@media (max-width: 768px) {
  .templates-list__head {
    display: none; /* Hide header on mobile, show as cards */
  }
}

.templates-list__th {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;
  background-color: #f8f9fa;
  font-weight: 600;
  color: #495057;
}

.templates-grid {
  display: flex;
  flex-direction: column;
}

/* Target row height: ~3–4 lines */
:root {
  --templates-row-min-height: 84px;
}

.template-card {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 180px) 1fr auto;
  gap: 0;

  /* row height */
  min-height: var(--templates-row-min-height);
  align-items: stretch;

  /* table row behavior */
  background: transparent;
}

/* Mobile: stack template cards vertically */
@media (max-width: 768px) {
  .template-card {
    grid-template-columns: 1fr;
    grid-template-areas:
      "name"
      "type"
      "preview"
      "actions";
    border-bottom: 2px solid #ddd;
    padding: 12px;
    min-height: auto;
  }

  .template-card__name {
    grid-area: name;
  }

  .template-card__type {
    grid-area: type;
  }

  .template-card__preview {
    grid-area: preview;
  }

  .template-card__actions {
    grid-area: actions;
  }
}

/* Each direct child is a "cell" */
.template-card > * {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #ddd;

  /* force equal cell height */
  min-height: var(--templates-row-min-height);
  display: flex;
  flex-direction: column;
}

/* Mobile: adjust template card cells */
@media (max-width: 768px) {
  .template-card > * {
    border-bottom: none;
    min-height: auto;
    padding: 8px 0;
  }
}

/* Vertically center text cells by default */
.template-card__header,
.template-card__type,
.template-card__actions {
  justify-content: center;
}

/* Name can wrap up to ~3–4 lines, then clip */
.template-card__name {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

/* Preview cell should not add extra offset that pushes the thumbnail out of view */
.template-card__preview {
  padding: 12px; /* keep same cell padding */
  overflow: hidden;
}

.template-preview-thumb {
  display: inline-flex;
  align-items: flex-start;
  justify-content: flex-start;
  overflow: hidden;
  line-height: 0;
  padding: 0;
  margin: 0;
  /* prevent any unexpected baseline alignment offsets */
  vertical-align: top;
}

/* Ensure the scaled page starts at top-left inside the clipped thumb */
.template-preview-page {
  transform-origin: top left;
  margin: 0;
  padding: 0;
  position: relative;
  top: 0;
  left: 0;
}

.template-preview-page * {
  margin: 0;
}

/* Template modal footer: prevent artifacts under sticky actions */
#template-modal .modal {
  overflow: hidden; /* clip sticky footer edge artifacts */
}

/* ===== Template editor split modal ===== */
#template-modal .template-modal {
  width: 96vw;
  max-width: 1400px;
  height: 92vh;
  max-height: 92vh;

  padding: 0;                 /* remove default modal padding */
  overflow: hidden;           /* we manage scrolling inside */
  display: flex;
  flex-direction: column;
}

/* Mobile: optimize template modal for small screens */
@media (max-width: 768px) {
  #template-modal .template-modal {
    width: 98vw;
    max-width: 100vw;
    height: 95vh;
    max-height: 95vh;
    border-radius: 4px;
  }
}

#template-modal .template-modal__header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  background: #fff;
  flex: 0 0 auto;
}

/* Mobile: reduce template modal header padding */
@media (max-width: 768px) {
  #template-modal .template-modal__header {
    padding: 12px 15px;
  }
}

#template-modal .template-modal__header h3 {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.25rem);
  word-break: break-word;
}

#template-modal .template-modal__form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#template-modal .template-modal__body {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 0;
  flex: 1;
  min-height: 0;
}

/* Mobile: stack template modal body vertically */
@media (max-width: 768px) {
  #template-modal .template-modal__body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}

#template-modal .template-modal__left {
  padding: 20px;
  border-right: 1px solid #eee;
  overflow: auto;
  min-height: 0;
}

/* Mobile: adjust template modal left panel */
@media (max-width: 768px) {
  #template-modal .template-modal__left {
    padding: 15px;
    border-right: none;
    border-bottom: 1px solid #eee;
    max-height: 40vh;
  }
}

#template-modal .template-modal__right {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#template-modal .template-modal__editor-toolbar {
  padding: 12px 12px;
  border-bottom: 1px solid #eee;
  background: #fff;
  flex: 0 0 auto;
}

/* Template editor toolbar row layout */
#template-modal .template-modal__editor-toolbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Mobile: adjust toolbar layout */
@media (max-width: 768px) {
  #template-modal .template-modal__editor-toolbar-row {
    gap: 8px;
  }
}

.template-var-insert {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding-left: 12px;
  border-left: 1px solid #eee;
}

/* Mobile: adjust variable insert section */
@media (max-width: 768px) {
  .template-var-insert {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    width: 100%;
    flex-wrap: wrap;
  }
}

.template-var-insert__label {
  font-size: 12px;
  color: #6c757d;
  margin: 0;
  white-space: nowrap;
}

.template-var-insert__select {
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  background: #fff;
  max-width: 220px;
}

/* Mobile: make selects full width */
@media (max-width: 768px) {
  .template-var-insert__select {
    max-width: 100%;
    flex: 1;
    min-width: 120px;
  }
}

#template-modal .template-modal__editor-scroll {
  padding: 0 12px 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* Explicit mobile padding override */
@media (max-width: 768px) {
  #template-modal .template-modal__editor-scroll {
    padding: 0 10px 10px;
  }
}

#template-modal .template-modal__editor-scroll .ql-container {
  min-height: calc(100% - 52px);
}

#template-modal .template-modal__editor-scroll .ql-editor {
  min-height: 100%;
}

/* When toolbars become sticky, keep them flush and visually separated */
#template-modal .template-modal__editor-scroll .html5-editor-toolbar,
#template-modal .template-modal__editor-scroll .ql-toolbar {
  margin-top: 0;
}

/* Give the editor body some breathing room now that scroll container has no top padding */
#template-modal .template-modal__editor-scroll .html5-editor-content,
#template-modal .template-modal__editor-scroll .ql-editor {
  padding-top: 12px;
}

#template-modal #rich-template-editor.template-modal__editor {
  height: 100%;
  min-height: 100%;
}

/* HTML5 editor toolbar: make sticky like Quill */
#template-modal .template-modal__editor-scroll .html5-editor-toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
}

/* Ensure sticky toolbars have opaque background */
#template-modal .template-modal__editor-scroll .html5-editor-toolbar,
#template-modal .template-modal__editor-scroll .ql-toolbar {
  background: #f8f9fa;
}

/* Quill: make its toolbar sticky inside the editor scroll area */
#template-modal .template-modal__editor-scroll .ql-toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
}

#template-modal .template-modal__editor-scroll .ql-container {
  min-height: calc(100% - 42px);
}

/* Footer always visible */
#template-modal .template-modal__footer {
  margin-top: 0;
  padding: 12px 20px;
  border-top: 1px solid #eee;
  background: #fff;
  flex: 0 0 auto;
}

/* Mobile: adjust footer padding */
@media (max-width: 768px) {
  #template-modal .template-modal__footer {
    padding: 12px 15px;
  }
}

/* ===== Additional Mobile Responsive Utilities ===== */

/* Prevent common elements from causing overflow */
img, video, iframe, canvas, svg {
  max-width: 100%;
  height: auto;
}

/* Ensure form inputs don't overflow */
input, textarea, select, button {
  max-width: 100%;
}

/* Allow specific elements to use full width properly */
html, body, .app, .app-content, .tab-content {
  max-width: 100vw;
}

/* Ensure form inputs don't overflow */
.form-group input,
.form-group textarea,
.form-group select {
  max-width: 100%;
  box-sizing: border-box;
}

/* Mobile: improve touch targets */
@media (max-width: 768px) {
  button, .btn, .nav-btn {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
  }
}

/* Tablet: intermediate breakpoint adjustments */
@media (min-width: 768px) and (max-width: 1024px) {
  .app-content {
    padding: 16px;
  }

  .section-header {
    flex-wrap: wrap;
  }
}

/* Desktop: optimize for larger screens */
@media (min-width: 1024px) {
  .modal {
    max-width: 700px;
  }

  .modal-large {
    max-width: 1000px;
  }
}

/* Accessibility: Ensure focus indicators are visible */
button:focus,
.btn:focus,
.nav-btn:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* Print styles: hide navigation and optimize layout */
@media print {
  .app-nav,
  .settings-btn,
  .modal-actions,
  .action-buttons,
  button {
    display: none !important;
  }

  .app-content {
    padding: 0;
  }

  .document-preview {
    border: none;
    box-shadow: none;
  }
}
