@import url('https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&display=swap');

/* Note: Tailwind utilities are loaded via CDN in the HTML templates */
/* If you want to compile Tailwind locally, run: npm run build-css-prod */

/* ===== BASE STYLES ===== */
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-text-size-adjust: 100%;
  font-family: 'Amiri', serif;
}

body, html, * {
  font-family: 'Amiri', serif;
}

/* Prevent horizontal scroll */
body, html {
  overflow-x: hidden;
  max-width: 100%;
}

/* ===== MATERIAL ICONS - SINGLE SOURCE OF TRUTH ===== */
.material-icons {
  font-family: 'Material Icons' !important;
  font-weight: normal;
  font-style: normal;
  font-size: 24px; /* Default size */
  line-height: 1 !important;
  letter-spacing: normal;
  text-transform: none;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: middle;
}

/* Size variants for material icons - ensure width/height match font-size */
.material-icons.text-xs { font-size: 12px !important; width: 12px !important; height: 12px !important; }
.material-icons.text-sm { font-size: 14px !important; width: 14px !important; height: 14px !important; }
.material-icons.text-base { font-size: 16px !important; width: 16px !important; height: 16px !important; }
.material-icons.text-lg { font-size: 20px !important; width: 20px !important; height: 20px !important; }
.material-icons.text-xl { font-size: 24px !important; width: 24px !important; height: 24px !important; }
.material-icons.text-2xl { font-size: 28px !important; width: 28px !important; height: 28px !important; }
.material-icons.text-3xl { font-size: 32px !important; width: 32px !important; height: 32px !important; }

/* Icon button styling - ensures proper centering in buttons/links */
button.inline-flex .material-icons,
a.inline-flex .material-icons,
.inline-flex.items-center.justify-center .material-icons {
  margin: 0 !important;
  padding: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: relative;
}

/* Icon-only buttons - ensure icon fills container properly */
.w-10.h-10.inline-flex .material-icons,
.w-12.h-12.inline-flex .material-icons {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Ensure proper icon sizing in common button sizes */
.w-10.h-10 .material-icons { font-size: 20px !important; width: 20px !important; height: 20px !important; }
.w-12.h-12 .material-icons { font-size: 24px !important; width: 24px !important; height: 24px !important; }

/* ===== MOBILE STYLES ===== */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
  
  input[type="number"] {
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: textfield;
  }
  
  input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
  
  input[type="number"],
  input[type="tel"],
  input[type="text"],
  input[type="email"],
  input[type="url"],
  select,
  textarea {
    min-height: 44px !important;
  }
  
  h1 {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
  }
}

/* ===== JQUERY UI AUTOCOMPLETE ===== */
.ui-autocomplete {
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.ui-menu-item {
  padding: 8px 12px;
  border-bottom: 1px solid #e5e7eb;
  cursor: pointer;
}

.ui-menu-item:last-child {
  border-bottom: none;
}

.ui-state-active,
.ui-widget-content .ui-state-active {
  border: none;
  background: #e5e7eb;
  color: black;
  margin: 0;
}

.ui-menu .ui-menu-item-wrapper {
  padding: 0;
}

/* ===== DRAG AND DROP ===== */
.draggable-row.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.drag-over {
  border-top: 3px solid #3b82f6;
}

.move-up-btn, .move-down-btn {
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
}

.move-up-btn:disabled, .move-down-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.section-card {
  transition: all 0.2s ease;
}

.section-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.section-card.drag-over {
  border-color: #3b82f6;
  background-color: #eff6ff;
}

.drag-handle {
  transition: color 0.2s ease;
}

.drag-handle:hover {
  color: #6b7280;
}

/* ===== COLLAPSIBLE SECTIONS ===== */
.section-header {
  transition: background-color 0.2s ease;
  cursor: pointer;
}

.section-header:hover {
  background-color: #f3f4f6;
}

.section-icon {
  transition: transform 0.2s ease;
}

.section-content {
  transition: all 0.3s ease;
}

@media (max-width: 768px) {
  .section-header {
    padding: 16px 20px !important;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }
  
  .section-header:active {
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    transform: translateY(1px);
  }
  
  .section-header.has-options {
    border-color: #f59e0b;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  }
  
  .section-header.has-options:active {
    background: linear-gradient(135deg, #fde68a 0%, #fcd34d 100%);
  }
  
  .section-icon-mobile {
    width: 24px;
    height: 24px;
    color: #6b7280;
    transition: transform 0.2s ease;
  }
  
  .section-header.expanded .section-icon-mobile {
    transform: rotate(180deg);
  }
  
  .section-title-mobile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }
  
  .section-name-mobile {
    font-size: 18px;
    font-weight: 700;
    color: #1f2937;
    line-height: 1.2;
  }
  
  .section-meta-mobile {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #6b7280;
  }
  
  .mobile-tap-hint {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.1);
    color: #6b7280;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
  }
  
  .package-option-mobile {
    padding: 16px !important;
    border: 2px solid #e5e7eb !important;
    border-radius: 8px !important;
    margin-bottom: 12px !important;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  }
  
  .package-option-mobile:active {
    border-color: #3b82f6 !important;
    background: #eff6ff;
    transform: translateY(1px);
  }
  
  .package-option-mobile.selected {
    border-color: #10b981 !important;
    background: #ecfdf5;
  }
}

/* ===== ESTIMATE UPGRADE INDICATOR ===== */
.upgrade-indicator {
  background-color: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 2px 6px;
  margin: 2px 0;
  display: inline-block;
}

.upgrade-indicator .font-medium {
  color: #7c3aed;
}

.upgrade-indicator .text-gray-500 {
  color: #6b7280;
  font-size: 0.75rem;
}

/* ===== TABLE STYLES ===== */
.table-fixed {
  table-layout: fixed;
}

.table-fixed th,
.table-fixed td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.table-fixed th:first-child,
.table-fixed td:first-child {
  word-wrap: break-word;
  white-space: normal;
}

.table-fixed td:nth-child(4),
.table-fixed td:nth-child(5) {
  text-align: center;
}

.table-fixed th {
  white-space: nowrap;
  overflow: visible;
}

.table-fixed th:nth-child(5) {
  min-width: 80px;
}

.table-fixed .space-x-1 > * + * {
  margin-left: 0.25rem;
}

@media (min-width: 768px) and (max-width: 1023px) {
  .tablet-table {
    font-size: 0.875rem;
  }
  .tablet-table td {
    white-space: nowrap;
  }
  .tablet-table .truncate {
    max-width: 120px;
  }
}

/* ===== ICON BOX ===== */
.icon-22,
svg.icon-22 {
  display: inline-flex;
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}

/* ===== MONETARY AMOUNTS ===== */
.amount-align {
  display: flex !important;
  justify-content: center !important;
  width: 100% !important;
  font-variant-numeric: tabular-nums !important;
  font-feature-settings: 'tnum' 1, 'lnum' 1 !important;
}

#financial-summary-cards p[data-currency],
.hidden.sm\\:grid p[data-currency] {
  display: flex !important;
  justify-content: center !important;
  width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* ===== COMPANY LOGO ===== */
#company-avatar-btn {
  flex-shrink: 0;
  position: relative;
}

#company-avatar-btn img {
  object-fit: contain;
  width: 100%;
  height: 100%;
}

