/* Pistasol design system — shared across every view. Keep page-specific
   CSS out of individual view files; add reusable patterns here instead. */

:root {
    --color-bg: #f4f6fa;
    --color-surface: #ffffff;
    --color-border: #e2e5eb;
    --color-border-strong: #cbd2e0;
    --color-text: #171b26;
    --color-text-muted: #656d80;
    --color-primary: #142449;
    --color-primary-hover: #1f3468;
    --color-accent: #0d9488;
    --color-accent-hover: #0b7f74;
    --color-success: #15803d;
    --color-success-bg: #e9f9ee;
    --color-success-border: #86e0a8;
    --color-error: #b91c1c;
    --color-error-bg: #fdecec;
    --color-error-border: #f3a6a6;
    --color-warning: #b45309;
    --color-warning-bg: #fef3e0;
    --radius-sm: 6px;
    --radius-md: 10px;
    --shadow-sm: 0 1px 2px rgba(20, 36, 73, 0.06);
    --shadow-md: 0 6px 20px rgba(20, 36, 73, 0.08);
    --sidebar-width: 232px;
    --topbar-height: 60px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 4px; color: var(--color-primary); }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-top: 28px; }
p { margin: 6px 0 0; color: var(--color-text-muted); }
a { color: var(--color-accent); }

/* ---------- App shell ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-primary);
    color: #cfd7ec;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    font-weight: 700;
    font-size: 17px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .logo-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 0 4px rgba(13,148,136,0.25);
}

.sidebar-nav { padding: 14px 10px; flex: 1; }
.sidebar-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #8993b5;
    padding: 16px 10px 6px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    margin: 1px 0;
    border-radius: var(--radius-sm);
    color: #cfd7ec;
    text-decoration: none;
    font-size: 14px;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav a.active { background: var(--color-accent); color: #fff; font-weight: 600; }
.sidebar-nav .icon { width: 16px; text-align: center; opacity: 0.85; flex-shrink: 0; }

.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar-location {
    display: flex; align-items: center; gap: 7px;
    background: var(--color-bg); border: 1px solid var(--color-border);
    border-radius: 999px; padding: 5px 12px 5px 10px;
    color: var(--color-primary);
}
.topbar-location .icon { color: var(--color-accent); flex-shrink: 0; }
.topbar-location-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); font-weight: 600; }
.topbar-location select {
    margin: 0; max-width: 220px; font-size: 13px; padding: 2px 4px;
    border: none; background: transparent; font-weight: 700; color: var(--color-primary); cursor: pointer;
}
.topbar-location select:focus { box-shadow: none; outline: 2px solid var(--color-accent); border-radius: 4px; }
.topbar-location--switchable { border-color: var(--color-accent); }
.topbar-spacer { flex: 1; }
.topbar-user { font-size: 13px; color: var(--color-text-muted); display: flex; align-items: center; gap: 12px; }
.topbar-user strong { color: var(--color-text); }
.topbar-user a { color: var(--color-text-muted); text-decoration: none; }
.topbar-user a:hover { color: var(--color-error); }
.topbar-location-badge {
    font-size: 13px; font-weight: 700; color: var(--color-primary);
}

main.content { padding: 24px 28px 48px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------- Flash messages ---------- */

.flash-success, .flash-error {
    padding: 11px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    border: 1px solid;
}
.flash-success { background: var(--color-success-bg); border-color: var(--color-success-border); color: var(--color-success); }
.flash-error { background: var(--color-error-bg); border-color: var(--color-error-border); color: var(--color-error); }
.flash-error ul { margin: 4px 0 0 18px; padding: 0; }

/* ---------- Cards / sections ---------- */

.callout-warning {
    background: var(--color-warning-bg);
    border-color: #f0d29b;
    font-size: 14px;
}
.callout-warning a { color: var(--color-warning); font-weight: 600; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 20px 22px;
    margin-bottom: 20px;
}
.card + .card { margin-top: 0; }
.card-header {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.card-header h2, .card-header h3 { margin: 0; }

.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Stat cards (dashboard) ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; color: var(--color-primary); margin-top: 4px; }
.stat-card .stat-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }

