/**
 * 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
 * ========================================================
 */

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

.responsive-panel-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.responsive-panel-grid>.panel {
    margin-bottom: 0;
}

/* ======================================================== */
/* 2. BUTTONS & BADGES                                      */
/* ======================================================== */
.btn {
    background-color: var(--accent);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

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

.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: 24px;
}

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

.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 {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-start;
    gap: 6px;
    line-height: 1;
}

/* ======================================================== */
/* 3. FORMS, INPUTS & TOGGLES                               */
/* ======================================================== */
.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;
}

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

td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

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 {
    /* Logical borders and padding */
    border-inline-start: 3px solid var(--accent);
    padding-inline-start: 16px;
    margin-bottom: 24px;
    position: relative;
}

.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"],
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;
}

.calendar-month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.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: #f8fafc;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    /* Logical border placement */
    border-inline-start: 3px solid var(--accent);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

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


/* ======================================================== */
/* 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 */
        inset-inline-start: auto;
        text-align: start;
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.8rem;
        text-transform: uppercase;
        flex-shrink: 0;
        /* Logical margin */
        margin-inline-end: 16px;
        width: auto;
        max-width: 40%;
        white-space: normal;
    }

    #view-title,
    #google-sync-indicator,
    #global-sync-status {
        display: block !important;
        width: 100% !important;
        flex-basis: 100% !important;
        margin-top: 4px;
        /* Logical text align */
        text-align: start;
    }

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

    tr.dir-row .dir-mobile-hidden {
        display: none !important;
    }

    tr.dir-row.mobile-expanded .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;
    }
}