/* ============================================================
   Sunset Resort PMS — Main Stylesheet
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.hidden { display: none !important; }

:root {
    --bg:         #f4f6fa;
    --surface:    #ffffff;
    --border:     #e2e8f0;
    --border-mid: #cbd5e1;
    --text:       #1e293b;
    --text-mid:   #475569;
    --text-light: #94a3b8;
    --accent:     #2563eb;
    --accent-h:   #1d4ed8;
    --accent-bg:  #eff6ff;
    --green:      #16a34a;
    --green-bg:   #f0fdf4;
    --red:        #dc2626;
    --red-bg:     #fef2f2;
    --yellow:     #d97706;
    --yellow-bg:  #fffbeb;
    --radius:     8px;
    --radius-lg:  12px;
    --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
    --sidebar-w:  240px;
    --font:       'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Layout ───────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--text);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}
.sidebar-brand {
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    background: #fff;
}
.brand-logo {
    width: 36px; height: 36px; border-radius: 8px;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.brand-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.brand-sub  { font-size: 11px; color: rgba(255,255,255,.45); margin-top: 2px; }
.sidebar-logo        { width: 180px; max-width: 100%; height: auto; aspect-ratio: 188 / 68; display: block; }
.sidebar-logo-mobile { display: none; width: 40px; max-width: 100%; height: auto; aspect-ratio: 70 / 25; }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section {
    font-size: 10px; font-weight: 600; letter-spacing: .08em;
    color: rgba(255,255,255,.35);
    padding: 14px 18px 4px;
    text-transform: uppercase;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 18px;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    font-size: 13.5px; font-weight: 400;
    transition: all .15s;
    border-left: 3px solid transparent;
}
.nav-item:hover  { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: rgba(37,99,235,.35); border-left-color: var(--accent); }
.nav-icon { width: 18px; text-align: center; font-size: 14px; }

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; color: #fff; }
.user-role { font-size: 11px; color: rgba(255,255,255,.4); }
.btn-logout {
    display: block; width: 100%; text-align: center;
    padding: 7px; border-radius: var(--radius);
    background: rgba(255,255,255,.08); color: rgba(255,255,255,.6);
    text-decoration: none; font-size: 12.5px;
    transition: all .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── Main ─────────────────────────────────────────────────── */