@media (max-width: 768px) {
  #company-avatar-btn {
    min-width: 40px !important;
    min-height: 40px !important;
    padding: 4px !important;
  }
  
  #company-avatar-btn img {
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
  }
  
  header {
    overflow: visible !important;
  }
  
  header .flex {
    min-width: 0 !important;
  }
}

/* ===== TOUCH MANIPULATION ===== */
.touch-manipulation {
  touch-action: manipulation;
}

/* ===== ACTION BUTTONS CENTERING ===== */
td.text-center {
  text-align: center !important;
}

.flex.items-center.justify-center {
  justify-content: center !important;
  align-items: center !important;
}

td.text-center .flex.flex-col {
  align-items: center !important;
  justify-content: center !important;
}

td.text-center button {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 auto !important;
}

/* ===== DOCUMENT VIEW STYLES (view-estimate, view-invoice) ===== */
body.no-color {
  background-color: #c8b5a0 !important;
}

.main-container {
  background: white;
  max-width: 800px;
  margin: 0 auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border-radius: 0;
  display: flex;
  min-height: 1000px;
  position: relative;
}

.sidebar {
  width: 180px;
  background: linear-gradient(to bottom, #6b7280, #4b5563);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  padding: 20px 10px;
}

.sidebar .logo-container {
  margin-bottom: 30px;
  text-align: center;
}

.sidebar .logo-container img {
  max-width: 120px;
  max-height: 80px;
  object-fit: contain;
  background: white;
  padding: 8px;
  border-radius: 8px;
}

.sidebar .vertical-text {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 200px;
  padding-left: 15px;
}

.sidebar .vertical-text span {
  font-size: 5.5rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.15);
  transform: rotate(-90deg);
  white-space: nowrap;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  transform-origin: center center;
}

.content {
  flex: 1;
  padding: 40px 40px 40px 220px;
}

.header-section {
  border-bottom: 4px solid #1f2937;
  margin-bottom: 32px;
  padding-bottom: 16px;
  position: relative;
}

.header-section::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 4px;
  background: repeating-linear-gradient(90deg, transparent, transparent 10px, #1f2937 10px, #1f2937 20px);
}

.company-name {
  font-size: 2rem;
  font-weight: 700;
  color: #1f2937;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.estimate-title,
.invoice-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #374151;
  margin-bottom: 16px;
}

.info-grid {
  display: flex;
  justify-content: space-between;
  margin-bottom: 32px;
}

.bill-to, .estimate-info {
  font-size: 1rem;
  color: #4b5563;
}

.bill-to strong, .estimate-info strong {
  display: block;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 8px;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 32px;
}

.items-table th {
  text-align: left;
  font-weight: 700;
  color: #1f2937;
  padding: 12px 8px;
  border-bottom: 2px solid #e5e7eb;
  vertical-align: top;
}

.items-table td {
  padding: 12px 8px;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
  vertical-align: top;
  line-height: 1.4;
}

