/* ==========================================================================
   Recordatio - Mobile-first stylesheet
   --------------------------------------------------------------------------
   Design approach (user-centric, mobile-first):
   1. Styles are written for small screens (phones) FIRST. Larger breakpoints
      (tablet >= 700px, desktop >= 1024px) progressively ENHANCE the layout
      using min-width media queries, instead of the old approach of designing
      for desktop and squeezing things down.
   2. Every interactive element (links, buttons, checkboxes, form fields)
      respects a minimum touch target of ~44x44px, per WCAG / mobile HIG
      guidance, so it's comfortable to tap on a phone/tablet.
   3. Form inputs use font-size: 16px (or larger) to prevent iOS Safari from
      automatically zooming in when a field is focused.
   4. Data tables collapse into stacked "cards" on narrow screens (see the
      ".table-responsive" rules) so users don't have to scroll horizontally
      to read appointment/client/reminder data on a phone.
   5. The top navigation collapses into a hamburger-triggered menu below the
      tablet breakpoint, and expands into a normal horizontal bar on larger
      screens (see nav.js for the toggle behaviour).
   ========================================================================== */

/* -------------------------------------------------------------------------
   0. CSS variables - central place to tweak the theme
   ------------------------------------------------------------------------- */
:root {
    --color-brand: #1FA855;        /* WhatsApp-inspired green, slightly deeper for better contrast on white text */
    --color-brand-dark: #178443;
    --color-brand-light: #e8f7ee;  /* tint for subtle highlights/active states */
    --color-text: #1c1e21;
    --color-muted: #6b7280;
    --color-bg: #f6f7f8;
    --color-card-bg: #fff;
    --color-border: #e2e4e8;
    --color-secondary: #6c757d;
    --color-secondary-dark: #565e64;
    --color-danger: #d64545;
    --color-danger-dark: #b53838;
    --radius: 10px;
    --radius-sm: 6px;
    --spacing-1: 0.5rem;
    --spacing-2: 1rem;
    --spacing-3: 1.5rem;
    --spacing-4: 2rem;
    --touch-target: 44px; /* minimum comfortable tap size */
    --shadow-card: 0 1px 3px rgba(20, 20, 30, 0.06), 0 1px 2px rgba(20, 20, 30, 0.04);
}

/* -------------------------------------------------------------------------
   1. Reset & base (mobile-first defaults)
   ------------------------------------------------------------------------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* Prevents the classic mobile-browser "text auto-resize" surprise */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    /* Fluid base font size: never smaller than 15px, never larger than 16px */
    font-size: clamp(15px, 2.5vw, 16px);
}

a {
    color: var(--color-brand-dark);
}

/* Consistent, visible focus ring for keyboard/assistive-tech users across
   links, buttons and form controls (native outlines vary wildly by browser). */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-brand-dark);
    outline-offset: 2px;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    /* Small horizontal padding on phones so content doesn't touch the edges */
    padding: 0 var(--spacing-2);
}

/* -------------------------------------------------------------------------
   2. Header & responsive navigation
   ------------------------------------------------------------------------- */
.header {
    background: var(--color-brand);
    color: #fff;
    padding: var(--spacing-2) 0;
    margin-bottom: var(--spacing-3);
}

.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-2);
}

.header h1 {
    font-size: 1.15rem;
    line-height: 1.3;
    /* Keep long business names from wrapping the header into 3 lines on phones */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header .brand {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.75;
    margin-bottom: 0.1rem;
}

.brand-logo {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    background: #fff;
    padding: 2px;
    vertical-align: -3px;
}

/* Hamburger button: only meaningful/visible on small screens */
.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target);
    height: var(--touch-target);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    flex-shrink: 0;
}

/* Groups the clock and hamburger together on the right so the layout stays
   a simple two-item flex (title on the left, everything else on the right)
   regardless of viewport width. */
.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    flex-shrink: 0;
}

/* Running clock (see clock.js): kept compact and secondary in weight/size
   so it stays "large and visible" without competing with the business name
   for attention. font-variant-numeric keeps the digits from jittering the
   layout width as seconds tick over. */
.header-clock {
    text-align: right;
    line-height: 1.15;
}

