/**
 * SESSIONVAULT - COMPONENTS CSS
 * --------------------------------------------------------
 * TABLE OF CONTENTS:
 * --------------------------------------------------------
 * 1. Grid & Metrics
 * 2. Buttons & Badges
 * 3. Forms, Inputs & Toggles
 * 4. Tables & Timelines
 * 5. Calendar & Appointments
 * 6. Responsive Overrides
 * 7. Toasts, Search & Directory Controls
 * ========================================================
 */

/* ======================================================== */
/* 1. GRID & METRICS                                        */
/* ======================================================== */
.grid-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.metric-card {
    margin-bottom: 0 !important;
}

.metric-card h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.metric-card p {
    font-size: 1.8rem;
    font-weight: 700;
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
}

.responsive-panel-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.responsive-panel-grid>.panel {
    margin-bottom: 0;
}

/* ======================================================== */
/* 2. BUTTONS & BADGES                                      */
/* ======================================================== */

/* Prevent copying or highlighting titles globally */
h1,
h2,
h3,
h4,
h5,
h6 {
    -webkit-user-select: none;
    user-select: none;
}

.btn {
    background-color: var(--accent);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.1s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    outline: none !important;
    -webkit-tap-highlight-color: transparent !important;
    min-height: 40px;
    box-sizing: border-box;
}

.btn:active {
    transform: scale(0.97);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn:focus {
    outline: none !important;
}

.btn:hover {
    background-color: var(--accent-hover);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: #f8fafc;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 4px;
    min-height: 32px;
}

.btn-danger {
    background-color: var(--danger);
}

.btn-danger:hover {
    background-color: var(--danger-hover);
}

.btn-charcoal {
    background-color: var(--charcoal);
}

.btn-charcoal:hover {
    background-color: #334155;
}

.tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    gap: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
    display: none;
}

.tab {
    padding: 12px 4px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    flex-shrink: 0;
    white-space: nowrap;
}

.tab:hover {
    color: var(--text-main);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.badge {
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-active {
    background-color: #dcfce7;
    color: #166534;
}

.badge-closed {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid var(--border);
}

.badge-office {
    background-color: #e0f2fe;
    color: #0369a1;
}

.badge-online {
    background-color: #f3e8ff;
    color: #6b21a8;
}

#global-sync-status-container {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
}

#global-sync-status {
    display: block;
    font-size: 0.65rem !important;
    line-height: 1.15 !important;
    white-space: normal !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

.sync-text-full {
    display: inline;
}

.sync-text-mobile {
    display: none;
}

/* ======================================================== */
.form-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group.full-width {
    grid-column: span 2;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-main);
}

.control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    outline: none;
    background-color: #f8fafc;
    min-height: 42px;
    box-sizing: border-box;
}

.control:focus {
    border-color: var(--accent);
    background-color: #ffffff;
}

.control.flatpickr-input:read-only {
    background-color: #ffffff;
    cursor: pointer;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    /* Logical start inset instead of fixed left */
    inset-inline-start: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

/* Fallback for RTL switch movement */
[dir="rtl"] input:checked+.slider:before {
    transform: translateX(-24px);
}

.date-picker-ui,
.time-picker-ui {
    background-repeat: no-repeat;
    background-position: right 10px center;
    /* Logical padding */
    padding-inline-end: 36px !important;
}

/* Fallback for RTL Date/Time icon placement */
[dir="rtl"] .date-picker-ui,
[dir="rtl"] .time-picker-ui {
    background-position: left 10px center;
}


/* ======================================================== */
/* 4. TABLES & TIMELINES                                    */
/* ======================================================== */
#directory-table tr td:first-child,
#directory-table tr td.dir-name-cell,
#directory-table tr td.dir-name-cell strong {
    color: var(--accent, #2563eb) !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    text-decoration: none;
}

@media (hover: hover) {

    #directory-table tr td:first-child:hover,
    #directory-table tr td.dir-name-cell:hover,
    #directory-table tr td.dir-name-cell:hover strong {
        color: var(--accent-hover, #1d4ed8) !important;
        text-decoration: underline !important;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    /* Logical text align */
    text-align: start;
}

th {
    padding: 12px 16px;
    background-color: #f8fafc;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-align: start;
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    text-align: start;
}

/* Dashboard Session Table Column Alignment & Sizing */
.dash-sessions-table {
    width: 100%;
    table-layout: auto;
    border-collapse: collapse;
}

.dash-sessions-table thead th {
    background: #f8fafc !important;
    color: #64748b !important;
    font-size: 0.75rem !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    padding: 12px 16px !important;
    border-bottom: 2px solid #e2e8f0 !important;
}

.dash-sessions-table td {
    padding: 14px 16px !important;
    border-bottom: 1px solid #f1f5f9 !important;
    vertical-align: middle !important;
    font-size: 0.92rem !important;
}

#dash-sessions-list-panel {
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 16px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03) !important;
}

