/* Meridian — design tokens and component styles. A single palette change here
   re-themes the whole app. Deep ink/charcoal + champagne gold: professional,
   mature, no primary-blue or playful accents. */

:root {
    --ink: #12151b;
    --ink-2: #1b1f27;
    --ink-3: #262b35;
    --gold: #c6a15b;
    --gold-deep: #9c7c3e;
    --gold-soft: #f1e6cf;
    --paper: #f7f5f0;
    --surface: #ffffff;
    --surface-2: #fbf9f5;
    --text: #201f1c;
    --text-muted: #6b6459;
    --text-faint: #9a9284;
    --border: #e6e1d6;
    --border-strong: #d8d1c0;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-soft: 0 1px 2px rgba(18,21,27,.06), 0 6px 20px rgba(18,21,27,.06);
    --font-sans: 'Inter', -apple-system, 'Segoe UI', Arial, sans-serif;
    --font-serif: 'Playfair Display', Georgia, serif;

    --success: #3f6b4a;      --success-bg: #e8f0e9;
    --warning: #a97325;      --warning-bg: #f6ecda;
    --danger:  #8c3a3a;      --danger-bg:  #f6e6e6;
    --info:    #3a5a78;      --info-bg:    #e8eef3;
    --neutral: #75705f;      --neutral-bg: #ece9df;

    --sidebar-w: 264px;
    --topbar-h: 68px;
}

* { box-sizing: border-box; }

html, body {
    background: var(--paper);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 15px;
}

a { color: var(--gold-deep); text-decoration: none; }
a:hover { color: var(--gold); text-decoration: underline; }

.brand-serif { font-family: var(--font-serif); }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--ink);
    color: #cfc9ba;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 1040;
    transition: transform .25s ease;
}

.sidebar-brand {
    padding: 24px 22px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--ink-3);
    margin-bottom: 4px;
}
.sidebar-logo {
    width: 42px; height: 42px; flex-shrink: 0; border-radius: 11px;
    background: rgba(198,161,91,0.14); border: 1px solid rgba(198,161,91,0.28);
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sidebar-logo span { font-family: var(--font-serif); font-size: 18px; color: var(--gold); }
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.sidebar-brand-text .name {
    font-family: var(--font-serif); font-size: 16.5px; color: var(--gold); letter-spacing: .01em;
    line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-brand-text .tagline {
    font-size: 10.5px; color: #837d6c; text-transform: uppercase; letter-spacing: .06em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 12px 16px; }
.sidebar-group { margin-top: 18px; }
.sidebar-group:first-child { margin-top: 0; }
.sidebar-group-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #726c5c;
    padding: 0 12px 6px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #c7c1b2;
    font-size: 14px;
    margin-bottom: 2px;
}
.sidebar-link i { font-size: 16px; width: 18px; text-align: center; color: #8f8a7b; }
.sidebar-link:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.sidebar-link.is-active { background: var(--ink-2); color: #fff; }
.sidebar-link.is-active i { color: var(--gold); }
.sidebar-link.is-active { box-shadow: inset 3px 0 0 var(--gold); }

.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid var(--ink-3);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--ink-3); color: var(--gold);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; flex-shrink: 0; overflow: hidden;
}
.sidebar-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user-name { font-size: 13px; color: #eae5d8; line-height: 1.2; }
.sidebar-user-role { font-size: 11px; color: #837d6c; text-transform: capitalize; }
.sidebar-logout { margin-left: auto; color: #8f8a7b; font-size: 16px; }
.sidebar-logout:hover { color: var(--gold); }

.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(18,21,27,.5);
    z-index: 1030; display: none;
}

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.topbar-title { font-size: 18px; font-weight: 600; margin: 0; flex: 1; min-width: 0; }
.topbar-title .sub { font-size: 12px; color: var(--text-muted); font-weight: 400; display: block; }
.topbar-clock { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.sidebar-toggle {
    display: none;
    border: 1px solid var(--border); background: var(--surface);
    border-radius: 8px; width: 38px; height: 38px;
    align-items: center; justify-content: center; font-size: 18px; color: var(--text);
}

.user-menu { position: relative; }
.user-menu-btn {
    display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--border); background: var(--surface);
    border-radius: 999px; padding: 6px 14px 6px 6px; font-size: 13px; color: var(--text);
}
.user-menu-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--gold-soft); color: var(--gold-deep); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; overflow: hidden; flex-shrink: 0; }
.user-menu-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-menu-drop {
    position: absolute; right: 0; top: calc(100% + 8px);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-soft); min-width: 190px; padding: 6px; display: none; z-index: 1050;
}
.user-menu.is-open .user-menu-drop { display: block; }
.user-menu-drop a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); font-size: 13px; }
.user-menu-drop a:hover { background: var(--surface-2); text-decoration: none; }