.header-clock__time {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.header-clock__date {
    display: block;
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: capitalize;
    opacity: 0.8;
    white-space: nowrap;
}

.header-clock__tier {
    display: inline-block;
    margin-top: 0.2rem;
    padding: 0.1rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
    color: #fff;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 999px;
}

.support-banner {
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #664d03;
    background: #fff3cd;
    border-bottom: 1px solid #ffe69c;
}

.support-banner a {
    color: #664d03;
    text-decoration: underline;
}

.usage-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    margin-bottom: var(--spacing-3);
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 1px solid transparent;
}

/* The banner sits flush against the header (no gray body background
   showing through the gap) - move .header's normal bottom margin onto
   the banner itself instead, only when a banner is actually present. */
.header:has(+ .usage-banner) {
    margin-bottom: 0;
}

.usage-banner__icon {
    font-size: 1.1rem;
    line-height: 1;
}

.usage-banner--yellow {
    color: #664d03;
    background: #fff3cd;
    border-bottom-color: #ffe69c;
}

.usage-banner--orange {
    color: #7a3b00;
    background: #ffe1b3;
    border-bottom-color: #ffc266;
}

.usage-banner--red {
    color: #ffffff;
    background: #c0392b;
    border-bottom-color: #922b21;
}

.usage-banner--red a {
    color: #ffffff;
    text-decoration: underline;
    font-weight: 700;
}

.header-employee-badge {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.1rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #fff;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    vertical-align: middle;
}

.nav-toggle:hover,
.nav-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.3);
}

/* Mobile nav: hidden by default, expands as a full-width dropdown */
.nav {
    display: none;
    flex-direction: column;
    gap: var(--spacing-1);
    margin-top: var(--spacing-2);
    width: 100%;
}

.nav.is-open {
    display: flex;
}

.nav a {
    color: #fff;
    text-decoration: none;
    padding: var(--spacing-1) var(--spacing-2);
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
}

.nav a:hover,
.nav a:focus-visible {
    background: rgba(255, 255, 255, 0.3);
}

/* Highlights the current section so users always know where they are */
.nav a.is-active {
    background: #fff;
    color: var(--color-brand-dark);
    font-weight: 600;
}

.nav a.is-active:hover,
.nav a.is-active:focus-visible {
    background: #fff;
}

/* Tablet and up: show the nav inline and hide the hamburger */
@media (min-width: 700px) {
    .nav-toggle {
        display: none;
    }

    .header-bar {
        flex-wrap: wrap;
    }

    .nav {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        width: auto;
        margin-top: 0;
    }

    .nav a {
        min-height: auto;
    }

    .header h1 {
        font-size: 1.5rem;
        white-space: normal;
    }

    /* More breathing room on tablet/desktop, so the clock can be genuinely
       "large and visible" without crowding the business name or nav. */
    .header-clock__time {
        font-size: 1.75rem;
    }

    .header-clock__date {
        font-size: 0.85rem;
    }
}

/* -------------------------------------------------------------------------
   3. Cards, messages, generic layout helpers
   ------------------------------------------------------------------------- */
.card {
    background: var(--color-card-bg);
    padding: var(--spacing-2);
    margin-bottom: var(--spacing-3);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--color-border);
}

@media (min-width: 700px) {
    .card {
        padding: var(--spacing-4);
    }
}

.card-narrow {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.messages {
    margin-bottom: var(--spacing-2);
}

.message {
    padding: var(--spacing-2);
    margin-bottom: var(--spacing-1);
    border-radius: 6px;
}

.message.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.message.error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.message.warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

.text-muted { color: var(--color-muted); }
.text-center { text-align: center; }

.empty-state {
    color: var(--color-muted);
    text-align: center;
    padding: var(--spacing-4) var(--spacing-2);
}

.empty-state .empty-state-icon {
    display: block;
    font-size: 2rem;
    margin-bottom: var(--spacing-1);
    opacity: 0.8;
}

/* -------------------------------------------------------------------------
   3b. Quick-glance stat cards (dashboard)
   ------------------------------------------------------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-2);
    margin-bottom: var(--spacing-3);
}

@media (min-width: 480px) {
    .stat-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.stat-card {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--spacing-2);
    box-shadow: var(--shadow-card);
    border-left: 4px solid var(--color-brand);
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-text);
}

.stat-card .stat-label {
    color: var(--color-muted);
    font-size: 0.85rem;
}

/* Generic flex helpers, replacing scattered inline styles */
.stack {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-1);
}

.toolbar {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
    margin-bottom: var(--spacing-2);
}

