/* ============================================================
   TourCRM Components
   ============================================================ */

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  height: 36px;
  min-height: 36px;
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-secondary {
  background: var(--color-bg-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg-surface-hover); }

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

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

.btn-sm { height: 28px; padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-lg { height: 44px; padding: var(--space-3) var(--space-6); font-size: var(--text-md); }

/* ---- Inputs ---- */

.input, .select, .textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
  height: 36px;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.input::placeholder { color: var(--color-text-muted); }

.textarea {
  height: auto;
  min-height: 80px;
  resize: vertical;
}

.label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  margin-block-end: var(--space-1);
}

.field {
  margin-block-end: var(--space-4);
}

.input.invalid, .select.invalid {
  border-color: var(--color-danger);
}
.input.invalid:focus, .select.invalid:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}
.field-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-block-start: var(--space-1);
}

/* ---- Cards ---- */

.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  min-width: 0;
  overflow-wrap: break-word;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-block-end: var(--space-4);
}

/* ---- Status Badge ---- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.badge-new        { background: #DBEAFE; color: #1E40AF; }
.badge-processing { background: #FEF3C7; color: #92400E; }
.badge-confirmed  { background: #D1FAE5; color: #065F46; }
.badge-paid       { background: #D1FAE5; color: #065F46; }
.badge-on-tour    { background: #EDE9FE; color: #5B21B6; }
.badge-completed  { background: #F3F4F6; color: #374151; }
.badge-cancelled  { background: #FEE2E2; color: #991B1B; }
.badge-overdue    { background: #FEE2E2; color: #991B1B; }
.badge-draft      { background: #F3F4F6; color: #6B7280; }

/* Dark theme badge adjustments */
[data-theme="dark"] .badge-new        { background: #1E3A5F; color: #93C5FD; }
[data-theme="dark"] .badge-processing { background: #451A03; color: #FCD34D; }
[data-theme="dark"] .badge-confirmed  { background: #064E3B; color: #6EE7B7; }
[data-theme="dark"] .badge-completed  { background: #1F2937; color: #9CA3AF; }
[data-theme="dark"] .badge-cancelled  { background: #450A0A; color: #FCA5A5; }
[data-theme="dark"] .badge-draft      { background: #1F2937; color: #9CA3AF; }

/* ---- Toast ---- */

.toast-container {
  position: fixed;
  inset-block-start: var(--space-4);
  inset-inline-end: var(--space-4);
  z-index: var(--z-tooltip);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 400px;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  min-width: 280px;
  animation: toast-in 0.2s ease-out;
}

.toast-text {
  flex: 1;
}

.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-muted);
  flex-shrink: 0;
  font-size: var(--text-md);
  line-height: 1;
}

.toast-close:hover {
  background: var(--color-bg-surface-hover);
  color: var(--color-text);
}

.toast-success { border-inline-start: 3px solid var(--color-success); }
.toast-error   { border-inline-start: 3px solid var(--color-danger); }
.toast-warning { border-inline-start: 3px solid var(--color-warning); }
.toast-info    { border-inline-start: 3px solid var(--color-info); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal-overlay);
  animation: fade-in 0.15s ease;
  padding: var(--space-4);
}

.modal {
  background: var(--color-bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--space-6);
  max-width: min(640px, calc(100vw - 2rem));
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: modal-in 0.2s ease-out;
  position: relative;
}

.modal-sm {
  max-width: min(400px, calc(100vw - 2rem));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-block-end: var(--space-4);
}

.modal-title {
  font-size: var(--text-lg);
  margin: 0;
  flex: 1;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--color-bg-surface-hover);
  color: var(--color-text);
}

.modal-actions { display: flex; gap: var(--space-3); justify-content: flex-end; margin-block-start: var(--space-6); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* Modal full-screen on mobile */
@media (max-width: 767px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: modal-slide-up 0.25s ease-out;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

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

@keyframes modal-slide-up {
  from { opacity: 0; transform: translateY(100%); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Command Palette ---- */

.cmd-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-tooltip);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-block-start: 15vh;
}

.cmd-palette {
  background: var(--color-bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 560px;
  max-width: 90vw;
  max-height: 400px;
  overflow: hidden;
  animation: modal-in 0.15s ease-out;
}

.cmd-palette-input {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-md);
  border: none;
  border-block-end: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  outline: none;
  font-family: var(--font-body);
}

.cmd-palette-results {
  max-height: 320px;
  overflow-y: auto;
  padding: var(--space-2);
}

.cmd-palette-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  min-height: 40px;
}

.cmd-palette-item:hover,
.cmd-palette-item.active {
  background: var(--color-bg-surface-hover);
}

.cmd-palette-item-icon { color: var(--color-text-muted); width: 18px; }
.cmd-palette-item-label { flex: 1; }
.cmd-palette-item-hint { color: var(--color-text-muted); font-size: var(--text-xs); }

/* ---- Empty State ---- */

.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--color-text-muted);
}

.empty-state-icon { font-size: 48px; margin-block-end: var(--space-4); opacity: 0.4; }
.empty-state-title { font-size: var(--text-lg); color: var(--color-text-secondary); margin-block-end: var(--space-2); }
.empty-state-text { font-size: var(--text-sm); margin-block-end: var(--space-6); }

/* ---- Table ---- */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead th {
  text-align: start;
  padding: var(--space-3) var(--space-4);
  font-weight: var(--weight-semibold);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  background: var(--color-bg-muted);
  border-block-end: 1px solid var(--color-border);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
}

tbody td {
  padding: var(--space-3) var(--space-4);
  border-block-end: 1px solid var(--color-border);
}

tbody tr:hover { background: var(--color-bg-surface-hover); }
tbody tr:last-child td { border-block-end: none; }

/* ---- Dropdown Menu (three-dot) ---- */

.dropdown {
  position: relative;
  display: inline-flex;
}

.dropdown-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

.dropdown-trigger:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.dropdown-trigger:hover {
  background: var(--color-bg-surface-hover);
  color: var(--color-text);
}

.dropdown-menu {
  position: absolute;
  inset-block-start: 100%;
  inset-inline-end: 0;
  margin-block-start: var(--space-1);
  min-width: 160px;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  z-index: var(--z-dropdown);
  animation: dropdown-in 0.12s ease-out;
  display: none;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  border: none;
  background: none;
  width: 100%;
  text-align: start;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  min-height: 36px;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
  background: var(--color-bg-surface-hover);
  outline: none;
}

.dropdown-item-danger {
  color: var(--color-danger);
}

.dropdown-item-danger:hover,
.dropdown-item-danger:focus-visible {
  background: var(--color-danger-light);
}

.dropdown-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-1) 0;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Hover Actions (show on parent hover) ---- */