.content { padding: 28px; flex: 1; }

/* ---------------------------------------------------------------- cards */
.card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-soft); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: 16px 20px; font-weight: 600; }
.card-body { padding: 20px; }

.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow-soft);
}
.stat-card-top { display: flex; align-items: center; justify-content: space-between; }
.stat-card-icon { width: 36px; height: 36px; border-radius: 9px; background: var(--gold-soft); color: var(--gold-deep); display: flex; align-items: center; justify-content: center; font-size: 17px; }
.stat-card-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-card-value { font-size: 26px; font-weight: 600; font-family: var(--font-serif); }
.stat-card-delta { font-size: 12px; }
.stat-card-delta.up { color: var(--success); }
.stat-card-delta.down { color: var(--danger); }

/* ---------------------------------------------------------------- buttons */
/* Base .btn must come BEFORE the .btn-* variants below: same specificity
   (one class each), so whichever rule is declared later wins the cascade.
   The base rule exists so a bare .btn still lays out correctly even if the
   Bootstrap CDN fails (see app.css history) — but that fallback background
   must never be allowed to win over an actual variant's own color, which is
   exactly what source order guarantees here. */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    border-radius: 8px; font-family: var(--font-sans); font-size: 13.5px; font-weight: 500;
    padding: 8px 16px; border: 1px solid transparent; cursor: pointer; text-decoration: none;
    background: var(--surface); color: var(--text); line-height: 1.3;
}
.btn:hover { text-decoration: none; }
.btn i { font-size: 14px; vertical-align: -1px; }
.w-100 { width: 100%; }

.btn-brand { background: var(--ink); border: 1px solid var(--ink); color: var(--gold); font-weight: 600; }
.btn-brand:hover { background: var(--ink-2); color: var(--gold); }
.btn-outline-brand { background: transparent; border: 1px solid var(--border-strong); color: var(--text); }
.btn-outline-brand:hover { background: var(--surface-2); border-color: var(--gold); color: var(--text); }
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger-soft { background: var(--danger-bg); border: 1px solid var(--danger-bg); color: var(--danger); }
.btn-danger-soft:hover { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- forms */
/* Layout-critical properties are declared here explicitly (not left to
   Bootstrap alone) so every form control still lays out correctly even if
   the Bootstrap CDN is slow, blocked, or offline on first load. */
.form-control, .form-select {
    display: block; width: 100%; box-sizing: border-box;
    padding: 8px 12px; min-height: 40px; line-height: 1.4;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
    font-family: var(--font-sans); font-size: 14px; color: var(--text);
}
.form-control:focus, .form-select:focus {
    outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(198,161,91,.18);
}
.form-check { display: block; min-height: 1.2rem; padding-left: 1.6em; margin-bottom: 0.25rem; }
.form-check-input { float: left; margin-left: -1.6em; margin-top: 0.2em; width: 1em; height: 1em; }
.form-check-label { display: inline-block; margin-bottom: 0; }
.form-label, label.form-label { display: block; }
.form-label { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 6px; }
.field-help { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* ---------------------------------------------------------------- tables */
.table-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.table-toolbar .search-box { flex: 1; min-width: 200px; }
.table-luxury-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.table-luxury { width: 100%; margin: 0; font-size: 13.5px; }
.table-luxury thead th {
    background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border);
    padding: 12px 16px; white-space: nowrap;
}
.table-luxury tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-luxury tbody tr:last-child td { border-bottom: none; }
.table-luxury tbody tr:hover { background: var(--surface-2); }
.table-luxury .text-end { text-align: right; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table-actions .btn { padding: 5px 10px; font-size: 12.5px; }

.badge-status {
    display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; text-transform: capitalize;
}
.badge-status.success { background: var(--success-bg); color: var(--success); }
.badge-status.warning { background: var(--warning-bg); color: var(--warning); }
.badge-status.danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-status.info    { background: var(--info-bg);    color: var(--info); }
.badge-status.neutral { background: var(--neutral-bg); color: var(--neutral); }

.cell-thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); display: block; }
.cell-thumb-empty { display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--text-faint); font-size: 15px; }

