/* ==========================================================================
   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: #25D366;        /* WhatsApp green, matches the messaging theme */
    --color-brand-dark: #1ea952;
    --color-text: #222;
    --color-muted: #666;
    --color-bg: #f4f4f4;
    --color-card-bg: #fff;
    --color-border: #ddd;
    --color-secondary: #6c757d;
    --color-secondary-dark: #565e64;
    --radius: 8px;
    --spacing-1: 0.5rem;
    --spacing-2: 1rem;
    --spacing-3: 1.5rem;
    --spacing-4: 2rem;
    --touch-target: 44px; /* minimum comfortable tap size */
}

/* -------------------------------------------------------------------------
   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);
}

.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;
}

/* 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;
}

.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);
}

/* 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;
    }
}

/* -------------------------------------------------------------------------
   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: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@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);
}

/* 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;
}

/* -------------------------------------------------------------------------
   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: 6px;
    cursor: pointer;
    font-size: 1rem;
    min-height: var(--touch-target);
    text-align: center;
}

.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-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-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;
    }
}