@media (min-width: 1001px) {
    .col-session-client {
        width: 28%;
        text-align: start;
    }

    .col-session-date {
        width: 16%;
        text-align: start;
    }

    .col-session-format {
        width: 14%;
        text-align: start;
    }

    .col-session-status {
        width: 20%;
        text-align: start;
    }

    .col-session-yield {
        width: 11%;
        text-align: end;
        font-variant-numeric: tabular-nums;
    }

    .col-session-actions {
        width: 11%;
        text-align: end;
    }
}

@media (max-width: 1000px) {
    .col-session-client,
    .col-session-date,
    .col-session-format,
    .col-session-status,
    .col-session-yield,
    .col-session-actions {
        width: 100% !important;
    }
}

tr.clickable:hover td {
    background-color: #f8fafc;
    cursor: pointer;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-style: italic;
}

.timeline-box {
    margin-top: 16px;
}

.timeline-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--accent, #3b82f6);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
}

.timeline-header-strip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.timeline-meta-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.timeline-session-date {
    font-weight: 750;
    font-size: 0.95rem;
    color: var(--text-main);
}

.timeline-meta-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.timeline-actions-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.timeline-btn-mark-paid {
    background: var(--success, #10b981) !important;
    color: #ffffff !important;
    border: 1px solid var(--success, #10b981) !important;
    font-weight: 600 !important;
    padding: 6px 12px !important;
    font-size: 0.82rem !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02) !important;
}

.timeline-btn-mark-paid:hover {
    background: #059669 !important;
}

.timeline-btn-notes {
    background: #eff6ff !important;
    color: #1d4ed8 !important;
    border: 1px solid #bfdbfe !important;
    font-weight: 600 !important;
    padding: 6px 12px !important;
    font-size: 0.82rem !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02) !important;
}

.timeline-btn-notes:hover {
    background: #dbeafe !important;
}

.timeline-btn-secondary {
    background: #f8fafc !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border) !important;
    font-weight: 500 !important;
    padding: 6px 10px !important;
    font-size: 0.8rem !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 5px !important;
}

.timeline-btn-secondary:hover {
    background: #f1f5f9 !important;
}

.timeline-btn-delete {
    background: transparent !important;
    color: #94a3b8 !important;
    border: 1px solid transparent !important;
    padding: 6px 8px !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-inline-start: auto;
    transition: color 0.15s, background-color 0.15s;
}

.timeline-btn-delete:hover {
    background: #fef2f2 !important;
    color: #dc2626 !important;
    border-color: #fee2e2 !important;
}

.timeline-del-text {
    display: none;
}

@media (max-width: 600px) {
    .timeline-actions-toolbar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        width: 100%;
    }
    
    .timeline-btn-mark-paid {
        grid-column: span 2;
        justify-content: center;
        padding: 8px 12px !important;
        height: 38px !important;
    }

    .timeline-btn-notes {
        grid-column: span 2;
        justify-content: center;
        padding: 8px 12px !important;
        height: 38px !important;
    }

    .timeline-btn-secondary {
        justify-content: center;
        height: 36px !important;
        padding: 6px 8px !important;
        font-size: 0.78rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .timeline-btn-delete {
        margin-inline-start: 0;
        justify-content: center;
        background: #fef2f2 !important;
        color: #dc2626 !important;
        border: 1px solid #fee2e2 !important;
        padding: 6px 8px !important;
        height: 36px !important;
        font-size: 0.78rem !important;
    }

    .timeline-del-text {
        display: inline;
        margin-inline-start: 4px;
    }
}

.timeline-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    justify-content: space-between;
    flex-wrap: wrap;
}

td .badge {
    white-space: nowrap !important;
    display: inline-block;
}

td[data-label="Amount"],
table:not(.doc-table) td:nth-child(4) {
    white-space: nowrap !important;
}


