/*
 * components.css — Yalla Wrap It ERP
 * Shared UI components: buttons, forms, modals, tables, badges,
 * nav-tabs, cards, kanban, toasts.  Used by all 9 modules.
 */

/* ═══════════════════════════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled           { opacity: 0.5; cursor: not-allowed; }
.btn-sm                 { padding: 5px 10px; font-size: 12px; }
.btn-lg                 { padding: 11px 22px; font-size: 14px; }
.btn-block              { width: 100%; justify-content: center; }

.btn-primary            { background: var(--orange); color: var(--navy); }
.btn-primary:hover      { background: var(--orange-dark); }

.btn-secondary          { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover    { background: var(--light); }

.btn-outline            { background: transparent; color: white; border: 1px solid rgba(255,255,255,0.3); }
.btn-outline:hover      { background: rgba(255,255,255,0.1); }

.btn-outline-dark       { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline-dark:hover { background: var(--light); }

.btn-danger             { background: var(--red); color: white; }
.btn-danger:hover       { background: #C53030; }

.btn-success            { background: var(--green); color: white; }
.btn-success:hover      { background: #276749; }

.btn-ghost              { background: transparent; color: var(--text); }
.btn-ghost:hover        { background: var(--light); }

.btn-icon {
  padding: 6px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover         { background: var(--light); color: var(--text); }

/* ═══════════════════════════════════════════════════════════════════════════════
   FORM ELEMENTS
═══════════════════════════════════════════════════════════════════════════════ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-group.full { grid-column: 1 / -1; }

.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input,
.form-select,
.form-textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: white;
  color: var(--text);
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus  { border-color: var(--blue); }

.form-textarea        { resize: vertical; min-height: 70px; }
.form-hint            { font-size: 11px; color: var(--muted); }

.form-grid            { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3          { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 600px) {
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
}

/* ── Search box ── */
.search-box { position: relative; }
.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}
.search-box input {
  padding-left: 34px !important;
}