.photo-field-preview { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; border: 1px solid var(--border); display: block; margin-bottom: 10px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state i { font-size: 32px; color: var(--text-faint); margin-bottom: 12px; display: block; }

.pagination-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; font-size: 13px; color: var(--text-muted); flex-wrap: wrap; gap: 10px; }
.pagination-bar .page-links { display: flex; gap: 4px; }
.pagination-bar .page-links a, .pagination-bar .page-links span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; color: var(--text);
}
.pagination-bar .page-links a:hover { border-color: var(--gold); text-decoration: none; }
.pagination-bar .page-links .is-current { background: var(--ink); color: var(--gold); border-color: var(--ink); }

/* ---------------------------------------------------------------- alerts/flash */
.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash-alert {
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 10px; font-size: 13.5px;
}
.flash-alert.success { background: var(--success-bg); color: var(--success); }
.flash-alert.danger  { background: var(--danger-bg);  color: var(--danger); }
.flash-alert.warning { background: var(--warning-bg); color: var(--warning); }
.flash-alert.info    { background: var(--info-bg);    color: var(--info); }
.flash-alert .close-flash { margin-left: auto; cursor: pointer; opacity: .6; }
.flash-alert .close-flash:hover { opacity: 1; }

/* One-time reveal of freshly-provisioned tenant portal logins — deliberately NOT
   a .flash-alert (those auto-fade after 6s; credentials must stay until dismissed). */
.reveal-credentials-card {
    background: rgba(198,161,91,0.08); border: 1px solid rgba(198,161,91,0.35);
    border-radius: 12px; padding: 20px 22px; margin-bottom: 20px;
}
.reveal-credentials-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 16px; }
.reveal-credentials-icon {
    width: 38px; height: 38px; border-radius: 10px; background: rgba(198,161,91,0.18); color: var(--gold-deep);
    display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0;
}
.reveal-credentials-heading { flex: 1; min-width: 0; }
.reveal-credentials-heading strong { display: block; font-size: 15px; margin-bottom: 3px; }
.reveal-credentials-heading p { margin: 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.reveal-credentials-heading p code { background: var(--surface-2); padding: 2px 7px; border-radius: 5px; color: var(--text); font-weight: 500; }
.reveal-credentials-head .close-flash-manual { cursor: pointer; opacity: .5; font-size: 18px; line-height: 1; flex-shrink: 0; }
.reveal-credentials-head .close-flash-manual:hover { opacity: 1; }
.reveal-credentials-list { display: flex; flex-direction: column; gap: 8px; }
.reveal-credentials-row {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
}
.reveal-credentials-avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--gold-soft); color: var(--gold-deep);
    display: flex; align-items: center; justify-content: center; font-family: var(--font-serif);
    font-size: 14px; flex-shrink: 0;
}
.reveal-credentials-who { flex: 1; min-width: 0; }
.reveal-credentials-name { font-weight: 500; font-size: 13.5px; }
.reveal-credentials-username { font-size: 12px; color: var(--gold-deep); background: none; padding: 0; }
.reveal-credentials-row .btn { flex-shrink: 0; }