/* ======================================================== */
/* 5. CALENDAR & APPOINTMENTS                               */
/* ======================================================== */
.chart-container {
    height: 280px;
    width: 100%;
    margin-top: 24px;
}

.chart-bar {
    transition: fill 0.2s;
}

.chart-bar:hover {
    opacity: 0.85;
}

.calendar-container {
    display: grid;
    grid-template-columns: 100%;
    gap: 16px;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.calendar-nav-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}

.calendar-nav-group .btn-sm {
    border-radius: 7px;
    font-size: 0.82rem;
    padding: 5px 12px;
    font-weight: 600;
    border: none;
    background: #ffffff;
    color: #334155;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    cursor: pointer;
    transition: all 0.15s ease;
}

.calendar-nav-group .btn-sm:hover {
    background: #f8fafc;
    color: #0f172a;
}

@media (max-width: 600px) {
    .calendar-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }
    .calendar-nav-group {
        gap: 2px;
        padding: 2px;
    }
    .calendar-nav-group .btn-sm {
        padding: 4px 8px;
        font-size: 0.78rem;
    }
    #calendar-month-year {
        font-size: 1rem !important;
    }
}

.calendar-month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar-month-grid > .calendar-cell:nth-child(7n),
.calendar-month-grid > .calendar-cell:nth-child(7n - 1) {
    background: #f8fafc;
}

.calendar-month-grid > .calendar-cell.today:nth-child(7n),
.calendar-month-grid > .calendar-cell.today:nth-child(7n - 1) {
    background: #eff6ff;
}

.calendar-day-label {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding-bottom: 8px;
}

.calendar-cell {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-bg);
    padding: 4px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 80px;
    overflow-y: auto;
    overflow-x: hidden;
}

.calendar-cell:hover {
    background-color: #f8fafc;
    border-color: var(--accent);
}

.calendar-cell.inactive {
    opacity: 0.4;
}

.calendar-cell.today {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
    background: #f0f7ff;
}

.calendar-cell.selected {
    border-color: var(--accent);
    background: #eff6ff;
}

.calendar-cell-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.calendar-day-num {
    font-size: 0.85rem;
    font-weight: 600;
}

.calendar-apt-label {
    font-size: 0.65rem;
    padding: 3px 4px;
    border-radius: 4px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    color: #ffffff;
}

.apt-label-online {
    background-color: #3b82f6;
}

.apt-label-office {
    background-color: #06b6d4;
}

.apt-label-completed {
    background-color: #10b981;
}

.apt-label-missed {
    background-color: #f59e0b;
}

.appointment-strip {
    background: #ffffff;
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--accent);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
    transition: transform 0.15s, box-shadow 0.15s;
}

@media (min-width: 768px) {
    .appointment-strip:not(.calendar-grid-layout .appointment-strip) {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.calendar-grid-layout .appointment-strip {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
}

.appointment-strip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.apt-meta-title {
    font-size: 1.05rem;
    font-weight: 750;
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.apt-time-badge {
    color: var(--accent, #2563eb);
    font-weight: 700;
    font-size: 0.92rem;
    background: #eff6ff;
    padding: 2px 8px;
    border-radius: 6px;
}

.apt-actions-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.calendar-grid-layout .apt-actions-toolbar {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    width: 100% !important;
}

@media (min-width: 768px) {
    .appointment-strip:not(.calendar-grid-layout .appointment-strip) .apt-actions-toolbar {
        display: flex;
        align-items: center;
        width: auto;
        gap: 6px;
    }
}

.apt-btn-primary {
    background: #3b82f6 !important;
    color: #ffffff !important;
    border: none !important;
    font-weight: 600 !important;
    padding: 7px 12px !important;
    font-size: 0.82rem !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2) !important;
}

.apt-btn-primary:hover {
    background: #2563eb !important;
}

.apt-btn-secondary {
    background: #f8fafc !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border) !important;
    font-weight: 600 !important;
    padding: 7px 12px !important;
    font-size: 0.82rem !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
}

.apt-btn-secondary:hover {
    background: #f1f5f9 !important;
}

.apt-btn-cancel {
    background: #fef2f2 !important;
    color: #dc2626 !important;
    border: 1px solid #fee2e2 !important;
    font-weight: 600 !important;
    padding: 7px 12px !important;
    font-size: 0.82rem !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
}

.apt-btn-cancel:hover {
    background: #fee2e2 !important;
    border-color: #fca5a5 !important;
}

.appointment-strip-details {
    flex: 1;
    min-width: 150px;
}

.appointment-strip-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.appointment-strip.completed {
    border-inline-start-color: var(--success);
    opacity: 0.7;
}

.appointment-strip.cancelled {
    border-inline-start-color: var(--danger);
    text-decoration: line-through;
    opacity: 0.5;
}

#upcoming-appointments-list {
    max-height: 300px;
    overflow-y: auto;
    /* Logical padding */
    padding-inline-end: 4px;
}

#upcoming-appointments-list::-webkit-scrollbar {
    width: 6px;
}

#upcoming-appointments-list::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 4px;
}