.hover-actions {
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.hover-parent:hover .hover-actions,
.hover-actions:focus-within {
  opacity: 1;
}

/* ---- Icon Button (small, for inline actions) ---- */

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--color-bg-surface-hover);
  color: var(--color-text);
}

.btn-icon:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn-icon-danger:hover {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

/* ---- List row: hover-revealed open-details button next to the name ---- */

.row-name-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.row-name-text {
  font-weight: var(--weight-medium);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-open-btn {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
  color: var(--color-primary);
}
@media (hover: hover) {
  tr:hover .row-open-btn,
  tr:focus-within .row-open-btn {
    opacity: 1;
  }
}
/* Touch devices have no hover — keep the button always visible. */
@media (hover: none) {
  .row-open-btn { opacity: 1; }
}

/* ---- Timeline (for notes / activity) ---- */

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-block-end: 1px solid var(--color-border);
}

.timeline-item:last-child {
  border-block-end: none;
}

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  flex-shrink: 0;
  margin-block-start: 6px;
}

.timeline-content {
  flex: 1;
  min-width: 0;
}

.timeline-text {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-text);
}

.timeline-meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-block-start: var(--space-1);
}

/* ---- Section Header (for card sections) ---- */

.section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-block-end: var(--space-3);
}

/* ---- Client Header (entity detail pages) ---- */

.entity-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-block-end: var(--space-6);
}

.entity-header-info {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
}

.entity-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
}

.entity-name {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  font-family: var(--font-body);
  line-height: var(--leading-tight);
}

.entity-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-block-start: var(--space-1);
  flex-wrap: wrap;
}

.entity-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ---- List Item (phone, traveller rows etc) ---- */

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

.list-item + .list-item {
  border-block-start: 1px solid var(--color-border);
}

/* ---- Disabled button ---- */

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Loading spinner ---- */

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

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

/* ---- Mobile toast ---- */
@media (max-width: 767px) {
  .toast-container {
    inset-inline-start: var(--space-4);
    inset-inline-end: var(--space-4);
    max-width: none;
  }

  .toast {
    min-width: auto;
    width: 100%;
  }
}

/* ---- Rich-text display ---- */
.rt-display ul, .rt-display ol { margin: 0 0 .6em 20px; padding: 0; }
.rt-display p { margin: 0 0 .6em; }
.rt-display p:last-child { margin-bottom: 0; }
.rt-display a { color: var(--color-primary); text-decoration: underline; }
.rt-display { line-height: 1.5; }