/* ── Inline warning / info boxes ── */
.warn-box   { background: #FFFBEB; border: 1px solid #F6E05E; border-radius: 8px; padding: 10px 14px; font-size: 12px; color: #744210; margin-bottom: 12px; }
.info-box   { background: #EBF8FF; border: 1px solid #90CDF4; border-radius: 8px; padding: 10px 14px; font-size: 12px; color: #2C5282; margin-bottom: 12px; }
.success-box{ background: #F0FFF4; border: 1px solid #9AE6B4; border-radius: 8px; padding: 10px 14px; font-size: 12px; color: #22543D; margin-bottom: 12px; }
.error-box  { background: var(--red-light); border: 1px solid #FEB2B2; border-radius: 8px; padding: 10px 14px; font-size: 12px; color: #C53030; margin-bottom: 12px; }

/* ═══════════════════════════════════════════════════════════════════════════════
   TOOLBAR (filter bar below topbar)
═══════════════════════════════════════════════════════════════════════════════ */
.toolbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   MODULE NAV TABS (within a page)
═══════════════════════════════════════════════════════════════════════════════ */
.nav-tabs {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 0;
  overflow-x: auto;
}
.nav-tab {
  padding: 13px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  user-select: none;
}
.nav-tab:hover  { color: var(--navy); }
.nav-tab.active { color: var(--navy); border-bottom-color: var(--orange); font-weight: 600; }
.nav-badge {
  background: var(--orange);
  color: var(--navy);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 5px;
}
.nav-badge.warn { background: var(--red); color: white; }

/* ═══════════════════════════════════════════════════════════════════════════════
   TABLES
═══════════════════════════════════════════════════════════════════════════════ */
.table-wrap {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}
.table-wrap thead th {
  background: var(--navy);
  color: white;
  padding: 11px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.table-wrap thead th:hover { background: var(--navy-2); }
.table-wrap tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.table-wrap tbody tr:last-child { border-bottom: none; }
.table-wrap tbody tr:hover { background: #F7FAFC; cursor: pointer; }
.table-wrap tbody td {
  padding: 11px 14px;
  font-size: 13px;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   CARDS
═══════════════════════════════════════════════════════════════════════════════ */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.card-header {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header .card-header-link {
  font-size: 11px;
  font-weight: 500;
  color: var(--blue);
  cursor: pointer;
}
.card-header .card-header-link:hover { text-decoration: underline; }

/* KPI / stat card */
.kpi-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
}
.kpi-card:hover { border-color: var(--orange); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,0.06); }
.kpi-card .kc-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; margin-bottom: 6px; }
.kpi-card .kc-value { font-size: 28px; font-weight: 800; color: var(--navy); line-height: 1.1; }
.kpi-card .kc-value.sm { font-size: 20px; }
.kpi-card .kc-sub   { font-size: 11px; color: var(--muted); margin-top: 4px; }
.kpi-card .kc-icon  { position: absolute; top: 14px; right: 14px; font-size: 20px; opacity: 0.15; }
.kpi-card.warn  { border-left: 3px solid var(--amber); }
.kpi-card.warn .kc-value { color: var(--amber); }
.kpi-card.danger{ border-left: 3px solid var(--red); }
.kpi-card.danger .kc-value { color: var(--red); }
.kpi-card.success{ border-left: 3px solid var(--green); }
.kpi-card.success .kc-value { color: var(--green); }

/* ═══════════════════════════════════════════════════════════════════════════════
   BADGES / PILLS
═══════════════════════════════════════════════════════════════════════════════ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--light);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.warn    { background: var(--amber-light); color: #744210; border-color: #F6E05E; }
.badge.danger  { background: var(--red-light);   color: #C53030; border-color: #FEB2B2; }
.badge.success { background: var(--green-light);  color: #276749; border-color: #9AE6B4; }
.badge.info    { background: #EBF8FF; color: #2C5282; border-color: #90CDF4; }
.badge.vip     { background: #FFFAF0; color: var(--amber); border-color: var(--orange); font-weight: 700; }
.badge.purple  { background: #E9D8FD; color: #6B46C1; border-color: #D6BCFA; }

/* Status pills (larger) */
.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.hidden { display: none !important; }

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
  animation: modalIn 0.2s ease forwards;
}
.modal.modal-sm  { max-width: 440px; }
.modal.modal-lg  { max-width: 800px; }
.modal.modal-xl  { max-width: 1000px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}
.modal-header h2  { font-size: 17px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0 4px;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  flex-shrink: 0;
}
.modal-tab {
  padding: 11px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.modal-tab:hover  { color: var(--navy); }
.modal-tab.active { color: var(--navy); border-bottom-color: var(--orange); font-weight: 600; }

.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   EMPTY STATES
═══════════════════════════════════════════════════════════════════════════════ */
.empty-state {
  background: white;
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 60px 24px;
  text-align: center;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 14px; }
.empty-state h3  { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.empty-state p   { font-size: 13px; color: var(--muted); margin-bottom: 20px; max-width: 440px; margin-left: auto; margin-right: auto; }
.empty-state .empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ═══════════════════════════════════════════════════════════════════════════════
   SECTION GRID HELPERS
═══════════════════════════════════════════════════════════════════════════════ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.grid-kpi  { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px)  { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px)  {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   ACTIVITY / TIMELINE LIST
═══════════════════════════════════════════════════════════════════════════════ */
.activity-list { display: flex; flex-direction: column; gap: 8px; }
.activity-item {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  background: var(--light);
  border-radius: 8px;
}
.activity-item .ai-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.activity-item .ai-body { flex: 1; min-width: 0; }
.activity-item .ai-title { font-size: 12px; font-weight: 500; }
.activity-item .ai-meta  { font-size: 10px; color: var(--muted); margin-top: 1px; }

/* ═══════════════════════════════════════════════════════════════════════════════
   SPINNER / LOADING
═══════════════════════════════════════════════════════════════════════════════ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner.dark {
  border-color: var(--border);
  border-top-color: var(--navy);
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  z-index: 10;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   PERIOD PILL (dashboard)
═══════════════════════════════════════════════════════════════════════════════ */
.period-pill {
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 4px 6px;
  display: flex;
  gap: 2px;
}
.period-pill button {
  background: transparent;
  color: rgba(255,255,255,0.7);
  border: none;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
  font-family: inherit;
}
.period-pill button.active {
  background: var(--orange);
  color: var(--navy);
  font-weight: 700;
}
.period-pill button:hover:not(.active) {
  background: rgba(255,255,255,0.08);
  color: white;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SHARED STATUS PILLS (used by Client Picker dropdown + cross-module lists)
═══════════════════════════════════════════════════════════════════════════════ */
.st-pill { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.st-pill.st-Lead     { background: #EDF2F7; color: #4A5568; }
.st-pill.st-Active   { background: #BEE3F8; color: #2B6CB0; }
.st-pill.st-Customer { background: #C6F6D5; color: #276749; }
.st-pill.st-Repeat   { background: #E9D8FD; color: #6B46C1; }
.st-pill.st-Lost     { background: #FED7D7; color: #C53030; }
.st-pill.st-Inactive { background: #EDF2F7; color: #4A5568; }
.st-pill.st-VIP      { background: #FFFAF0; color: var(--amber); border: 1px solid var(--orange); font-weight: 700; }

/* ═══════════════════════════════════════════════════════════════════════════════
   CLIENT PICKER (autocomplete used in Viewing / Installation / Quote / Lead modals)
═══════════════════════════════════════════════════════════════════════════════ */
.client-picker .cp-item:hover { background: #FFFAF0 !important; }
.client-picker-panel { font-family: inherit; }

/* ═══════════════════════════════════════════════════════════════════════════════
   LOOKUP MANAGER (admin Settings modal)
═══════════════════════════════════════════════════════════════════════════════ */
.lkm-wrap { display: grid; grid-template-columns: 220px 1fr; gap: 14px; min-height: 420px; }
.lkm-types { background: var(--light); border-radius: 10px; padding: 6px; overflow-y: auto; }
.lkm-type-btn { padding: 9px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--text); user-select: none; display: flex; justify-content: space-between; align-items: center; }
.lkm-type-btn:hover { background: white; }
.lkm-type-btn.active { background: var(--navy); color: white; font-weight: 600; }
.lkm-type-btn .count { font-size: 11px; opacity: 0.8; }
.lkm-list { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 0; overflow: hidden; }
.lkm-list-header { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; background: var(--light); }
.lkm-list-header h4 { font-size: 14px; font-weight: 700; flex: 1; }
.lkm-row { display: grid; grid-template-columns: 24px 1fr 1fr 90px 80px 80px; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); align-items: center; font-size: 13px; }
.lkm-row:last-child { border-bottom: none; }
.lkm-row.inactive { opacity: 0.55; }
.lkm-row input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; font-family: inherit; width: 100%; }
.lkm-row input[type=color] { padding: 0; height: 28px; cursor: pointer; }
.lkm-row .lkm-grip { cursor: ns-resize; color: var(--muted); text-align: center; user-select: none; }
.lkm-row .lkm-actions { display: flex; gap: 4px; justify-content: flex-end; }
.lkm-row .lkm-actions button { padding: 3px 9px; font-size: 11px; border-radius: 5px; border: 1px solid var(--border); background: white; cursor: pointer; font-family: inherit; }
.lkm-row .lkm-actions button:hover { background: var(--light); }
.lkm-row .lkm-actions .danger { color: var(--red); border-color: #FEB2B2; }
.lkm-row .lkm-system-tag { font-size: 10px; color: var(--muted); padding: 2px 6px; background: var(--light); border-radius: 4px; }

/* ═══════════════════════════════════════════════════════════════════════════════
   UTILITY
═══════════════════════════════════════════════════════════════════════════════ */
.hidden   { display: none !important; }
.text-muted  { color: var(--muted); }
.text-navy   { color: var(--navy); }
.text-orange { color: var(--orange); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.font-bold   { font-weight: 700; }
.mt-0  { margin-top: 0; }
.mt-8  { margin-top: 8px; }
.mt-14 { margin-top: 14px; }
.mt-20 { margin-top: 20px; }
.mb-14 { margin-bottom: 14px; }
.mb-20 { margin-bottom: 20px; }
