/**
 * Custom Application Styles
 *
 * Main stylesheet for JTS Web 2025 application
 * Modernized with Blue Slate palette and refined UI components
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary-color: #0f172a;       /* Slate 900 */
    --primary-light: #1e293b;      /* Slate 800 */
    --heading-color: var(--primary-color);
    --accent-color: #3b82f6;       /* Blue 500 */
    --accent-color-rgb: 59, 130, 246;
    --success-color: #10b981;      /* Emerald 500 */
    --warning-color: #f59e0b;      /* Amber 500 */
    --danger-color: #ef4444;       /* Red 500 */
    --bg-body: #f8fafc;            /* Slate 50 */
    --bg-card: #ffffff;
    --text-main: #1e293b;          /* Slate 800 */
    --text-muted: #64748b;         /* Slate 500 */
    --border-color: #e2e8f0;       /* Slate 200 */
    --card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --card-shadow-hover: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

[data-bs-theme="dark"] {
    --primary-color: #0a0e14;
    --primary-light: #131822;
    --heading-color: #f8fafc;
    --accent-color: #60a5fa;
    --accent-color-rgb: 96, 165, 250;
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --danger-color: #f87171;
    --bg-body: #0a0e14;
    --bg-card: #131822;
    --text-main: #f1f5f9;
    --text-muted: #a8b6c9;
    --border-color: #64748b;
    --card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.6), 0 1px 2px -1px rgb(0 0 0 / 0.6);
    --card-shadow-hover: 0 4px 6px -1px rgb(0 0 0 / 0.6), 0 2px 4px -2px rgb(0 0 0 / 0.6);

    --bs-body-bg: var(--bg-body);
    --bs-body-color: var(--text-main);
    --bs-secondary-color: var(--text-muted);
    --bs-secondary-bg: #1a2029;
    --bs-tertiary-bg: #171c26;
    --bs-emphasis-color: #ffffff;
    --bs-border-color: var(--border-color);
    --bs-border-color-translucent: rgba(255, 255, 255, 0.18);
    --bs-link-color: var(--accent-color);
    --bs-link-hover-color: #93c5fd;
    --bs-card-bg: var(--bg-card);
    --bs-card-border-color: var(--border-color);
    --bs-heading-color: var(--heading-color);
    --bs-dropdown-bg: var(--bg-card);
    --bs-dropdown-link-color: var(--text-main);
    --bs-dropdown-link-hover-bg: #1a2029;
    --bs-modal-bg: var(--bg-card);
    --bs-table-color: var(--text-main);
    --bs-table-bg: var(--bg-card);
    --bs-table-border-color: var(--border-color);
}

/* ── Legacy Bootstrap Utility Compatibility (dark mode) ──────
   Bootstrap 5.3's color-mode system doesn't remap old utility
   classes (bg-light, bg-white, table-light, text-bg-light,
   text-dark) used throughout existing templates. This is the
   single compatibility seam for those classes — do not add
   scattered one-off dark-mode fixes elsewhere for them. */
