/* HQ CRM — app styles (Tailwind CDN in dev; use PostCSS build for prod) */

/* ─── Base ─── */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

/* Smooth page-level transitions for HTMX content swaps */
#main-content {
  animation: fadeSlideIn 0.22s ease-out;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Subtle scrollbar styling */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.3); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.5); }
.dark ::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); }
.dark ::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.35); }

/* Selection color */
::selection { background: color-mix(in srgb, var(--color-primary, #0ea5e9) 25%, transparent); }

/* Cards — default lift on hover */
.card-hover {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.1), 0 2px 8px -2px rgba(0, 0, 0, 0.06);
}
.dark .card-hover:hover {
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.35), 0 2px 8px -2px rgba(0, 0, 0, 0.2);
}

/* ── Modern form controls ────────────────────────────────────────── */

#app :is(
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):not([type="range"]),
    select,
    textarea
) {
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

#app :is(
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):not([type="range"]),
    select,
    textarea
):hover:not(:focus):not(:disabled):not([readonly]) {
    border-color: #9ca3af;
}
.dark #app :is(
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):not([type="range"]),
    select,
    textarea
):hover:not(:focus):not(:disabled):not([readonly]) {
    border-color: #6b7280;
}

#app :is(
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):not([type="range"]),
    select,
    textarea
):focus {
    outline: none;
    border-color: var(--color-primary, #0ea5e9);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary, #0ea5e9) 15%, transparent),
                0 1px 2px 0 rgb(0 0 0 / 0.05);
}
.dark #app :is(
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):not([type="range"]),
    select,
    textarea
):focus {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary, #0ea5e9) 25%, transparent),
                0 1px 2px 0 rgb(0 0 0 / 0.10);
}

#app input::placeholder,
#app textarea::placeholder {
    color: #9ca3af;
    opacity: 1;
    transition: color 0.15s ease;
}
.dark #app input::placeholder,
.dark #app textarea::placeholder {
    color: #6b7280;
}

#app :is(
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]):not([type="range"]),
    select,
    textarea
):disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#app :is([type="checkbox"], [type="radio"]) {
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
#app :is([type="checkbox"], [type="radio"]):focus {
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary, #0ea5e9) 15%, transparent);
}

/* Sidebar navigation — no bullets, clean list appearance */
#app nav[aria-label="Sidebar"] ul,
#app nav[aria-label="Sidebar"] ul li {
  list-style: none;
  padding-left: 0;
  margin-left: 0;
}
#app nav[aria-label="Sidebar"] ul {
  margin-top: 0;
  margin-bottom: 0;
}

/* Sidebar navigation links: svg icon sizing, no underline, smooth hover */
#app .nav-link {
  text-decoration: none;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
#app .nav-link:hover,
#app .nav-link:focus {
  text-decoration: none;
}
#app .nav-link:hover {
  transform: translateX(2px);
}
#app .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.125rem;
  height: 1.125rem;
  flex: 0 0 1.125rem;
  transition: transform 0.15s ease;
}
#app .nav-link:hover .nav-icon {
  transform: scale(1.1);
}
#app .nav-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Sidebar panel — subtle gradient background for depth */
.sidebar-panel {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}
.dark .sidebar-panel {
  background: linear-gradient(180deg, #1f2937 0%, #1a2332 100%);
}

/* Sidebar group headers — refined spacing */
#app nav[aria-label="Sidebar"] p {
  transition: color 0.15s ease;
}