@media (min-width: 700px) {
    .toolbar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
    margin-top: var(--spacing-2);
}

@media (min-width: 480px) {
    .form-actions {
        flex-direction: row;
    }
}

.note-box {
    padding: var(--spacing-2);
    border-radius: 6px;
    margin-bottom: var(--spacing-3);
}

.note-box--info { background: #e7f3ff; }
.note-box--warning { background: #fff3cd; border: 1px solid #ffeeba; color: #856404; }
.note-box--muted { background: #f8f9fa; border: 1px solid #dee2e6; }

/* -------------------------------------------------------------------------
   4. Forms - touch-friendly, full-width on phones
   ------------------------------------------------------------------------- */
.form-group {
    margin-bottom: var(--spacing-2);
    position: relative; /* anchors the client-search dropdown, see forms.js */
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-1);
    font-weight: bold;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--spacing-1) 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    /* 16px stops iOS Safari from zooming the page in on focus */
    font-size: 16px;
    min-height: var(--touch-target);
    font-family: inherit;
}

.form-group input[type="checkbox"] {
    width: auto;
    min-height: auto;
    /* Larger checkbox hit-area for touch, without changing the visual size much */
    width: 1.25rem;
    height: 1.25rem;
    margin-right: var(--spacing-1);
}

.checkbox-row {
    display: flex;
    align-items: center;
    font-weight: normal;
    /* Ensures the whole row (not just the tiny checkbox) is tappable */
    min-height: var(--touch-target);
    padding: var(--spacing-1) 0;
}

/* Time picker: pre-defined slot chips, used on every screen size (the
   native <input type="time"> picker is inconvenient on many mobile
   browsers, so we use one consistent widget everywhere instead of
   switching between desktop/mobile pickers). Kept in sync with a hidden
   field via appointment_form.html's inline script. */
.time-picker-chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
    gap: var(--spacing-1);
    max-height: 14rem;
    overflow-y: auto;
    padding: var(--spacing-1);
    border: 1px solid var(--color-border);
    border-radius: 6px;
}

.time-chip {
    padding: 0.6rem 0.25rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: #fff;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
    cursor: pointer;
    min-height: var(--touch-target);
}

.time-chip.is-selected {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: #fff;
    font-weight: 700;
}

@media (min-width: 700px) {
    .time-picker-chips {
        grid-template-columns: repeat(auto-fill, minmax(5rem, 1fr));
        max-height: 18rem;
    }
}

/* Slot-count hint: fades/slides in beneath the time-slot chips when there
   are already appointments at the selected date/time. Reuses the app's
   existing warning color language (see .note-box--warning) so it reads as
   an attention-worthy notice rather than plain muted text, without
   introducing a new visual style. Stays visible until the date or time
   selection changes. */
.slot-count-hint {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.6rem;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    background: #fff3cd;
    border: 1px solid #ffeeba;
    color: #856404;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.slot-count-hint.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Channel selector: WhatsApp vs SMS radio chips for appointment
   create/edit forms. */
.channel-selector {
    display: flex;
    gap: var(--spacing-2);
    flex-wrap: wrap;
}

.channel-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    min-height: var(--touch-target);
}