.flatpickr-calendar {
    z-index: 10000 !important;
    font-family: 'Inter', sans-serif;
    border-radius: 14px !important;
    box-shadow: 0 10px 30px -8px rgba(15, 23, 42, 0.35) !important;
    overflow: hidden;
    border: none !important;
}

.flatpickr-calendar.hasTime .flatpickr-time {
    border-top: 1px solid #e5e7eb !important;
}

.flatpickr-time {
    height: 56px !important;
}

.flatpickr-time input {
    font-size: 1.15rem !important;
    font-weight: 600 !important;
    color: #1e293b !important;
}

.flatpickr-day.selected {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
}

/* Document Preview & Page Formatting */
.doc-page {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    min-height: 860px;
    position: relative;
}

.doc-page-content {
    flex: 1 0 auto;
}

.doc-footer {
    margin-top: auto;
    padding-top: 20px;
    text-align: end;
    font-size: 0.8rem;
    color: #94a3b8;
}

.doc-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    box-sizing: border-box;
}

.doc-table th,
.doc-table td {
    box-sizing: border-box;
}

.doc-table th {
    background-color: #2e4a52 !important;
    color: #ffffff !important;
    border: 1px solid #2e4a52 !important;
}

.doc-table td {
    white-space: normal !important;
    word-break: normal;
    overflow-wrap: break-word;
}


/* ======================================================== */
/* 6. RESPONSIVE OVERRIDES                                  */
/* ======================================================== */
@media (min-width: 1001px) {
    .responsive-panel-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 24px;
        align-items: stretch;
    }

    .responsive-panel-grid>.panel {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: 100%;
        margin-bottom: 0;
    }

    .responsive-panel-grid>.panel.full-span {
        grid-column: span 2;
    }

    #payment-method-breakdown {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 16px;
    }

    .mobile-only-toggle,
    .mobile-only-arrears,
    .dir-accordion-toggle,
    .dir-mobile-action-cell {
        display: none !important;
    }

    .profile-collapsible-section {
        display: block !important;
    }
}