.main    { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.content { padding: 28px; }

/* A dialog that stops at the navigation instead of covering it. The user's call: one spilling
   over the menu makes the whole app feel replaced, when all that happened is that a panel opened.
   It starts where .main starts, so both read the same definition of "where the content area
   begins" — and see the max-width:768px block below for the phone, where the sidebar is a drawer
   and there is nothing to leave room for.
   ⚠ The element carries only `display` inline (the script toggles it); everything else is here,
   because an inline `inset:0` would outrank this rule and the offset would never apply. */
.modal-beside-nav {
    position: fixed;
    top: 0; right: 0; bottom: 0; left: var(--sidebar-w);
    background: rgba(0,0,0,.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

/* ── Flash messages ───────────────────────────────────────── */
.flash {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px; font-size: 13.5px; font-weight: 500;
}
.flash-success { background: var(--green-bg); color: var(--green); border-bottom: 1px solid #bbf7d0; }
.flash-error   { background: var(--red-bg);   color: var(--red);   border-bottom: 1px solid #fecaca; }
.flash-warning { background: var(--yellow-bg);color: var(--yellow);border-bottom: 1px solid #fde68a; }
.flash-close   { background: none; border: none; font-size: 18px; cursor: pointer; color: inherit; opacity: .6; }
.flash-close:hover { opacity: 1; }

/* ── Page header ──────────────────────────────────────────── */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-sub   { font-size: 13px; color: var(--text-light); margin-top: 3px; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.card-body    { padding: 20px; }
.card-header  { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title   { font-size: 15px; font-weight: 600; }
.card-footer  { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ── Stat cards ───────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; color: var(--text-light); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.stat-card.accent { border-top: 3px solid var(--accent); }
.stat-card.green  { border-top: 3px solid var(--green); }
.stat-card.red    { border-top: 3px solid var(--red); }
.stat-card.yellow { border-top: 3px solid var(--yellow); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
    text-align: left; padding: 11px 14px;
    font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-light);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--accent-bg); }
.td-actions { display: flex; gap: 6px; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: 3px 9px; border-radius: 20px;
    font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue   { background: var(--accent-bg); color: var(--accent); }
.badge-gray   { background: #f1f5f9; color: var(--text-mid); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius);
    font-size: 13.5px; font-weight: 500; font-family: var(--font);
    cursor: pointer; border: none; text-decoration: none;
    transition: all .15s; line-height: 1;
}
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--surface); color: var(--text-mid); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-mid); color: var(--text); }
.btn-danger    { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-success   { background: var(--green); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group  { margin-bottom: 16px; }
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
label        { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-mid); margin-bottom: 5px; }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 13.5px; font-family: var(--font); color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11.5px; color: var(--text-light); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--red); margin-top: 4px; }
.form-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.form-section-title { font-size: 13px; font-weight: 600; color: var(--text-mid); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 14px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input[type="checkbox"] { width: auto; }

/* ── Filter bar ───────────────────────────────────────────── */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.filter-bar input, .filter-bar select { width: auto; min-width: 160px; }
.filter-bar .spacer { flex: 1; }

/* ── Pagination ───────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; justify-content: center; padding: 14px 0 0; }
.page-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: var(--radius);
    border: 1px solid var(--border); font-size: 13px; font-weight: 500;
    text-decoration: none; color: var(--text-mid);
    transition: all .15s;
}
.page-link:hover { border-color: var(--accent); color: var(--accent); }
.page-link.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-light); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; }

/* ── Login page ───────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}
.login-card {
    background: #fff; border-radius: var(--radius-lg);
    padding: 40px; width: 380px; max-width: 95vw;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
    text-align: center; margin-bottom: 28px;
}
.login-logo-mark {
    width: 52px; height: 52px; border-radius: 12px;
    background: var(--accent); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 700; margin-bottom: 10px;
}
.login-title { font-size: 20px; font-weight: 700; color: var(--text); }
.login-sub   { font-size: 13px; color: var(--text-light); margin-top: 3px; }
.login-error {
    background: var(--red-bg); color: var(--red);
    border: 1px solid #fecaca; border-radius: var(--radius);
    padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}

/* ── Multi-select filter dropdown (button + checkbox panel) ───────── */
.ms-wrap { position: relative; display: inline-block; vertical-align: middle; }
.ms-btn {
    font: inherit; font-size: 13px; background: #fff;
    border: 1px solid var(--border-mid); border-radius: var(--radius);
    padding: 7px 28px 7px 12px; color: var(--text); cursor: pointer;
    white-space: nowrap; position: relative; min-width: 120px; text-align: left;
}
.ms-btn::after {
    content: '▾'; position: absolute; right: 10px; top: 50%;
    transform: translateY(-50%); color: var(--text-light); font-size: 11px;
}
.ms-btn.ms-active { border-color: var(--accent); color: var(--accent); font-weight: 500; }
.ms-panel {
    position: absolute; z-index: 50; top: calc(100% + 4px); left: 0; min-width: 100%;
    background: #fff; border: 1px solid var(--border-mid); border-radius: var(--radius);
    box-shadow: var(--shadow-md); padding: 6px; max-height: 280px; overflow-y: auto;
}
.ms-opt {
    display: flex; align-items: center; gap: 8px; padding: 5px 8px;
    border-radius: 6px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.ms-opt:hover { background: var(--accent-bg); }
.ms-opt input { width: auto; min-width: auto; margin: 0; cursor: pointer; }

/* PWA install pill — phones only (desktop Chrome also fires beforeinstallprompt) */
@media (min-width: 769px) { #pwa-install-bar { display: none !important; } }

/* ── Mobile top bar + drawer backdrop (shown only on small screens) ── */
.topbar           { display: none; }
.sidebar-backdrop { display: none; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Top bar that holds the hamburger */
    .topbar {
        display: flex; align-items: center; gap: 12px;
        padding: 9px 14px; background: var(--text);
        position: sticky; top: 0; z-index: 90;
    }
    .topbar-toggle {
        display: flex; align-items: center; justify-content: center;
        width: 40px; height: 40px; flex-shrink: 0;
        background: rgba(255,255,255,.1); border: none; border-radius: var(--radius);
        color: #fff; font-size: 18px; cursor: pointer;
    }
    .topbar-brand     { display: inline-flex; }
    .topbar-brand img { display: block; height: 26px; width: auto; }

    /* Sidebar slides in as a drawer over the content */
    .sidebar {
        width: 264px; max-width: 84vw;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 0 0 40px rgba(0,0,0,.45);
    }
    body.nav-open .sidebar { transform: translateX(0); }

    .sidebar-backdrop {
        position: fixed; inset: 0; z-index: 95;
        background: rgba(0,0,0,.5);
    }
    body.nav-open .sidebar-backdrop { display: block; }

    /* Content reclaims the full width */
    .main        { margin-left: 0; }
    /* …and so does the email preview: on a phone the sidebar is a drawer that is
       off-canvas until opened, so there is nothing to leave room for. */
    .modal-beside-nav { left: 0; }
    .content     { padding: 16px; }
    .page-header { flex-wrap: wrap; gap: 12px; }
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .stat-grid   { grid-template-columns: 1fr 1fr; }

    /* Stack any inline multi-column grid (dossier two-column layouts, detail
       forms) into one column on phones. Mobile-only — desktop grids untouched. */
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
    /* Let grid children shrink to the column instead of forcing the page wider
       than the phone (default grid min-width:auto causes a slight overflow). */
    [style*="grid-template-columns"] > * { min-width: 0; }

    /* Hide secondary table columns on phones (cells marked .hide-sm) */
    .hide-sm { display: none !important; }

    /* Data tables → stacked "label: value" cards (opt in with .cards-sm).
       Header text is copied onto each cell as data-label by a small script. */
    table.cards-sm thead { display: none; }
    table.cards-sm tbody,
    table.cards-sm tr,
    table.cards-sm td { display: block; width: auto; }
    table.cards-sm tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow);
        margin-bottom: 12px;
        padding: 4px 2px;
    }
    table.cards-sm td {
        padding: 6px 14px;
        border: none;
        border-bottom: 1px solid var(--border);
        text-align: left !important;
        white-space: normal !important;
    }
    table.cards-sm tr td:last-child { border-bottom: none; }
    table.cards-sm td::before {
        content: attr(data-label);
        display: block; margin-bottom: 2px;
        font-size: 10.5px; font-weight: 600;
        text-transform: uppercase; letter-spacing: .04em;
        color: var(--text-light);
    }
    table.cards-sm td[data-label='']::before { content: none; }
    table.cards-sm tbody tr:hover td { background: transparent; }

    /* Filter bars stack full-width on phones — each field on its own line (its
       label sits just above it), buttons grow to share rows. Bigger, clearer
       touch targets, never horizontally squeezed. The !important overrides the
       inline width:auto some filters set on their inputs. Desktop untouched. */
    .filter-bar > label { flex: 1 1 100%; margin: 2px 0 -4px; }
    .filter-bar > input,
    .filter-bar > select,
    .filter-bar .ms-wrap { flex: 1 1 100%; width: 100% !important; min-width: 0; display: block; }
    .filter-bar .ms-btn { width: 100%; min-width: 0; }
    .filter-bar .spacer { display: none; }
    .filter-bar > .btn { flex: 1 1 auto; }
}