.channel-option:has(input:checked) {
    border-color: var(--color-brand);
    background: color-mix(in srgb, var(--color-brand) 10%, #fff);
    font-weight: 700;
}

/* -------------------------------------------------------------------------
   5. Buttons
   ------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    background: var(--color-brand);
    color: #fff;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    min-height: var(--touch-target);
    text-align: center;
    transition: background-color 0.15s ease;
}

.btn:hover,
.btn:focus-visible {
    background: var(--color-brand-dark);
}

.btn-secondary { background: var(--color-secondary); }
.btn-secondary:hover,
.btn-secondary:focus-visible { background: var(--color-secondary-dark); }

.btn-danger { background: var(--color-danger); }
.btn-danger:hover,
.btn-danger:focus-visible { background: var(--color-danger-dark); }

.btn-sm {
    padding: var(--spacing-1) 0.75rem;
    font-size: 0.875rem;
    min-height: 36px;
}

.btn-block {
    width: 100%;
}

/* On very small phones, stack full-width primary actions for easy tapping */
@media (max-width: 479px) {
    .form-actions .btn {
        width: 100%;
    }
}

/* -------------------------------------------------------------------------
   6. Status badges
   ------------------------------------------------------------------------- */
.status {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: nowrap;
}

.status-scheduled { background: #d1ecf1; color: #0c5460; }
.status-sent { background: #d4edda; color: #155724; }
.status-delivered { background: #d6d8db; color: #383d41; }
.status-read { background: #cce5ff; color: #004085; }
.status-failed { background: #f8d7da; color: #721c24; }
.status-skipped { background: #ffc107; color: #856404; }
.status-cancelled { background: #6c757d; color: #fff; }

/* -------------------------------------------------------------------------
   7. Responsive tables -> stacked cards on narrow screens
   --------------------------------------------------------------------------
   Usage: wrap the <table> in <div class="table-responsive"> and add a
   data-label="Column name" attribute to each <td>. Below 700px, the table
   loses its tabular layout and each <tr> becomes a small card where every
   cell shows its own label, so nothing needs to scroll horizontally.
   ------------------------------------------------------------------------- */
.table-responsive table {
    width: 100%;
    border-collapse: collapse;
}

.table-responsive th,
.table-responsive td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table-responsive th { background: #f8f9fa; font-weight: bold; }

@media (max-width: 699px) {
    .table-responsive thead {
        display: none; /* headers are replaced by per-cell data-label text */
    }

    .table-responsive table,
    .table-responsive tbody,
    .table-responsive tr,
    .table-responsive td {
        display: block;
        width: 100%;
    }

    .table-responsive tr {
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        margin-bottom: var(--spacing-2);
        padding: var(--spacing-1) var(--spacing-2);
        background: var(--color-card-bg);
    }

    .table-responsive td {
        border-bottom: none;
        padding: 0.5rem 0;
        display: flex;
        flex-direction: column;
        gap: 0.15rem;
    }

    /* The label is injected via the data-label attribute set in the template */
    .table-responsive td[data-label]::before {
        content: attr(data-label);
        font-size: 0.75rem;
        font-weight: bold;
        text-transform: uppercase;
        color: var(--color-muted);
    }

    .table-responsive td:empty {
        display: none;
    }
}

/* -------------------------------------------------------------------------
   8. Client search dropdown (used on the appointment form)
   ------------------------------------------------------------------------- */
.client-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--color-border);
    border-top: none;
    max-height: 60vh; /* keeps the list usable on short mobile viewports */
    overflow-y: auto;
    display: none;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 0 0 6px 6px;
}

.client-search-results.active {
    display: block;
}

.client-result {
    padding: var(--spacing-2);
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-1);
    min-height: var(--touch-target);
}

.client-result:hover,
.client-result:focus-visible {
    background: #f8f9fa;
}

.client-result:last-child {
    border-bottom: none;
}

.no-results {
    padding: var(--spacing-2);
    color: var(--color-muted);
    text-align: center;
}

#client_search.has-selection {
    background-color: #d4edda;
    border-color: var(--color-brand);
}

/* -------------------------------------------------------------------------
   9. Login page
   ------------------------------------------------------------------------- */
.login-card {
    max-width: 400px;
    margin: var(--spacing-3) auto;
}

@media (min-width: 700px) {
    .login-card {
        margin: 4rem auto;
    }
}

/* -------------------------------------------------------------------------
   9. Support business switcher
   ------------------------------------------------------------------------- */
.support-business-search {
    position: relative;
    margin-bottom: 1.25rem;
}

.support-business-search-icon {
    position: absolute;
    left: 0.9rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    pointer-events: none;
}

.support-business-search input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
}

.support-business-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-height: 3rem;
    transition: opacity 0.15s ease;
}

.support-business-list.is-loading {
    opacity: 0.5;
}

.support-business-row {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-card-bg);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.support-business-row:hover {
    box-shadow: var(--shadow-card);
    border-color: var(--color-brand);
}

.support-business-avatar {
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: var(--color-brand-light);
    color: var(--color-brand-dark);
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.support-business-info {
    flex: 1;
    min-width: 0;
}

.support-business-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.support-business-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.15rem;
    font-size: 0.8rem;
    color: var(--color-muted);
}

.support-business-id {
    font-family: monospace;
}

.support-business-tier {
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    background: var(--color-brand-light);
    color: var(--color-brand-dark);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
}

.support-business-action {
    flex-shrink: 0;
    margin: 0;
}

.support-business-empty {
    padding: var(--spacing-3);
    text-align: center;
    color: var(--color-muted);
}