@media (max-width: 1000px) {
    .grid-metrics {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .grid-metrics .metric-card:last-child {
        grid-column: span 2 !important;
    }

    #payment-method-breakdown {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 12px !important;
        width: 100% !important;
    }

    #payment-method-breakdown .metric-card {
        flex: 1 1 calc(50% - 12px) !important;
        min-width: 120px !important;
        margin-bottom: 0 !important;
    }

    .form-layout {
        grid-template-columns: 1fr;
    }

    .form-group.full-width {
        grid-column: span 1;
    }

    table {
        display: block;
        width: 100%;
        border-collapse: collapse;
    }

    thead {
        display: none;
    }

    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tr {
        margin-bottom: 16px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: #fff;
        padding: 8px 0;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    }

    td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        /* Logical text-align */
        text-align: end !important;
        padding: 12px 16px !important;
        border: none;
        border-bottom: 1px solid var(--border);
        position: relative;
        font-size: 0.95rem;
        word-break: break-word;
    }

    td:last-child {
        border-bottom: none;
    }

    td::before {
        content: attr(data-label);
        position: static !important;
        /* Logical left replacement */
        text-align: start;
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.8rem;
        flex-shrink: 0;
        /* Logical margin */
        margin-inline-end: 16px;
        width: auto;
        max-width: 40%;
        white-space: normal;
    }

    #view-title,
    #google-sync-indicator {
        display: block !important;
        width: 100% !important;
        flex-basis: 100% !important;
        margin-top: 4px;
        /* Logical text align */
        text-align: start;
    }

    /* Preserve document table layout in preview and print */
    .doc-table,
    #doc-preview-content table,
    #print-isolated-target table {
        display: table !important;
        width: 100% !important;
        border-collapse: collapse !important;
    }
    .doc-table thead,
    #doc-preview-content thead,
    #print-isolated-target thead {
        display: table-header-group !important;
    }

    .doc-table tbody,
    #doc-preview-content tbody,
    #print-isolated-target tbody {
        display: table-row-group !important;
    }

    .doc-table tr,
    #doc-preview-content tr,
    #print-isolated-target tr {
        display: table-row !important;
    }

    .doc-table th,
    .doc-table td,
    #doc-preview-content th,
    #doc-preview-content td,
    #print-isolated-target th,
    #print-isolated-target td {
        display: table-cell !important;
        box-shadow: none !important;
        margin-bottom: 0 !important;
        width: auto;
    }

    .doc-table th::before,
    .doc-table td::before,
    #doc-preview-content th::before,
    #doc-preview-content td::before,
    #print-isolated-target th::before,
    #print-isolated-target td::before {
        content: none !important;
        display: none !important;
    }

    .mobile-only-toggle {
        display: flex !important;
    }

    .profile-collapsible-section {
        display: none;
    }

    .profile-collapsible-section.expanded {
        display: block;
        margin-top: 12px;
        border-top: 1px solid var(--border);
        padding-top: 12px;
    }

    .dir-desktop-only {
        display: none !important;
    }

    /* Mobile Accordion Collapsible Rows for Directory & Dashboard */
    .dash-mobile-hidden,
    tr:not(.mobile-expanded) .dash-mobile-hidden,
    tr:not(.mobile-expanded) td.dash-mobile-hidden {
        display: none !important;
    }

    tr.mobile-expanded .dash-mobile-hidden,
    tr.mobile-expanded td.dash-mobile-hidden {
        display: flex !important;
    }

    tr.dir-row .dir-mobile-hidden,
    tr.dir-row:not(.mobile-expanded) .dir-mobile-hidden,
    tr.dir-row:not(.mobile-expanded) td.dir-mobile-hidden {
        display: none !important;
    }

    tr.dir-row.mobile-expanded .dir-mobile-hidden,
    tr.dir-row.mobile-expanded td.dir-mobile-hidden {
        display: flex !important;
    }

    tr.dir-row td.dir-name-cell {
        border-bottom: none !important;
        padding: 12px 16px !important;
    }

    tr.dir-row.mobile-expanded td.dir-name-cell {
        border-bottom: 1px solid var(--border) !important;
    }

    tr.dir-row td.dir-name-cell::before {
        display: none !important;
    }

    tr.dir-row td.dir-mobile-action-cell::before {
        display: none !important;
    }

    tr.dir-row td.dir-mobile-action-cell {
        border-bottom: none !important;
        padding: 12px 16px !important;
    }

    /* Prevent text selection and native mobile long-press menus on the About page */
    #view-about {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }

    /* Force 16px font size on mobile to block the iOS auto-zoom flicker */
    .control,
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    textarea,
    select {
        font-size: 16px !important;
    }
}

/* ======================================================== */
/* NATIVE BROWSER DATE/TIME ICON OVERLAP FIX                */
/* ======================================================== */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-inner-spin-button,
input[type="time"]::-webkit-inner-spin-button,
input[type="date"]::-webkit-clear-button,
input[type="time"]::-webkit-clear-button {
    display: none !important;
    -webkit-appearance: none !important;
    background: transparent !important;
    opacity: 0 !important;
}

input.flatpickr-input[type="time"],
input.flatpickr-input[type="date"] {
    display: none !important;
}

/* ======================================================== */
/* TOAST NOTIFICATION STYLING                               */
/* ======================================================== */
.app-toast {
    visibility: hidden;
    min-width: 250px;
    background-color: #0f172a;
    color: #ffffff;
    text-align: center;
    border-radius: 30px;
    padding: 12px 24px;
    position: fixed;
    z-index: 99999;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s, visibility 0.3s;
}

.app-toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 90px;
}

/* ======================================================== */
/* CLIENT DIRECTORY SEARCH & SORT CONTROLS                  */
/* ======================================================== */
.client-controls-container {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
}

.search-sort-group {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
    max-width: 480px;
    justify-content: flex-start;
}

[dir="rtl"] .search-sort-group {
    justify-content: flex-end;
}

