/*
 * main.css
 * Mobile-first global styles: layout guards, safe-area insets, scroll
 * behaviour and touch ergonomics. Tailwind handles the visual design.
 */

:root {
    color-scheme: dark;
}

/* Keep the original 500px logo in its native square proportions. */
.salon-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; }
.header-brand { font-size: 11px; line-height: 1.5; }
.header-salon-name { font-size: 18px; line-height: 1.35; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.header-branch-controls { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.header-branch-controls:empty { display: none; }
.header-branch-selector { flex: 1; min-width: 0; max-width: 360px; }
.setup-page { max-width: 960px; margin-inline: auto; }
.setup-steps { display: grid; grid-template-columns: 1fr; gap: 8px; }
.setup-steps button { width: 100%; display: grid; grid-template-columns: 28px 1fr; gap: 4px 10px; text-align: left; padding: 12px; border: 1px solid #1e293b; border-radius: 12px; font-size: 13px; color: #cbd5e1; }
.setup-steps button > span:last-child { grid-column: 2; }
.setup-steps button[aria-current] { border-color: #f43f8e; color: #fbcfe8; }
.setup-steps button:disabled { opacity: .5; cursor: not-allowed; }
.setup-step-number { grid-row: span 2; align-self: center; font-weight: 700; }
.branch-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.branch-form > * { min-width: 0; }
.branch-form input, .branch-form select { min-height: 44px; }
.branch-form > button[type=submit] { margin-top: 4px; }
@media (min-width: 640px) {
    .branch-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .branch-form > div:first-of-type, .branch-form > div:nth-last-of-type(-n+2), .branch-form > button { grid-column: 1 / -1; }
    .setup-steps { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .setup-steps button { height: 100%; grid-template-columns: 1fr; }
    .setup-step-number { grid-row: auto; }
    .setup-steps button > span:last-child { grid-column: 1; }
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Phone-like app shell, centered on larger screens, never wider than the viewport. */
.app-shell {
    width: 100%;
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    overflow: hidden;
    min-height: 100dvh;
    height: 100dvh;
    border-left: 1px solid #1e293b;
    border-right: 1px solid #1e293b;
    /* No horizontal overflow under any circumstances. */
    overflow-x: hidden;
}

.app-shell main {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
    width: 100%;
    max-width: 100%;
}

.app-shell main::-webkit-scrollbar {
    width: 4px;
}

.app-shell main::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 999px;
}

/* Safe-area insets for notched devices (iOS) and foldables. */
@supports (padding: env(safe-area-inset-bottom)) {
    .safe-bottom {
        padding-bottom: calc(0.625rem + env(safe-area-inset-bottom, 0px));
    }
    .app-shell main {
        padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
    }
}

/* Hide scrollbars on horizontal pager / lists. */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Touch-friendly interaction targets. */
button,
[role='button'],
select,
input,
a {
    touch-action: manipulation;
}

select {
    -webkit-appearance: none;
    appearance: none;
}

/* Hide number input spinners (keeps form compact on mobile). */
input[type='number'].input-number::-webkit-outer-spin-button,
input[type='number'].input-number::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type='number'].input-number {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Date/time inputs: native picker friendly sizing. */
input[type='date'],
input[type='time'] {
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
}

/* Clear/visible focus for keyboard users; not on touch taps. */
button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid #f43f8e;
    outline-offset: 2px;
    border-radius: 0.75rem;
}

/* Invalid-field styling driven by the client-side validator. */
.field-invalid {
    border-color: rgba(244, 63, 94, 0.75) !important;
    box-shadow: 0 0 0 1px rgba(244, 63, 94, 0.45);
}

/* Prevent text selection on interactive chrome. */
button,
[role='button'] {
    user-select: none;
    -webkit-user-select: none;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ================================================================
   DESKTOP LAYOUT (>= 1024px)
   Full SaaS dashboard: sidebar nav, wider content, centered modals.
   All mobile styles remain untouched below this comment.
   ================================================================ */
@media (min-width: 1024px) {
    /* --- App Shell: remove phone-frame constraints --- */
    .app-shell {
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
        border-left: none !important;
        border-right: none !important;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
        position: relative;
    }

    /* Desktop sidebar — hidden on mobile (Tailwind `hidden lg:flex`) */
    [data-nav="sidebar"] {
        display: flex !important;
    }

    /* Mobile bottom nav — hidden on desktop */
    [data-nav="bottom"] {
        display: none !important;
    }

    /* --- Row container: sidebar + content column --- */
    .desktop-container {
        flex: 1 1 0% !important;
        min-height: 0;
        min-width: 0;
        display: flex;
        flex-direction: row;
    }

    /* --- Header: clean top bar in the content column --- */
    .desktop-container header {
        position: sticky;
        top: 0;
        z-index: 30;
    }

    /* --- Main content: flexible area with comfortable padding --- */
    .desktop-container main {
        flex: 1 1 0%;
        min-width: 0;
        overflow-y: auto;
        overflow-x: hidden;
        scrollbar-width: thin;
        scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
        padding-bottom: 2rem !important;
        padding-left: 2rem !important;
        padding-right: 2rem !important;
    }

    /* Content wrapper max-width for readability on ultrawide */
    .desktop-container main > * {
        max-width: 90rem;
        margin-left: auto;
        margin-right: auto;
        width: 100%;
    }

    /* --- Modals: centered dialog, not bottom sheet --- */
    .app-shell [data-action="modal-backdrop"] {
        align-items: center;
        justify-content: center;
        padding: 2rem;
    }

    .app-shell [data-action="modal-backdrop"] > div {
        max-height: 85vh;
        width: 100%;
        max-width: 36rem;
        border-radius: 1.5rem;
        border: 1px solid rgba(30, 41, 59, 0.6);
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
        margin: auto;
    }

    /* --- Dashboard / data-view responsive grids ---
       Specific layouts are applied via Tailwind `lg:` classes inside the
       view renderers (dashboard.js, customers.js, etc.). */

    /* Appointment filter bar: horizontal layout on desktop */
    .desktop-container .grid.grid-cols-2.gap-1\\.5 {
        display: flex;
        gap: 0.5rem;
    }

    .desktop-container .grid.grid-cols-2.gap-1\\.5 > * {
        flex: 1;
        min-width: 0;
    }

    /* --- Section headers: slightly larger typography --- */
    .desktop-container h2.text-lg {
        font-size: 1.25rem;
    }

    /* --- Login: centered card on desktop --- */
    .desktop-container .bg-gradient-to-b.from-slate-900,
    .app-shell > .bg-gradient-to-b.from-slate-900 {
        justify-content: center;
        align-items: center;
    }

    .app-shell > .bg-gradient-to-b.from-slate-900 > div.text-center,
    .app-shell > .bg-gradient-to-b.from-slate-900 > div.w-full {
        max-width: 24rem;
        width: 100%;
    }
}

/* Desktop xl: even more space */
@media (min-width: 1280px) {
    .desktop-container main {
        padding-left: 2.5rem !important;
        padding-right: 2.5rem !important;
    }
}

/* Desktop 2xl: ultrawide optimization */
@media (min-width: 1536px) {
    .desktop-container main {
        padding-left: 3rem !important;
        padding-right: 3rem !important;
    }

    .desktop-container main > * {
        max-width: 100rem;
    }
}

/* ================================================================
   GLOBAL ICON & BUTTON SIZING SYSTEM — desktop (>= 1024px only)
   ----------------------------------------------------------------
   Audit baseline (mobile-first base, < 1024px — intentionally
   untouched by every rule below):
     • default icons .......... 16px (w-4 h-4 via js/ui/icons.js)
     • meta / inline icons .... 12px (w-3) / 14px (w-3.5)
     • sidebar nav icons ...... 18px, labels 13px, rows ~41px tall
     • header icon buttons .... 36px box, 16px icon
     • table / card actions ... 32px box, 14px icon (iconAction)
     • text action buttons .... ~32px tall, 12px text (actionButton)
     • tab pills / chips ...... ~33px tall, 11px text, 14px icon
     • quick-action tiles ..... 40-48px tile, 20-24px icon, 10-11px label
     • modal close ............ 32px box, 16px icon
     • submit buttons ......... ~48px tall, 12px text (height already ok)
   Desktop comfort scale applied below (all modules — Dashboard,
   Customers, Staff, Appointments, Services, Billing, Expenses,
   Reports, Settings — via shared selectors, no one-off styles):
     • meta icons 16px / inline & button icons 18px
     • nav / header / dropdown icons 20px / feature icons 24px
     • icon-only buttons 40px (header 44px), text buttons 40px min-height,
       primary submit buttons 48px min-height.
   Unlayered author CSS wins over Tailwind's layered utilities, so no
   !important is needed; pre-lucide <i> and rendered <svg> are both
   covered (lucide copies classes onto the svg).
   ================================================================ */
@media (min-width: 1024px) {
    :root {
        --icon-meta: 1rem; /* 16px — badges, timestamps, meta rows */
        --icon-inline: 1.125rem; /* 18px — search, inline & button icons */
        --icon-button: 1.25rem; /* 20px — header, nav & dropdown icons */
        --icon-feature: 1.5rem; /* 24px — quick-action & feature tiles */
        --btn-icon: 2.5rem; /* 40px — icon-only touch target */
        --btn-min-h: 2.5rem; /* 40px — text-button touch target */
    }

    /* --- 1. Tiny meta icons: 12px (w-3) → 16px -------------------- */
    .desktop-container svg.lucide.w-3,
    .desktop-container i[data-lucide].w-3 {
        width: var(--icon-meta);
        height: var(--icon-meta);
    }

    /* --- 2. Small icons: 14px (w-3.5) → 16px ---------------------- */
    .desktop-container svg.lucide.w-3\.5,
    .desktop-container i[data-lucide].w-3\.5 {
        width: var(--icon-meta);
        height: var(--icon-meta);
    }

    /* --- 3. Standard icons: 16px (w-4) → 18px --------------------- */
    .desktop-container svg.lucide.w-4,
    .desktop-container i[data-lucide].w-4 {
        width: var(--icon-inline);
        height: var(--icon-inline);
    }

    /* --- 4. Sidebar navigation: 20px icons, 44px rows, 14px labels - */
    .desktop-container [data-nav='sidebar'] button {
        min-height: 2.75rem;
        font-size: 0.875rem;
    }
    .desktop-container [data-nav='sidebar'] button svg.lucide,
    .desktop-container [data-nav='sidebar'] button i[data-lucide] {
        width: var(--icon-button);
        height: var(--icon-button);
    }
    .desktop-container [data-nav='sidebar'] button[data-tab='quickBilling'] {
        min-height: 3rem;
    }
    .desktop-container [data-nav='sidebar'] select[data-action='salon'] {
        min-height: 2.5rem;
        font-size: 0.75rem;
    }

    /* --- 5. App header: 44px buttons, 20px icons, balanced type --- */
    .desktop-container header button[data-action='open-help-menu'],
    .desktop-container header button[data-action='logout'] {
        width: 2.75rem;
        height: 2.75rem;
    }
    .desktop-container header button svg.lucide,
    .desktop-container header button i[data-lucide] {
        width: var(--icon-button);
        height: var(--icon-button);
    }
    .desktop-container header select[data-action='salon'] {
        min-height: var(--btn-icon);
        font-size: 0.75rem;
    }
    .desktop-container header h1 {
        font-size: 0.875rem;
    }

    /* --- 6. Section-header action buttons: 40px tall, 13-14px ----- */
    .desktop-container main button[data-action='modal']:not(.flex-col),
    .desktop-container main button[data-action='role'],
    .desktop-container main button[data-action='manage-salon'],
    .desktop-container main button[data-action='tab']:not(.flex-col):not(.w-9) {
        min-height: var(--btn-min-h);
        padding: 0.625rem 1rem;
        font-size: 0.8125rem;
    }
    .desktop-container main button[data-action='section-info'] {
        width: var(--btn-icon);
        height: var(--btn-icon);
    }
    .desktop-container main button[data-action='section-info'] svg.lucide,
    .desktop-container main button[data-action='section-info'] i[data-lucide] {
        width: var(--icon-inline);
        height: var(--icon-inline);
    }

    /* --- 7. Table / card row actions: 40px targets, 18px icons --- */
    .desktop-container main button[data-action='open-edit'],
    .desktop-container main button[data-action='request-delete'],
    .desktop-container main button[data-action='open-payment'],
    .desktop-container main button[data-action='customer-profile'],
    .desktop-container main button[data-action='toggle-service-active'] {
        min-width: var(--btn-icon);
        min-height: var(--btn-icon);
        font-size: 0.8125rem;
    }
    .desktop-container main button[data-action='refund-invoice'] {
        min-height: 3rem;
        font-size: 0.875rem;
    }
    .desktop-container main button[data-action='wallet-use-max'],
    .app-shell [data-action='modal-backdrop'] button[data-action='wallet-use-max'] {
        min-height: 2.25rem;
        padding: 0.375rem 0.875rem;
        font-size: 0.75rem;
    }
    .desktop-container main button[data-action='tab'].w-9,
    .desktop-container main button[data-action='attendance-day-prev'],
    .desktop-container main button[data-action='attendance-day-next'] {
        width: var(--btn-icon);
        height: var(--btn-icon);
    }
    .desktop-container main button[data-action='attendance-mark'] {
        min-height: var(--btn-min-h);
        padding: 0.625rem 1rem;
        font-size: 0.8125rem;
    }
    .desktop-container main button[data-action='attendance-day-today'] {
        min-height: var(--btn-icon);
        padding-left: 1rem;
        padding-right: 1rem;
        font-size: 0.75rem;
    }

    /* --- 8. Quick status pills (Start / Complete): 32px, 12px ----- */
    .desktop-container main button[data-action='update-appointment-status'] {
        min-height: 2rem;
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
    }

    /* --- 9. Tab pills & filter chips: 40px / 38px ----------------- */
    .desktop-container main button[data-action='dashboard-tab'],
    .desktop-container main button[data-action='staff-tab'],
    .desktop-container main button[data-action='referral-tab'] {
        min-height: var(--btn-min-h);
        font-size: 0.75rem;
    }
    .desktop-container main button[data-action='referral-filter'] {
        min-height: 2.375rem;
        padding: 0.5rem 1rem;
        font-size: 0.75rem;
    }
    .desktop-container main button[data-action='clear-appointment-filters'] {
        min-height: 2rem;
        font-size: 0.75rem;
    }

    /* --- 10. Dashboard quick-action tiles: 56px art, 24px icons --- */
    .desktop-container main button.flex-col {
        padding: 1rem 0.5rem;
    }
    .desktop-container main button.flex-col > div {
        width: 3.5rem;
        height: 3.5rem;
    }
    .desktop-container main button.flex-col > div svg.lucide,
    .desktop-container main button.flex-col > div i[data-lucide] {
        width: var(--icon-feature);
        height: var(--icon-feature);
    }
    .desktop-container main button.flex-col > span {
        font-size: 0.75rem;
    }

    /* --- 11. Filter bars, search & dropdown controls: 40-44px ----- */
    .desktop-container main input[data-action='appointment-search'],
    .desktop-container main select[data-action='appointment-filter'],
    .desktop-container main input[data-action='customer-search-list'],
    .desktop-container main input[data-action='service-search-list'],
    .desktop-container main input[data-action='referral-search'],
    .desktop-container main input[data-action='quick-billing-service-search'],
    .desktop-container main input[data-action='attendance-month'],
    .desktop-container main select[data-action='attendance-staff-filter'] {
        min-height: 2.75rem;
        font-size: 0.8125rem;
    }
    .desktop-container main input[data-action='attendance-date'] {
        min-height: 2.75rem;
        font-size: 0.8125rem;
    }
    .desktop-container main button[data-action='clear-customer-search'],
    .desktop-container main button[data-action='clear-service-search'] {
        width: 1.75rem;
        height: 1.75rem;
    }

    /* --- 12. Dropdown / suggestion rows: 52px, 20px icons --------- */
    .desktop-container main button[data-action='quick-billing-select-customer'],
    .desktop-container main button[data-action='quick-billing-add-service'] {
        min-height: 3.25rem;
        padding: 0.75rem 1rem;
    }
    .desktop-container main button[data-action='quick-billing-select-customer'] svg.lucide,
    .desktop-container main button[data-action='quick-billing-select-customer'] i[data-lucide],
    .desktop-container main button[data-action='quick-billing-add-service'] svg.lucide,
    .desktop-container main button[data-action='quick-billing-add-service'] i[data-lucide] {
        width: var(--icon-button);
        height: var(--icon-button);
    }

    /* --- 12b. Inline line-item remove buttons: 28px → 40px squares --- */
    .desktop-container main button[data-action='quick-billing-remove-service'] {
        width: var(--btn-icon);
        height: var(--btn-icon);
    }

    /* --- 13. Attendance badges & report table: roomier type -------- */
    .desktop-container main span[data-status] > span:last-child {
        font-size: 0.6875rem;
    }
    .desktop-container main table th {
        padding: 0.75rem;
        font-size: 0.625rem;
    }
    .desktop-container main table td {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }

    /* --- 14. Primary submit buttons: 48px, 14px -------------------- */
    .desktop-container main button[type='submit'] {
        min-height: 3rem;
        font-size: 0.875rem;
    }

    /* --- 15. Modal sheets (rendered outside .desktop-container) ---- */
    .app-shell [data-action='modal-backdrop'] button {
        min-height: var(--btn-min-h);
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='remove-appointment-service'] {
        width: var(--btn-icon);
        height: var(--btn-icon);
        min-height: var(--btn-icon);
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='close-modal'].rounded-full {
        width: var(--btn-icon);
        height: var(--btn-icon);
        min-height: var(--btn-icon);
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='close-modal'].rounded-full svg.lucide,
    .app-shell [data-action='modal-backdrop'] button[data-action='close-modal'].rounded-full i[data-lucide] {
        width: var(--icon-button);
        height: var(--icon-button);
    }
    .app-shell [data-action='modal-backdrop'] button[type='submit'],
    .app-shell [data-action='modal-backdrop'] button[data-action='confirm-delete'] {
        min-height: 3rem;
        font-size: 0.875rem;
    }
    .app-shell [data-action='modal-backdrop'] input:not([type='checkbox']):not([type='radio']),
    .app-shell [data-action='modal-backdrop'] select {
        min-height: 2.75rem;
        font-size: 0.8125rem;
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='add-appointment-service'],
    .app-shell [data-action='modal-backdrop'] button[data-action='pick-customer'],
    .app-shell [data-action='modal-backdrop'] button[data-action='quick-add-customer'] {
        min-height: 3rem;
        font-size: 0.8125rem;
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='redeem-referral-balance'],
    .app-shell [data-action='modal-backdrop'] button[data-action='redeem-referral-balance-on-appointment'],
    .app-shell [data-action='modal-backdrop'] button[data-action='redeem-reward'] {
        min-height: 2.75rem;
        font-size: 0.8125rem;
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='replay-tutorial'] {
        min-height: 3.25rem;
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='copy-booking-link'],
    .app-shell [data-action='modal-backdrop'] button[data-action='toggle-booking-qr'],
    .app-shell [data-action='modal-backdrop'] div.grid a {
        min-height: 2.75rem;
        font-size: 0.75rem;
    }
    .app-shell [data-action='modal-backdrop'] button[data-action='copy-referral-code'],
    .app-shell [data-action='modal-backdrop'] button[data-action='generate-referral-code'] {
        min-height: var(--btn-min-h);
        padding: 0.625rem 1rem;
        font-size: 0.75rem;
    }

    /* --- 16. Body-level dialogs (tour, info, exit — outside #app) -- */
    body > div[role='dialog'] button {
        min-height: var(--btn-min-h);
    }
    body > div[role='dialog'] button[data-tutorial-action='skip']:has(svg.lucide:only-child),
    body > div[role='dialog'] button[data-tutorial-action='skip']:has(i[data-lucide]:only-child) {
        min-width: var(--btn-icon);
    }
}