/* ---------------------------------------------------------------- charts */
.chart-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; }
.chart-legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ---------------------------------------------------------------- misc */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 20px; font-weight: 600; margin: 0; }
.page-header p { font-size: 13px; color: var(--text-muted); margin: 2px 0 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 0 0 12px; }

/* ---------------------------------------------------------------- icon input field */
.input-icon-field { position: relative; }
.input-icon-field .form-control { padding-left: 42px; }
.input-icon-field > i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: 16px; pointer-events: none; }

/* ---------------------------------------------------------------- password field */
.password-field { position: relative; }
.password-field .form-control { padding-right: 42px; }
.password-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: 6px; color: var(--text-faint); cursor: pointer; padding: 0;
}
.password-toggle:hover { color: var(--text-muted); background: var(--surface-2); }
.password-toggle i { font-size: 16px; margin: 0; }

/* ---------------------------------------------------------------- file picker */
.file-picker { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-picker-input {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.file-picker-input:focus-visible + .file-picker-btn {
    box-shadow: 0 0 0 3px rgba(198,161,91,.35); border-color: var(--gold);
}
.file-picker-btn { cursor: pointer; display: inline-flex; align-items: center; }
.file-picker-name { font-size: 13px; color: var(--text-muted); }

/* ---------------------------------------------------------------- searchable select */
/* Progressive enhancement over a plain <select> (public/assets/js/searchable-select.js)
   for any dropdown backed by a table that grows over time — units, tenants,
   leases, invoices, vendors, properties — so finding one record in a list of
   hundreds doesn't mean scrolling a native <select>. */
.ss-wrap { position: relative; }
.ss-native {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.ss-control {
    display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px;
    border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: text;
}
.ss-control:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(198,161,91,.18); }
.ss-control.is-invalid { border-color: var(--danger); }
.ss-control.is-disabled { background: var(--surface-2); cursor: not-allowed; opacity: .7; }
.ss-search-input {
    flex: 1; min-width: 0; border: none; outline: none; background: transparent;
    font-family: var(--font-sans); font-size: 14px; color: var(--text); padding: 8px 0;
}
.ss-caret { color: var(--text-faint); font-size: 12px; flex-shrink: 0; pointer-events: none; }
.ss-dropdown {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: var(--shadow-soft); max-height: 240px; overflow-y: auto; padding: 4px;
}
.ss-option { padding: 8px 10px; border-radius: 6px; font-size: 13.5px; color: var(--text); cursor: pointer; }
.ss-option:hover, .ss-option.is-highlighted { background: var(--surface-2); }
.ss-option.is-selected { color: var(--gold-deep); font-weight: 500; }
.ss-empty { padding: 8px 10px; font-size: 13px; color: var(--text-faint); }
.ss-error { font-size: 12px; color: var(--danger); margin-top: 6px; }

/* ---------------------------------------------------------------- confirm dialog */
.modal-backdrop-custom {
    position: fixed; inset: 0; background: rgba(18,21,27,.55);
    display: flex; align-items: center; justify-content: center; z-index: 1080; padding: 16px;
}
.modal-box { background: var(--surface); border-radius: var(--radius-lg); padding: 22px; max-width: 380px; width: 100%; box-shadow: var(--shadow-soft); }
.modal-box p { font-size: 14px; margin: 0 0 18px; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1024px) {
    .content { padding: 20px; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }
    .main { margin-left: 0; }
    .sidebar-toggle { display: flex; }
    .topbar-clock { display: none; }
    .content { padding: 16px; }
    .btn { min-height: 44px; }
    .sidebar-link { min-height: 44px; }
}