/* Dynamic Icon Sort Dropdown */
.client-sort-select {
    flex: 0 0 52px !important;
    min-width: 52px !important;
    max-width: 52px !important;
    width: 52px !important;
    padding: 0 !important;
    color: transparent !important;
    cursor: pointer;
    margin-bottom: 0 !important;
    background-repeat: no-repeat !important;
    background-position: center center !important;
    background-size: 20px 20px !important;
}

.client-sort-select[value="name"] {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' fill=\'none\' stroke=\'%23475569\' stroke-width=\'2\' viewBox=\'0 0 24 24\'><path stroke-linecap=\'round\' stroke-linejoin=\'round\' d=\'M3 4h13M3 8h9m-9 4h6m4 0l4-4m0 0l4 4m-4-4v12\'/></svg>') !important;
}

.client-sort-select[value="date-desc"] {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' fill=\'none\' stroke=\'%23475569\' stroke-width=\'2\' viewBox=\'0 0 24 24\'><path stroke-linecap=\'round\' stroke-linejoin=\'round\' d=\'M3 4h18M3 10h12M3 16h6m6-4v8m0 0l-3-3m3 3l3-3\'/></svg>') !important;
}

.client-sort-select[value="date-asc"] {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' fill=\'none\' stroke=\'%23475569\' stroke-width=\'2\' viewBox=\'0 0 24 24\'><path stroke-linecap=\'round\' stroke-linejoin=\'round\' d=\'M3 4h18M3 10h12M3 16h6m6 8V8m0 0l3 3m-3-3l-3 3\'/></svg>') !important;
}

/* When focused/opened, reveal text and handle LTR/RTL padding correctly */
.client-sort-select:focus {
    color: var(--text-main) !important;
    flex: 0 0 160px !important;
    max-width: 160px !important;
    width: 160px !important;
}

[dir="ltr"] .client-sort-select:focus {
    padding-left: 36px !important;
    padding-right: 12px !important;
    background-position: left 10px center !important;
    text-align: left;
}

[dir="rtl"] .client-sort-select:focus {
    padding-right: 36px !important;
    padding-left: 12px !important;
    background-position: right 10px center !important;
    text-align: right;
}

.client-sort-select option {
    color: var(--text-main);
    background: #ffffff;
    padding: 10px;
    font-size: 0.95rem;
}

/* Search Input Styling with strict icon padding and direction isolation */
.client-search-input {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
    background-repeat: no-repeat;
    background-size: 18px 18px;
}

[dir="ltr"] .client-search-input,
[dir="ltr"] #client-search-input {
    padding-left: 40px !important;
    padding-right: 12px !important;
    background-position: left 12px center !important;
    text-align: left;
}

[dir="rtl"] .client-search-input,
[dir="rtl"] #client-search-input {
    padding-right: 40px !important;
    padding-left: 12px !important;
    background-position: right 12px center !important;
    text-align: right;
}

.add-client-btn {
    flex-shrink: 0;
    white-space: nowrap;
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .client-controls-container {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 8px !important;
        margin-bottom: 8px !important;
        width: 100% !important;
    }

    .add-client-btn {
        flex: 0 0 auto !important;
        width: auto !important;
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
        font-weight: 600 !important;
        height: 40px !important;
        min-height: 40px !important;
        white-space: nowrap !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 10px !important;
    }

    .search-sort-group {
        display: flex !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        gap: 6px !important;
        max-width: none !important;
    }

    .client-sort-select {
        flex: 0 0 40px !important;
        min-width: 40px !important;
        max-width: 40px !important;
        width: 40px !important;
        height: 40px !important;
        border-radius: 10px !important;
        background-size: 18px 18px !important;
    }

    .client-sort-select:focus {
        flex: 0 0 40px !important;
        max-width: 40px !important;
        width: 40px !important;
    }

    .client-search-input {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        height: 40px !important;
        font-size: 0.88rem !important;
        border-radius: 10px !important;
    }

    [dir="ltr"] .client-search-input,
    [dir="ltr"] #client-search-input {
        padding-left: 36px !important;
        padding-right: 10px !important;
    }

    [dir="rtl"] .client-search-input,
    [dir="rtl"] #client-search-input {
        padding-right: 36px !important;
        padding-left: 10px !important;
    }
}

/* RTL Icon & Direction Flipping */
[dir="rtl"] .rtl-flip,
html[dir="rtl"] .rtl-flip,
body[dir="rtl"] .rtl-flip {
    transform: scaleX(-1);
    display: inline-block;
}