/* ---------- Tables ---------- */

table { border-collapse: collapse; width: 100%; background: var(--color-surface); font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--color-border); }
th {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--color-text-muted); font-weight: 600; background: #fafbfd;
}
tbody tr:hover { background: #fafbfe; }
td .row-actions { display: flex; gap: 12px; align-items: center; }
td .row-actions a { text-decoration: none; }
.link-danger { background: none; border: none; color: var(--color-error); cursor: pointer; padding: 0; font-size: 14px; }
.link-danger:hover { text-decoration: underline; }
.link-secondary { background: none; border: none; color: var(--color-primary); cursor: pointer; padding: 0; font-size: 14px; }
.link-secondary:hover { text-decoration: underline; }

.rule-drag-handle { display: inline-flex; cursor: grab; color: var(--color-text-muted); padding: 4px; }
.rule-drag-handle:active { cursor: grabbing; }
tr.rule-row.dragging { opacity: 0.4; }
.empty-row { color: var(--color-text-muted); font-style: italic; text-align: center; padding: 24px; }

.pager-bar { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 14px 0 2px; font-size: 13px; color: var(--color-text-muted); }
.pager-bar a { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.pager-bar a:hover { text-decoration: underline; }

.item-thumb {
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    object-fit: cover; background: var(--color-bg); border: 1px solid var(--color-border);
    display: block;
}
.item-thumb-placeholder {
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    background: var(--color-bg); border: 1px dashed var(--color-border-strong);
    display: flex; align-items: center; justify-content: center;
    color: var(--color-text-muted); font-size: 10px;
}
.item-thumb-large {
    width: 140px; height: 140px; border-radius: var(--radius-md);
    object-fit: cover; background: var(--color-bg); border: 1px solid var(--color-border);
    display: block; margin-bottom: 10px;
}

/* ---------- Badges ---------- */

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-pending_payment { background: #f3e8ff; color: #9333ea; }
.badge-booked { background: #e6effe; color: #1d4ed8; }
.badge-checked_in, .badge-started { background: #fef3e0; color: var(--color-warning); }
.badge-completed, .badge-closed { background: #ede9fe; color: #6d28d9; }
.badge-paid { background: var(--color-success-bg); color: var(--color-success); }
.badge-cancelled { background: var(--color-error-bg); color: var(--color-error); }
.badge-no_show { background: #f1f2f6; color: var(--color-text-muted); }
.badge-neutral { background: #f1f2f6; color: var(--color-text-muted); }
.badge-info { background: #e6effe; color: #1d4ed8; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    background: var(--color-primary);
    color: #fff;
    text-decoration: none;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
}
.btn:hover { background: var(--color-primary-hover); }
.btn-accent { background: var(--color-accent); }
.btn-accent:hover { background: var(--color-accent-hover); }
.btn-danger { background: var(--color-error); }
.btn-danger:hover { background: #991b1b; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
form.inline { display: inline; }

/* ---------- Forms ---------- */

label { display: block; margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--color-text); }
label.label-checkbox {
    font-weight: normal; display: flex; align-items: center; gap: 8px; margin-top: 12px;
}
.field-hint { display: block; font-weight: 400; color: var(--color-text-muted); font-size: 12px; margin-top: 2px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=datetime-local], select, textarea {
    width: 100%; max-width: 420px; padding: 8px 10px; margin-top: 5px;
    border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
    box-sizing: border-box; font-size: 14px; font-family: inherit;
    background: var(--color-surface); color: var(--color-text);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(13,148,136,0.15);
}
input[type=checkbox] { width: auto; margin: 0; }

.checkbox-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 4px 16px; margin-top: 6px; max-width: 640px;
}
.form-actions { margin-top: 20px; }

/* Searchable dropdown (member search on booking/POS creation, etc.) */
.field-combobox { position: relative; max-width: 420px; }
.search-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-sm); margin-top: 4px; max-height: 240px;
    overflow-y: auto; box-shadow: var(--shadow-md);
}
.search-dropdown-item {
    padding: 8px 12px; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.search-dropdown-item:hover, .search-dropdown-item.active { background: var(--color-bg); }
.search-dropdown-item .name { font-weight: 600; color: var(--color-text); }
.search-dropdown-item .phone { color: var(--color-text-muted); font-size: 13px; white-space: nowrap; }
.search-dropdown-empty { padding: 8px 12px; color: var(--color-text-muted); font-size: 13px; }

/* Custom 24-hour date/time pickers (booking start/end date & time) */
.picker-wrap { position: relative; display: flex; align-items: stretch; gap: 6px; max-width: 420px; margin-top: 5px; }
.picker-wrap input[type=text] { flex: 1; margin-top: 0; max-width: none; }
.picker-toggle {
    flex-shrink: 0; width: 38px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
    background: var(--color-surface); cursor: pointer; font-size: 16px; line-height: 1;
}
.picker-toggle:hover:not(:disabled) { background: var(--color-bg); }
.picker-toggle:disabled { opacity: 0.5; cursor: not-allowed; }
.picker-panel {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-md); padding: 10px;
}
.picker-cal-header { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 8px; gap: 10px; color: var(--color-text); }
.picker-cal-nav { border: none; background: none; cursor: pointer; font-size: 14px; padding: 2px 8px; border-radius: 4px; color: var(--color-text); }
.picker-cal-nav:hover { background: var(--color-bg); }
.picker-cal-grid { display: grid; grid-template-columns: repeat(7, 28px); gap: 2px; }
.picker-cal-dow { font-size: 10px; color: var(--color-text-muted); text-align: center; font-weight: 600; }
.picker-cal-day { font-size: 12px; text-align: center; padding: 5px 0; border-radius: 4px; cursor: pointer; color: var(--color-text); }
.picker-cal-day:hover { background: var(--color-bg); }
.picker-cal-day.selected { background: var(--color-accent); color: #fff; font-weight: 600; }
.picker-time-columns { display: flex; gap: 6px; }
.picker-time-col { max-height: 180px; overflow-y: auto; width: 50px; }
.picker-time-item { font-size: 13px; text-align: center; padding: 5px 0; border-radius: 4px; cursor: pointer; color: var(--color-text); }
.picker-time-item:hover { background: var(--color-bg); }
.picker-time-item.selected { background: var(--color-accent); color: #fff; font-weight: 600; }

fieldset { border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 12px 14px; margin-top: 14px; }

/* flatpickr (booking date fields) — swap the library's default blue for the app's accent */
.flatpickr-day.selected, .flatpickr-day.selected:hover,
.flatpickr-day.startRange, .flatpickr-day.endRange {
    background: var(--color-accent); border-color: var(--color-accent);
}
.flatpickr-day.today { border-color: var(--color-accent); }
.flatpickr-months .flatpickr-month, .flatpickr-current-month .flatpickr-monthDropdown-months {
    color: var(--color-primary);
}
.flatpickr-day:hover { background: var(--color-bg); }
legend { padding: 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); font-weight: 600; }

/* ---------- Receipt ---------- */

.receipt-paper {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    max-width: 380px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
    white-space: pre-wrap;
    box-shadow: var(--shadow-sm);
}

/* ---------- Detail rows (booking show, etc.) ---------- */

.detail-table th { width: 180px; background: var(--color-surface); text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--color-text-muted); font-weight: 600; }
.detail-table td { font-size: 14px; }

/* ---------- Login ---------- */

.login-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, var(--color-primary), #0b1730);
    padding: 20px;
}
.login-card {
    background: var(--color-surface); border-radius: var(--radius-md);
    padding: 36px 34px; width: 100%; max-width: 360px; box-shadow: var(--shadow-md);
}
.login-card .sidebar-brand { padding: 0 0 20px; border: none; color: var(--color-primary); justify-content: center; }
.login-card .sidebar-brand .logo-dot { }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; }
    .sidebar-brand { display: none; }
    .sidebar-nav { display: flex; gap: 4px; padding: 8px; flex: none; white-space: nowrap; }
    .sidebar-section-label { display: none; }
    .sidebar-nav a { white-space: nowrap; }
    main.content { padding: 16px; }
    .topbar { padding: 0 16px; flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; }
}
