/**
 * components.css — D3 CORE Global Component Styles
 * Shared styles for: AppConfirm, AppTooltip, AppEmailHint,
 * page-header, table utilities, filter panels, modal scroll fixes, print.
 * Loaded once globally via app.html.
 */

/* ─────────────────────────────────────────────────────────────────────────────
   Global utility — loaded once here so all pages (SPA route + standalone) have
   the canonical .hidden rule.  Module CSS files may duplicate it; that is fine.
   ───────────────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════
   APP CONFIRM DIALOG
   Unified animated confirmation modal (replaces window.confirm)
   ═══════════════════════════════════════════════════════ */
.app-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.18s ease;
  backdrop-filter: blur(2px);
}
.app-confirm-overlay.visible { opacity: 1; }

.app-confirm-dialog {
  background: var(--sidebar-color, #fff);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.28);
  padding: 2rem 1.75rem 1.5rem;
  width: min(100%, 380px);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  transform: scale(0.94) translateY(-10px);
  transition: transform 0.18s ease, opacity 0.18s ease;
  opacity: 0;
}
.app-confirm-overlay.visible .app-confirm-dialog {
  transform: scale(1) translateY(0);
  opacity: 1;
}

/* Icon circle */
.app-confirm-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  margin-bottom: 0.35rem;
  flex-shrink: 0;
}
/* Icon colour variants */
.app-confirm-icon-danger,
.app-confirm-icon-delete  { background: rgba(204,76,76,0.12);   color: #cc4c4c; }
.app-confirm-icon-warning,
.app-confirm-icon-cancel  { background: rgba(245,158,11,0.14);  color: #b45309; }
.app-confirm-icon-info,
.app-confirm-icon-receive { background: rgba(52,168,83,0.14);   color: #2d8c4e; }
body.dark .app-confirm-icon-danger,
body.dark .app-confirm-icon-delete  { background: rgba(204,76,76,0.10);  color: #ef9a9a; }
body.dark .app-confirm-icon-warning,
body.dark .app-confirm-icon-cancel  { background: rgba(245,158,11,0.12); color: #fbbf24; }
body.dark .app-confirm-icon-info,
body.dark .app-confirm-icon-receive { background: rgba(52,168,83,0.12);  color: #5cb87a; }

/* Text */
.app-confirm-title   { margin: 0; font-size: 1rem; font-weight: 700; color: var(--text-color); }
.app-confirm-message { margin: 0.1rem 0 0.5rem; font-size: 0.875rem; color: #888; line-height: 1.55; word-break: break-word; overflow-wrap: anywhere; max-width: 100%; }
body.dark .app-confirm-message { color: #777; }
.app-confirm-message strong { color: var(--text-color); }
.app-confirm-detail {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: #aaa;
}

/* Actions */
.app-confirm-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
  margin-top: 0.5rem;
  width: 100%;
}
.app-confirm-actions .btn-secondary,
.app-confirm-actions .admin-button { flex: 1; justify-content: center; }

/* Button colour variants */
.app-confirm-btn-delete        { background-color: #cc4c4c !important; }
.app-confirm-btn-delete:hover  { background-color: #b03a3a !important; }
body.dark .app-confirm-btn-delete { background-color: #cc4c4c !important; }
.app-confirm-btn-receive        { background-color: #2d8c4e !important; }
.app-confirm-btn-receive:hover  { background-color: #246e3e !important; }
body.dark .app-confirm-btn-receive { background-color: #2d8c4e !important; }
.app-confirm-btn-cancel        { background-color: #b45309 !important; }
.app-confirm-btn-cancel:hover  { background-color: #92400e !important; }
body.dark .app-confirm-btn-cancel  { background-color: #b45309 !important; }

/* ═══════════════════════════════════════════════════════
   APP TOOLTIP
   Elegant hover tooltips via data-tooltip attribute
   ═══════════════════════════════════════════════════════ */
#app-tooltip.app-tooltip {
  position: fixed;
  z-index: 3000;
  pointer-events: none;
  background: #1e293b;
  color: #f1f5f9;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.28);
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  max-width: 260px;
  white-space: normal;
  text-align: center;
}
#app-tooltip.app-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}
body.dark #app-tooltip.app-tooltip {
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #1e3a60;
}

/* ═══════════════════════════════════════════════════════
   APP EMAIL HINT
   Smart email domain suggestion
   ═══════════════════════════════════════════════════════ */
.app-email-hint {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--primary-color, #1d4ed8);
  background: var(--card-bg, #fff);
  border: 1px solid var(--primary-color-light, rgba(29,78,216,0.30));
  border-radius: 6px;
  padding: 0.22rem 0.6rem;
  cursor: pointer;
  z-index: 30;
  font-weight: 500;
  transition: background 0.14s ease, color 0.14s ease;
  white-space: nowrap;
  max-width: 100%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.app-email-hint:hover {
  background: var(--primary-color, #1d4ed8);
  color: #fff;
}
.app-email-hint i { font-size: 0.9rem; }

/* ═══════════════════════════════════════════════════════
   PAGE HEADER — globally standardized
   ═══════════════════════════════════════════════════════ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
  flex-wrap: wrap;
}
.page-header-title,
.page-header-info,
.page-header > div:first-child { flex: 1; min-width: 0; }
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-color, #0f172a);
  margin: 0;
  line-height: 1.2;
}
.page-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted, #64748b);
  margin-top: 0.25rem;
}
.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════════
   TABLE STANDARDIZATION — applied to all .admin-table
   ═══════════════════════════════════════════════════════ */
.admin-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid var(--border, #e2e8f0);
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 0.875rem;
}
.admin-table thead th {
  background: var(--body-color, #f5f7fb);
  color: var(--text-muted, #64748b);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border, #e2e8f0);
  white-space: nowrap;
  vertical-align: middle;
  position: sticky;
  top: 0;
  z-index: 1;
}
.admin-table tbody tr {
  border-bottom: 1px solid var(--border, #e2e8f0);
  transition: background 0.12s ease;
}
.admin-table tbody tr:last-child { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--body-color, #f5f7fb); }
.admin-table tbody td {
  padding: 0.75rem 1rem;
  color: var(--text-color, #0f172a);
  vertical-align: middle;
  max-width: 240px;
}

/* Text overflow — apply .td-truncate to table cells that should ellipsis */
.td-truncate {
  max-width: 0;
  width: 1%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.td-mono {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.3px;
}
/* Name column — always has some fixed width */
.col-name {
  min-width: 160px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Actions column */
.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}
/* Numeric / money columns */
.col-num, .col-money {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
/* Date column */
.col-date { white-space: nowrap; }
/* Phone column */
.col-phone { white-space: nowrap; }

/* ═══════════════════════════════════════════════════════
   TABLE CONTROLS ROW — search + filters
   ═══════════════════════════════════════════════════════ */
.table-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  flex-wrap: wrap;
}
.search-field {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}
.search-field .search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted, #64748b);
  font-size: 1.1rem;
  pointer-events: none;
}
.search-field input {
  width: 100%;
  padding: 0.55rem 0.9rem 0.55rem 2.25rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  font-size: 0.875rem;
  background: var(--card-bg, #fff);
  color: var(--text-color, #0f172a);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.search-field input:focus {
  outline: none;
  border-color: var(--primary-color, #1d4ed8);
  box-shadow: 0 0 0 3px var(--primary-color-light, rgba(29,78,216,0.1));
}

/* Filter chips row (optional) */
.filter-chips {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.filter-chip {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--card-bg, #fff);
  color: var(--text-muted, #64748b);
  cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
  white-space: nowrap;
  font-family: inherit;
}
.filter-chip:hover { border-color: var(--primary-color, #1d4ed8); color: var(--primary-color, #1d4ed8); }
.filter-chip.active {
  background: var(--primary-color, #1d4ed8);
  border-color: var(--primary-color, #1d4ed8);
  color: #fff;
}
.filter-chip-critical {
  border-color: rgba(220,38,38,0.3);
  color: #dc2626;
}
.filter-chip-critical.active {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}
.filter-chip-warning {
  border-color: rgba(217,119,6,0.3);
  color: #d97706;
}
.filter-chip-warning.active {
  background: #d97706;
  border-color: #d97706;
  color: #fff;
}
.filter-chip-service {
  border-color: rgba(99,102,241,0.3);
  color: #6366f1;
}
.filter-chip-service.active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}
.filter-chip-count {
  display: inline-block;
  margin-left: 0.3rem;
  background: rgba(0,0,0,0.1);
  color: inherit;
  border-radius: 999px;
  font-size: 0.7rem;
  padding: 0 0.4rem;
  font-weight: 700;
}
.filter-chip.active .filter-chip-count {
  background: rgba(255,255,255,0.25);
}

/* ═══════════════════════════════════════════════════════
   MODAL IMPROVEMENTS — scroll, layout, focus
   ═══════════════════════════════════════════════════════ */
/* Modal body scroll — apply scrollable class where needed */
.modal-body-scroll {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 2px;           /* prevent scrollbar overlap */
  scroll-behavior: smooth;
}
.modal-body-scroll::-webkit-scrollbar { width: 5px; }
.modal-body-scroll::-webkit-scrollbar-track { background: transparent; }
.modal-body-scroll::-webkit-scrollbar-thumb { background: var(--border, #e2e8f0); border-radius: 999px; }
.modal-body-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-muted, #64748b); }

/* Scrollable item lists inside modals (service-order, sale, quote) */
.order-items-wrapper {
  max-height: 280px;
  overflow-y: auto !important; /* override per-module overflow:hidden */
  overflow-x: hidden;
}
.order-items-wrapper::-webkit-scrollbar { width: 5px; }
.order-items-wrapper::-webkit-scrollbar-track { background: transparent; }
.order-items-wrapper::-webkit-scrollbar-thumb { background: var(--border, #e2e8f0); border-radius: 999px; }
.order-items-wrapper::-webkit-scrollbar-thumb:hover { background: var(--text-muted, #64748b); }

/* Modal overlay backdrop */
.modal-overlay-base {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 1rem;
  overflow-y: auto;
}

/* ═══════════════════════════════════════════════════════
   BTN-SECONDARY — global secondary button
   ═══════════════════════════════════════════════════════ */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: var(--card-bg, #fff);
  color: var(--text-color, #0f172a);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, box-shadow 0.14s;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1;
}
.btn-secondary:hover {
  background: var(--body-color, #f5f7fb);
  border-color: var(--text-muted, #64748b);
}
.btn-secondary:active { transform: scale(0.97); }
.btn-secondary i { font-size: 1rem; }

/* ═══════════════════════════════════════════════════════
   ICON BUTTON — small action buttons in tables
   ═══════════════════════════════════════════════════════ */
.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted, #64748b);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--body-color, #f5f7fb);
  color: var(--text-color, #0f172a);
  border-color: var(--text-muted, #64748b);
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.danger:hover  { color: #dc2626; border-color: rgba(220,38,38,0.3); background: rgba(220,38,38,0.05); }
.icon-btn.primary:hover { color: var(--primary-color, #1d4ed8); border-color: var(--primary-color, #1d4ed8); background: var(--primary-color-light, rgba(29,78,216,0.05)); }
.icon-btn:disabled, .icon-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════
   DETAIL DIALOG — inline item detail overlay
   ═══════════════════════════════════════════════════════ */
.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 1rem;
}
.detail-dialog {
  background: var(--card-bg, #fff);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.22);
  max-width: 580px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}
.detail-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
  flex-shrink: 0;
}
.detail-dialog-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-color, #0f172a);
}
.detail-dialog-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  scroll-behavior: smooth;
}
.detail-dialog-body::-webkit-scrollbar { width: 5px; }
.detail-dialog-body::-webkit-scrollbar-track { background: transparent; }
.detail-dialog-body::-webkit-scrollbar-thumb { background: var(--border, #e2e8f0); border-radius: 999px; }
.detail-dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border, #e2e8f0);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 2rem;
  color: var(--text-muted, #64748b);
  text-align: center;
  gap: 0.5rem;
}
.empty-state i  { font-size: 2.5rem; opacity: 0.4; margin-bottom: 0.25rem; }
.empty-state p  { font-size: 0.95rem; font-weight: 500; }
.empty-state .empty-hint { font-size: 0.85rem; opacity: 0.8; }
.empty-state.hidden { display: none; }

/* ═══════════════════════════════════════════════════════
   ADMIN PANEL — main card container
   ═══════════════════════════════════════════════════════ */
.admin-panel {
  background: var(--card-bg, #fff);
  border-radius: 14px;
  box-shadow: var(--card-shadow, 0 1px 3px rgba(15,23,42,0.04));
  border: 1px solid var(--border, #e2e8f0);
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════
   STATUS BADGES — universal
   ═══════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════ */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ═══════════════════════════════════════════════════════
   DARK MODE overrides
   ═══════════════════════════════════════════════════════ */
body.dark .admin-table-wrapper     { border-color: var(--border, #1e3a60); }
body.dark .admin-table thead th    { background: #1a2a4a; color: var(--text-muted); }
body.dark .admin-table tbody tr:hover { background: rgba(29,78,216,0.06); }
body.dark .icon-btn               { border-color: var(--border, #1e3a60); color: var(--text-muted); }
body.dark .icon-btn:hover         { background: rgba(29,78,216,0.1); }
body.dark .filter-chip            { border-color: var(--border); background: var(--card-bg); }
body.dark .btn-secondary          { border-color: var(--border); background: var(--card-bg); color: var(--text-color); }
body.dark .detail-dialog          { background: var(--card-bg); }
body.dark .app-confirm-dialog     { background: var(--card-bg); }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-actions { width: 100%; }
  .table-controls { flex-direction: column; align-items: stretch; }
  .search-field { max-width: 100%; }
  .app-confirm-dialog { padding: 1.5rem 1.25rem; }

  /* Detail dialog: full-screen sheet on mobile */
  .detail-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .detail-dialog {
    max-width: 100%;
    width: 100%;
    max-height: calc(96dvh - 60px); /* 60px = bottom nav */
    border-radius: 20px 20px 0 0;
    animation: slideUp 0.22s ease-out both;
  }
  .detail-dialog-header {
    padding: 1rem 1.25rem;
  }
  .detail-dialog-body {
    padding: 1rem 1.25rem;
  }
  .detail-dialog-footer {
    padding: 0.875rem 1.25rem;
    flex-wrap: wrap;
  }
  .detail-dialog-footer .btn-secondary,
  .detail-dialog-footer .admin-button {
    flex: 1;
    justify-content: center;
  }

  /* Bigger tap targets for icon buttons */
  .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  /* Action buttons in page-header stretch to fill row */
  .page-header-actions .admin-button,
  .page-header-actions .admin-button-outline {
    flex: 1;
    justify-content: center;
  }

  /* Search field full-width */
  .search-field input {
    min-width: unset;
    width: 100%;
  }
}