.items-table .quantity-cell,
.items-table .price-cell,
.items-table .total-cell {
  text-align: right;
}

.totals-section {
  max-width: 300px;
  margin-left: auto;
  border-top: 2px solid #e5e7eb;
  padding-top: 16px;
}

.total-row {
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  padding: 8px 0;
  font-size: 1rem;
  color: #4b5563;
  width: 100%;
}

.total-row > span:first-child {
  flex: 0 0 auto;
  margin-right: auto;
}

.total-row > strong {
  flex: 0 0 auto;
  color: #1f2937;
  text-align: right !important;
  white-space: nowrap;
  margin-left: auto;
  display: block;
}

.total-row.final {
  border-top: 2px solid #e5e7eb;
  margin-top: 8px;
  padding-top: 16px;
  font-size: 1.25rem;
  font-weight: 700;
}

.footer-notes {
  margin-top: 48px;
  border-top: 1px solid #e5e7eb;
  padding-top: 24px;
  font-size: 0.9rem;
  color: #6b7280;
}

.action-section {
  text-align: center;
  padding: 32px 0;
  border-top: 1px solid #e5e7eb;
}

.action-button {
  background: #1f2937;
  color: white;
  padding: 12px 24px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.action-button:hover {
  background: #374151;
}

.document-type {
  font-size: 1.8rem;
  font-weight: 400;
  color: #6b7280;
  margin-bottom: 16px;
}

.document-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

.info-section h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1f2937;
}

.package-card {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.package-card.selected {
  border-color: #1f2937;
  background: #f9fafb;
}

.paid-stamp {
  position: absolute;
  top: 50%;
  right: 20px;
  transform: translateY(-50%) rotate(15deg);
  background: #059669;
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border: 3px solid #059669;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* Document mobile styles */
@media (max-width: 768px) {
  .main-container {
    flex-direction: column;
  }
  
  .sidebar {
    position: relative;
    width: 100%;
    height: 120px;
    flex-direction: row;
    justify-content: space-between;
    padding: 20px;
  }
  
  .sidebar .logo-container {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  .sidebar .logo-container img {
    max-width: 60px;
    max-height: 40px;
  }
  
  .sidebar .vertical-text {
    display: none;
  }
  
  .content {
    padding: 20px;
  }
  
  .info-grid {
    flex-direction: column;
    gap: 16px;
  }
  
  .totals-section {
    width: 100%;
    max-width: 100%;
  }
  
  .document-info {
    grid-template-columns: 1fr;
  }
}

/* Document print styles */
@media print {
  @page {
    size: A4;
    margin: 0in 0.35in 0.25in 0.35in;
  }
  
  body {
    background: white !important;
    padding: 0;
    margin: 0;
  }
  
  .main-container {
    box-shadow: none;
    margin: 0;
    border-radius: 0;
    width: 100%;
    display: block;
    position: relative;
  }
  
  .sidebar {
    display: none !important;
  }
  
  .content {
    padding: 0 !important;
    margin: 0 !important;
  }
  
  .header-section {
    text-align: center !important;
    margin-bottom: 20px !important;
    border-bottom: none !important;
    padding-bottom: 10px !important;
    margin-top: 0 !important;
    padding-top: 0 !important;
  }
  
  .header-section::after {
    display: none !important;
  }
  
  .print-logo {
    display: block !important;
  }
  
  .company-name {
    font-size: 1.8rem !important;
    margin-bottom: 5px !important;
  }
  
  .estimate-title,
  .invoice-title {
    font-size: 1.3rem !important;
    margin-bottom: 8px !important;
  }
  
  .no-print {
    display: none !important;
  }
  
  .upgrade-option.selected {
    background-color: #e0e7ff;
    border-color: #6366f1;
  }
  
  .upgrade-checkbox:checked + .flex-1 {
    color: #4f46e5;
  }
}

/* ===== CONTACT INFO ===== */
@media (min-width: 640px) {
  .contact-info {
    flex-direction: row !important;
    justify-content: center !important;
    gap: 30px !important;
  }
}

/* ===== MODAL STYLES ===== */
@media (max-width: 768px) {
  #editStatus,
  #editEstimateModal select {
    min-height: 44px !important;
    font-size: 16px !important;
    padding: 12px !important;
    border-radius: 8px !important;
  }
  
  #editEstimateModal .relative {
    margin: 1rem !important;
    max-width: calc(100vw - 2rem) !important;
  }
  
  #editEstimateModal .mb-4 {
    margin-bottom: 1rem !important;
  }
  
  #editEstimateModal .mt-6 {
    margin-top: 1.5rem !important;
  }
  
  select[onchange*="changeEstimateStatusInline"] {
    min-height: 44px !important;
    font-size: 16px !important;
    padding: 8px 12px !important;
    border-radius: 8px !important;
    background-color: white !important;
    border: 1px solid #d1d5db !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
  }
  
  .relative.inline-block .absolute svg {
    width: 20px !important;
    height: 20px !important;
    right: 8px !important;
  }
  
  .space-y-1 > div {
    margin-bottom: 8px !important;
  }
}