[data-bs-theme="dark"] .bg-light {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

[data-bs-theme="dark"] .bg-white {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

[data-bs-theme="dark"] .table-light,
[data-bs-theme="dark"] .table-light > th,
[data-bs-theme="dark"] .table-light > td {
    background-color: var(--bs-secondary-bg) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

[data-bs-theme="dark"] .text-bg-light {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

[data-bs-theme="dark"] .text-dark {
    color: var(--text-main) !important;
}

/* Badges/pills that intentionally keep a light, theme-independent
   background (bg-warning, bg-light, bg-white, bg-info) must keep
   dark text for contrast — restore it after the blanket .text-dark
   override above. */
[data-bs-theme="dark"] .bg-warning.text-dark,
[data-bs-theme="dark"] .bg-light.text-dark,
[data-bs-theme="dark"] .bg-white.text-dark,
[data-bs-theme="dark"] .bg-info.text-dark,
[data-bs-theme="dark"] .text-bg-warning,
[data-bs-theme="dark"] .text-bg-light {
    color: #1e293b !important;
}

/* Page Layout */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

/* Navbar Modernization */
.navbar {
    background-color: var(--primary-color) !important;
    padding: 0.75rem 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar-brand {
    font-weight: 700;
    letter-spacing: -0.025em;
}

/* Page Headers */
.page-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 2rem;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--heading-color);
    letter-spacing: -0.025em;
}

/* Card Styling */
.card {
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: var(--card-shadow);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    background-color: var(--bg-card);
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem;
    font-weight: 600;
}

.card-body {
    padding: 1.25rem;
}

/* Table Styling */
.table {
    --bs-table-hover-bg: #f1f5f9;
    --bs-table-striped-bg: rgba(248, 250, 252, 0.8); /* Slate 50 */
    margin-bottom: 0;
}

/* Force global table appearance and padding standards */
table.table {
    font-size: 0.85rem !important;
}

/* High-Density Table Standard */
.table-high-density td {
    padding: 0 0.75rem !important;
    height: 24px !important; /* Force exact row height */
    vertical-align: middle !important;
    line-height: 24px !important;
    white-space: nowrap;
}

.table-high-density th {
    padding: 2px 0.75rem !important;
    height: 24px !important;
    line-height: 20px !important;
}

/* Action Icons - Ultra Compact for 24px rows */
.action-icon, .more-actions {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 20px !important;
    height: 20px !important;
    padding: 0 !important;
    margin: 0 1px !important;
    font-size: 0.75rem !important;
    color: var(--text-muted);
    border-radius: 4px;
    vertical-align: middle;
}

.action-icon i, .more-actions i {
    font-size: 0.75rem !important;
    line-height: 1;
}

.action-icon:hover {
    background-color: #f1f5f9;
    color: var(--accent-color);
}

/* Badge Refinement for 24px rows */
.table-high-density .badge {
    padding: 1px 4px !important;
    font-size: 0.65rem !important;
    font-weight: 600 !important;
    line-height: 1 !important;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.action-icon:hover {
    background-color: #f1f5f9;
    color: var(--accent-color);
    transform: scale(1.1);
}

/* ── Count Badge ─────────────────────────────────────────────
   Ported from the orphaned apps/core/static/css/styles.css,
   which Django never serves. This is the live equivalent. */
.count-badge {
    display: inline-block;
    min-width: 30px;
    padding: 0.15rem 0.4rem;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    border-radius: 0.25rem;
    color: #fff;
    background-color: #0d6efd;
    text-decoration: none;
}

.count-badge:hover {
    background-color: #0b5ed7;
    color: #fff;
}

/* HTMX Transitions */
.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
}
.htmx-request .htmx-indicator {
    opacity: 1;
}
.htmx-request.htmx-indicator {
    opacity: 1;
}

/* Search results fade in */
.search-results-fade {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Custom form styling */
.form-control, .form-select {
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    padding: 0.625rem 0.875rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 4px rgba(var(--accent-color-rgb), 0.15);
}

/* ── Activity Tracking Grid ─────────────────────────────────── */
.activity-grid-wrapper {
    border: 1px solid #b7bcc1;
    border-radius: 0.25rem;
    background-color: #f8f9fa;
}

.activity-grid-scroll {
    overflow-x: auto;
}

.activity-grid {
    width: 100%;
    min-width: 1260px;
    border-collapse: collapse;
    font-size: 0.78rem;
    background-color: #ffffff;
    table-layout: fixed;
}

.activity-grid thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: #e8ecef;
    border: 1px solid #c7ccd1;
    padding: 0.32rem 0.4rem;
    font-weight: 600;
    white-space: nowrap;
}

.activity-grid thead th.wrap {
    white-space: normal;
    line-height: 1.1;
    text-align: center;
}

.activity-grid tbody td {
    border: 1px solid #d4d9de;
    padding: 0.28rem 0.4rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.activity-grid tbody tr:nth-child(even) {
    background-color: #f5f7f9;
}

.activity-grid tbody tr.is-current {
    background-color: #e5f4ff;
}

.activity-grid .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.activity-grid .actions-cell .d-flex {
    gap: 0.35rem;
}

.activity-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid #b7bcc1;
    border-radius: 0.25rem;
    background-color: #eef1f4;
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
}

.activity-summary .label {
    color: #4a535c;
    font-weight: 600;
    margin-right: 0.3rem;
}

@media (max-width: 992px) {
    .activity-summary {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }
}

/* ── Detention Booking Checklist ───────────────────────────── */
.booking-checklist-form .card-header {
    font-size: 0.92rem;
}

.checklist-grid-header,
.checklist-grid-row {
    display: grid;
    grid-template-columns: minmax(140px, 1.3fr) minmax(110px, 0.8fr) minmax(180px, 1.4fr) minmax(140px, 1fr) minmax(120px, 0.9fr) minmax(180px, 1.6fr);
    gap: 0.5rem;
    align-items: center;
}

.checklist-grid-header {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid #dee2e6;
    margin-bottom: 0.5rem;
}

.checklist-grid-row {
    padding: 0.32rem 0;
    border-bottom: 1px solid #f1f3f5;
}

.checklist-grid-row:last-of-type {
    border-bottom: 0;
}

.checklist-cell .form-group,
.checklist-cell .mb-3 {
    margin-bottom: 0;
}

.checklist-label {
    font-size: 0.92rem;
    font-weight: 500;
}

.checklist-grid-errors {
    margin-bottom: 0.5rem;
}

.checklist-status-panel {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    background: #f8f9fa;
}

.checklist-status-panel.is-complete {
    border-color: #198754;
    background: #eef9f2;
}

.checklist-status-heading {
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #6c757d;
    border-bottom: 1px solid #dee2e6;
}

.checklist-status-body {
    padding: 0.75rem;
}

@media (max-width: 991.98px) {
    .checklist-grid-header {
        display: none;
    }

    .checklist-grid-row {
        grid-template-columns: 1fr;
        gap: 0.35rem;
        padding: 0.75rem 0;
    }

    .checklist-label {
        margin-bottom: 0.15rem;
    }
}

/* ── Detention Pod Report ───────────────────────────────────── */
.pod-report-filter-form {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.pod-report-filter-date {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.pod-report-filter-date .form-control {
    width: 9.5rem;
}

.pod-report-filter-pods {
    flex: 1 1 auto;
    min-width: 14rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
}

.pod-report-filter-label,
.pod-report-filter-date .form-label {
    color: var(--bs-body-color);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    flex: 0 0 auto;
}

.pod-report-pod-options {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.25rem;
    overflow-x: auto;
    padding-bottom: 0.05rem;
}

.pod-report-pod-options .btn {
    min-width: 2.75rem;
    line-height: 1.1;
}

.pod-report-filter-actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    flex: 0 0 auto;
}

@media (max-width: 768px) {
    .pod-report-filter-form {
        align-items: end;
        flex-wrap: wrap;
    }

    .pod-report-filter-pods {
        flex-basis: 100%;
    }

    .pod-report-pod-options {
        flex-wrap: wrap;
        overflow-x: visible;
    }
}

.pod-report-table-wrap {
    overflow-x: auto;
}

table.table.pod-report-table {
    font-size: 0.78rem !important;
    white-space: nowrap;
}

.pod-report-header {
    vertical-align: bottom;
    white-space: normal;
    line-height: 1.1;
    min-width: 3.5rem;
    max-width: 6rem;
}

table.table.pod-report-table td,
table.table.pod-report-table th {
    padding: 0.25rem 0.35rem;
}

.pod-report-sticky-name_combined,
.pod-report-sticky-room_display,
.pod-report-sticky-pod {
    position: sticky;
    background: var(--bs-body-bg, #fff);
    z-index: 2;
}

.pod-report-sticky-name_combined {
    left: 0;
    min-width: 9rem;
    max-width: 11rem;
}

.pod-report-sticky-room_display {
    left: 9rem;
    min-width: 4.5rem;
}

.pod-report-sticky-pod {
    left: 13.5rem;
    min-width: 3.5rem;
}

.pod-report-empty-row {
    color: var(--bs-secondary-color);
}

.pod-report-inactive-room td {
    background-color: rgba(108, 117, 125, 0.08);
}

.pod-report-cell-commentable {
    cursor: pointer;
}

.pod-report-cell-commented {
    background-color: #fff3cd !important;
    box-shadow: inset 0 0 0 2px rgba(255, 193, 7, 0.75);
}

.pod-report-cell-edit-modal {
    background: rgba(0, 0, 0, 0.45);
}

.pod-report-name-cell {
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pod-report-history-table {
    background: rgba(0, 0, 0, 0.02);
}

.pod-report-history-instance {
    opacity: 0.85;
}

.pod-report-selectable-row {
    cursor: pointer;
}

.pod-report-selectable-row:focus {
    outline: 2px solid rgba(13, 110, 253, 0.35);
    outline-offset: -2px;
}

.pod-report-row-selected > td {
    background-color: rgba(13, 110, 253, 0.08) !important;
}

.pod-report-row-selected > td.pod-report-cell-commented {
    background-color: #fff3cd !important;
}

.pod-report-bottom-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
}

.pod-report-action-btn.disabled {
    pointer-events: none;
    opacity: 0.55;
}

/* ── Dark Theme Overrides ─────────────────────────────────────
   Component-specific dark-mode adjustments for hardcoded colors
   that don't come from the CSS variables above. Consolidated here
   per component as they're addressed (see the dark/light mode
   toggle plan, Pass 2). */

/* .table's own --bs-table-striped-bg/--bs-table-hover-bg (set above,
   in the "Table Styling" section) are hardcoded near-white values
   for light mode. Left as-is in dark mode, every other row rendered
   as a jarring bright block against the near-black body background. */
[data-bs-theme="dark"] .table {
    --bs-table-hover-bg: rgba(255, 255, 255, 0.06);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
}

/* Count Badge */
[data-bs-theme="dark"] .count-badge {
    background-color: var(--accent-color);
    color: #0a0e14;
}

[data-bs-theme="dark"] .count-badge:hover {
    background-color: #93c5fd;
    color: #0a0e14;
}

/* Activity Tracking Grid */
[data-bs-theme="dark"] .activity-grid-wrapper {
    border-color: var(--border-color);
    background-color: var(--bg-card);
}

[data-bs-theme="dark"] .activity-grid {
    background-color: var(--bg-card);
    color: var(--text-main);
}

[data-bs-theme="dark"] .activity-grid thead th {
    background-color: #1a2029;
    border-color: var(--border-color);
    color: var(--text-main);
}

[data-bs-theme="dark"] .activity-grid tbody td {
    border-color: var(--border-color);
}

[data-bs-theme="dark"] .activity-grid tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.03);
}

[data-bs-theme="dark"] .activity-grid tbody tr.is-current {
    background-color: rgba(96, 165, 250, 0.16);
}

[data-bs-theme="dark"] .activity-summary {
    border-color: var(--border-color);
    background-color: var(--bg-card);
}

[data-bs-theme="dark"] .activity-summary .label {
    color: var(--text-muted);
}

/* Detention Booking Checklist */
[data-bs-theme="dark"] .checklist-grid-header {
    color: var(--text-muted);
    border-bottom-color: var(--border-color);
}

[data-bs-theme="dark"] .checklist-grid-row {
    border-bottom-color: var(--border-color);
}

[data-bs-theme="dark"] .checklist-status-panel {
    border-color: var(--border-color);
    background: var(--bg-card);
}

[data-bs-theme="dark"] .checklist-status-panel.is-complete {
    border-color: var(--success-color);
    background: rgba(52, 211, 153, 0.12);
}

[data-bs-theme="dark"] .checklist-status-heading {
    color: var(--text-muted);
    border-bottom-color: var(--border-color);
}

/* Detention Pod Report */
[data-bs-theme="dark"] .pod-report-inactive-room td {
    background-color: rgba(148, 163, 184, 0.12);
}

[data-bs-theme="dark"] .pod-report-cell-commented,
[data-bs-theme="dark"] .pod-report-row-selected > td.pod-report-cell-commented {
    background-color: #78350f !important;
    color: #fef3c7 !important;
    box-shadow: inset 0 0 0 2px rgba(251, 191, 36, 0.75);
}

[data-bs-theme="dark"] .pod-report-cell-edit-modal {
    background: rgba(0, 0, 0, 0.65);
}

[data-bs-theme="dark"] .pod-report-history-table {
    background: rgba(255, 255, 255, 0.03);
}

[data-bs-theme="dark"] .pod-report-selectable-row:focus {
    outline-color: rgba(96, 165, 250, 0.5);
}

[data-bs-theme="dark"] .pod-report-row-selected > td {
    background-color: rgba(96, 165, 250, 0.16) !important;
}

/* Sticky form actions */
form:has(.form-actions-sticky) {
    padding-bottom: 6.5rem;
}

.form-actions-sticky {
    position: sticky;
    bottom: 0.75rem;
    z-index: 1020;
    margin-top: 1rem;
}

.form-actions-sticky__inner {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    padding: 0.9rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background: var(--bg-card);
    box-shadow: 0 0.5rem 1rem rgba(33, 37, 41, 0.12);
    backdrop-filter: blur(6px);
}

@supports not selector(form:has(.form-actions-sticky)) {
    .form-actions-sticky {
        margin-bottom: 5.5rem;
    }
}

@media (max-width: 767.98px) {
    .form-actions-sticky {
        bottom: 0.5rem;
    }

    .form-actions-sticky__inner {
        flex-direction: column;
        align-items: stretch;
    }

    .form-actions-sticky__inner .btn {
        width: 100%;
    }
}