/* Table row hover: light blue from palette (avoids white/gray on white) in /leads, /billing, and any .datatable-body table */
#app .datatable-body tbody tr:hover {
  background-color: color-mix(in srgb, var(--color-primary, #0ea5e9) 12%, transparent);
}
.dark #app .datatable-body tbody tr:hover {
  background-color: color-mix(in srgb, var(--color-primary, #0ea5e9) 22%, transparent);
}

/* Primary action links in tables (e.g. View on /leads, /billing): darken text on hover so it doesn't blend with row hover */
#app .datatable-body a.text-primary.link-primary-action:hover,
#app .datatable-body button.text-primary.link-primary-action:hover {
  color: color-mix(in srgb, var(--color-primary, #0ea5e9) 78%, #000);
}
.dark #app .datatable-body a.text-primary.link-primary-action:hover,
.dark #app .datatable-body button.text-primary.link-primary-action:hover {
  color: color-mix(in srgb, var(--color-primary, #0ea5e9) 85%, white);
}

/* Sidebar link refinement: active state with left accent */
#app nav[aria-label="Sidebar"] a[class*="bg-primary/10"] {
  border-left: 3px solid var(--color-primary, #0ea5e9);
  padding-left: calc(0.5rem - 3px);
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  border-radius: 0 0.375rem 0.375rem 0;
}
.dark #app nav[aria-label="Sidebar"] a[class*="bg-primary/10"] {
  border-left-color: var(--color-primary, #0ea5e9);
}

/* Dispatch calendar: darken header dates (FullCalendar toolbar title) */
#dispatch-calendar .fc-toolbar-title {
  color: #111827;
  font-weight: 600;
}
.dark #dispatch-calendar .fc-toolbar-title {
  color: #f3f4f6;
}

/* Buttons — all interactive buttons get smooth transitions */
button, [role="button"], a.btn-primary, a.btn-secondary {
    transition: background-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease, opacity 0.15s ease;
}
button:active:not(:disabled), [role="button"]:active:not(:disabled) {
    transform: scale(0.97);
}
.btn-primary {
    background-color: var(--color-primary, #0ea5e9);
    color: #fff;
    border: 0;
    font-weight: 500;
}
.btn-primary:hover {
    background-color: color-mix(in srgb, var(--color-primary, #0ea5e9) 85%, #000);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--color-primary, #0ea5e9) 30%, transparent);
}
.btn-primary:focus-visible {
    outline: 2px solid var(--color-primary, #0ea5e9);
    outline-offset: 2px;
}

/* Tab buttons — active underline indicator */
.bg-primary {
    position: relative;
}

/* Badge / pill styles — refined */
[class*="rounded-full"][class*="text-xs"][class*="font-medium"] {
    letter-spacing: 0.02em;
}

/* Table rows — smooth hover transition */
table tbody tr {
    transition: background-color 0.15s ease;
}

/* Rounded card borders — consistent subtle shadow on all cards */
.rounded-lg[class*="border"][class*="bg-white"],
.rounded-lg[class*="border"].dark\:bg-gray-800 {
    transition: box-shadow 0.2s ease;
}

/* htmx indicator — improved animation */
.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request {
    display: block !important;
    animation: fadeSlideIn 0.2s ease-out;
}
.htmx-indicator {
    display: none;
}

/* Alpine cloak */
[x-cloak] {
    display: none !important;
}

/* x-show transitions — smooth alpine content appearance */
[x-cloak],
[x-show] {
    animation: fadeSlideIn 0.18s ease-out;
}

/* Focus visible for keyboard accessibility (WCAG 2.1) */
:focus-visible {
    outline: 2px solid var(--tw-ring-color, #0ea5e9);
    outline-offset: 2px;
}

/* KPI stat cards — hover lift */
dl .overflow-hidden.rounded-lg,
[class*="rounded-lg"][class*="shadow"][class*="px-4"][class*="py-5"],
[class*="rounded-lg"][class*="shadow"][class*="px-5"][class*="py-4"] {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
dl .overflow-hidden.rounded-lg:hover,
[class*="rounded-lg"][class*="shadow"][class*="px-4"][class*="py-5"]:hover,
[class*="rounded-lg"][class*="shadow"][class*="px-5"][class*="py-4"]:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px -3px rgba(0, 0, 0, 0.08), 0 2px 6px -2px rgba(0, 0, 0, 0.04);
}
.dark dl .overflow-hidden.rounded-lg:hover,
.dark [class*="rounded-lg"][class*="shadow"][class*="px-4"][class*="py-5"]:hover,
.dark [class*="rounded-lg"][class*="shadow"][class*="px-5"][class*="py-4"]:hover {
    box-shadow: 0 6px 16px -3px rgba(0, 0, 0, 0.3), 0 2px 6px -2px rgba(0, 0, 0, 0.15);
}

/* Modal overlay — smooth backdrop */
.fixed[class*="bg-gray-500\\/75"],
.fixed[class*="bg-gray-900\\/80"],
.fixed[class*="bg-gray-900\\/60"],
.fixed[class*="bg-black\\/70"] {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Disabled states — consistent appearance */
:disabled, [disabled], .disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
/* Print-friendly — BOL, estimates, inventory reports */
@media print {
    body * {
        visibility: hidden;
    }
    #main-content,
    #main-content *,
    .print\:block,
    .print\:border-0,
    .print\:shadow-none {
        visibility: visible;
    }
    #main-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
    .print\:hidden,
    nav,
    header,
    .sidebar,
    .htmx-indicator,
    button:not(.print\:block) {
        display: none !important;
    }
}
