/* SMS (School Management System) — Custom Styles */
/* Most styling via Tailwind utility classes; this file handles edge cases */

/* ── Viewport shell (no gap above sticky/fixed headers) ─────── */
html,
body {
    margin: 0;
    padding: 0;
}

.app-top-bar {
    padding-top: env(safe-area-inset-top, 0);
}

.app-top-bar-spacer {
    height: calc(3.5rem + env(safe-area-inset-top, 0));
    flex-shrink: 0;
}

.portal-top-bar,
.teacher-top-bar {
    padding-top: env(safe-area-inset-top, 0);
}

/* ── Responsive Table Cards (mobile card layout) ──────────── */
@media (max-width: 767px) {
    .responsive-table thead { display: none; }
    .responsive-table tbody tr {
        display: block;
        margin-bottom: 0.75rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: 0.75rem;
        background: #fff;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    .responsive-table tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.375rem 0;
        border: none;
    }
    .responsive-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #475569;
        margin-right: 1rem;
    }
    /* Dark mode table cards */
    .dark .responsive-table tbody tr {
        background: #1e293b;
        border-color: #475569;
        box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    }
    .dark .responsive-table tbody td::before {
        color: #94a3b8;
    }

    .responsive-table tbody tr.details-row {
        background: transparent;
        border: none;
        box-shadow: none;
        margin-top: -0.5rem;
        margin-bottom: 4.5rem; /* Prevent overlap with sticky nav */
        padding: 0;
        position: relative;
        z-index: 20;
    }

    .responsive-table tbody tr.details-row td {
        display: block !important;
        width: 100%;
        padding: 0 !important;
        border: none !important;
    }

    .responsive-table tbody tr.details-row td::before {
        content: none !important;
    }

    .responsive-table tbody tr.details-row .rounded-lg {
        margin: 0;
        box-shadow: none;
        border: 1px solid #e5e7eb;
        padding: 1.25rem !important;
        margin-bottom: 1rem;
    }

    .toggle-details {
        min-width: 80px;
        min-height: 44px;
        padding: 0.75rem 0.9rem;
        touch-action: manipulation;
    }

    .summary-row td {
        cursor: pointer;
    }
}

/* ── Print Styles ──────────────────────────────────────────── */
@media print {
    .no-print, nav, .sidebar, #mobile-nav, .flash-message { display: none !important; }
    main { margin: 0 !important; padding: 0 !important; }
    body { background: #fff !important; color: #000 !important; }
}

/* ── Smooth Transitions ───────────────────────────────────── */
.sidebar-transition {
    transition: transform 0.3s ease-in-out;
}

/* ── Loading Skeleton ─────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}
.dark .skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
    background-size: 200% 100%;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Custom Scrollbar ─────────────────────────────────────── */
.custom-scrollbar::-webkit-scrollbar { width: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: #f1f5f9; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #64748b; }
.dark .custom-scrollbar::-webkit-scrollbar-track { background: #1e293b; }
.dark .custom-scrollbar::-webkit-scrollbar-thumb { background: #475569; }

/* ── Badge Pulse ──────────────────────────────────────────── */
.badge-pulse {
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Safe Area (iPhone notch) ─────────────────────────────── */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.safe-area-top {
    padding-top: env(safe-area-inset-top, 0);
}

/* ── Touch-friendly form inputs ───────────────────────────── */
@media (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="tel"],
    input[type="search"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        min-height: 44px;
    }
    button, .btn, [role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ── Pull-to-refresh indicator ────────────────────────────── */
.pull-indicator {
    transition: transform 0.2s ease;
}

/* ── Sticky table headers ─────────────────────────────────── */
@media (min-width: 768px) {
    .sticky-thead thead th {
        position: sticky;
        top: 0;
        z-index: 10;
        background: #f9fafb;
    }
    .dark .sticky-thead thead th {
        background: #1e293b;
    }
}

/* ── Mobile-friendly action buttons ───────────────────────── */
@media (max-width: 767px) {
    .action-bar {
        position: fixed;
        bottom: 56px; /* Above mobile nav */
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #e5e7eb;
        padding: 0.75rem 1rem;
        z-index: 15;
        box-shadow: 0 -2px 4px rgba(0,0,0,0.05);
    }
    .dark .action-bar {
        background: #1e293b;
        border-color: #475569;
    }
}

/* ── Swipe hint animations ────────────────────────────────── */
@keyframes swipe-hint {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-8px); }
}

.overflow-hint::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.9));
    pointer-events: none;
}
.dark .overflow-hint::after {
    background: linear-gradient(to right, transparent, rgba(15,23,42,0.9));
}

/* ── Dark mode form inputs ────────────────────────────────── */
.dark input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]):not([type="range"]),
.dark select,
.dark textarea {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
    border-color: #475569 !important;
    color-scheme: dark;
}
.dark input::placeholder,
.dark textarea::placeholder {
    color: #94a3b8 !important;
}
.dark input:focus,
.dark select:focus,
.dark textarea:focus {
    background-color: #334155 !important;
    border-color: #3b82f6 !important;
    color: #f1f5f9 !important;
}
.dark option {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
}
.dark input[type="file"] {
    background-color: #1e293b !important;
    color: #94a3b8 !important;
}
.dark input[type="file"]::file-selector-button {
    background-color: #334155 !important;
    color: #e2e8f0 !important;
    border-color: #475569 !important;
}

/* ── Dark mode subtle borders (where dark: variant is missing) ─── */
.dark .border-b:not([class*="dark:border"]) {
    border-color: #334155;
}
.dark .border-t:not([class*="dark:border"]) {
    border-color: #334155;
}

/* ── Dark mode status badges ──────────────────────────────── */
.dark .bg-green-100 { background-color: rgba(34, 197, 94, 0.15); }
.dark .text-green-700 { color: #4ade80; }
.dark .bg-red-50 { background-color: rgba(239, 68, 68, 0.1); }
.dark .border-red-200 { border-color: rgba(239, 68, 68, 0.3); }
.dark .bg-yellow-100 { background-color: rgba(234, 179, 8, 0.15); }
.dark .text-yellow-700 { color: #fbbf24; }
.dark .bg-blue-100 { background-color: rgba(59, 130, 246, 0.15); }
.dark .text-blue-700 { color: #60a5fa; }

/* ── Theme transition (smooth toggle) ─────────────────────── */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
    transition: background-color 0.3s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease !important;
    transition-delay: 0s !important;
}
/* ── Modern UI Polish ─────────────────────────────────────── */

/* Smooth card hover lift */
.card-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px -5px rgba(0,0,0,0.1), 0 4px 10px -5px rgba(0,0,0,0.04);
}
.dark .card-hover:hover {
    box-shadow: 0 8px 25px -5px rgba(0,0,0,0.4), 0 4px 10px -5px rgba(0,0,0,0.2);
}

/* Subtle glassmorphism for header */
@supports (backdrop-filter: blur(12px)) {
    .glass-header {
        background: rgba(255,255,255,0.85) !important;
        backdrop-filter: blur(12px) saturate(180%);
        -webkit-backdrop-filter: blur(12px) saturate(180%);
    }
    .dark .glass-header {
        background: rgba(15,23,42,0.85) !important;
    }
}

/* Smooth link/button interactions */
a, button {
    transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

/* Modern table row hover */
tbody tr {
    transition: background-color 0.15s ease;
}

/* Gradient accent bar for cards */
.accent-top {
    position: relative;
}
.accent-top::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #074DD9, #091c4d);
    border-radius: 0.75rem 0.75rem 0 0;
}

/* Better focus ring for dark mode */
.dark :focus-visible {
    outline-color: #60a5fa;
}

/* Animated page entrance */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in {
    animation: fadeInUp 0.3s ease-out;
}

/* Smooth count badge */
.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.375rem;
    font-size: 0.625rem;
    font-weight: 700;
    line-height: 1;
    border-radius: 9999px;
    background: #ef4444;
    color: white;
}

/* Status dot indicator */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.online { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.2); }
.status-dot.offline { background: #94a3b8; }

/* Improved empty state */
.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
}
.empty-state svg {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    color: #cbd5e1;
}
.dark .empty-state svg {
    color: #475569;
}

/* Modern select dropdown styling */
select {
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
    color: #374151;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
.dark select {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
}

/* ── Fee Board ─────────────────────────────────────────────── */
.fee-board-page .fee-board-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: flex-end;
    padding: 1rem 1.25rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
}
.dark .fee-board-page .fee-board-filters {
    background: #1e293b;
    border-color: #334155;
}
.fee-board-filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 120px;
}
.fee-board-filter-field span {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.fee-board-filter-field select,
.fee-board-filter-field input {
    min-height: 2.25rem;
    padding: 0.375rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background: #fff;
}
.dark .fee-board-filter-field select,
.dark .fee-board-filter-field input {
    background: #0f172a;
    border-color: #475569;
    color: #e2e8f0;
}
.fee-board-filter-search {
    flex: 1 1 220px;
    min-width: 220px;
}
.fee-board-filter-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}
.fee-board-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.25rem;
    padding: 0.375rem 0.875rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}
.fee-board-btn-primary {
    background: #2563eb;
    color: #fff;
}
.fee-board-btn-primary:hover {
    background: #1d4ed8;
}
.fee-board-btn-reset {
    background: #fff;
    color: #374151;
    border-color: #d1d5db;
}
.dark .fee-board-btn-reset {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #475569;
}
.fee-board-btn-discount {
    background: #06b6d4;
    color: #fff;
}
.fee-board-btn-discount:hover {
    background: #0891b2;
}
.fee-board-fee-chip {
    display: inline-flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.625rem 0.875rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    background: #f9fafb;
    color: #111827;
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s;
}
.fee-board-fee-chip:hover {
    border-color: #93c5fd;
    background: #eff6ff;
}
.fee-board-fee-chip.is-active {
    border-color: #2563eb;
    background: #dbeafe;
}
.dark .fee-board-fee-chip {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}
.dark .fee-board-fee-chip.is-active {
    background: #1e3a5f;
    border-color: #3b82f6;
}
.fee-board-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.fee-board-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    overflow: hidden;
}
.dark .fee-board-card {
    background: #1e293b;
    border-color: #334155;
}
.fee-board-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.fee-board-table thead {
    background: #f9fafb;
}
.dark .fee-board-table thead {
    background: #0f172a;
}
.fee-board-table th,
.fee-board-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
    text-align: left;
}
.dark .fee-board-table th,
.dark .fee-board-table td {
    border-bottom-color: #334155;
}
.fee-board-table th {
    font-size: 0.75rem;
    font-weight: 700;
    color: #374151;
    white-space: nowrap;
}
.dark .fee-board-table th {
    color: #cbd5e1;
}
.fee-board-table tbody tr:nth-child(even) {
    background: #fcfcfd;
}
.dark .fee-board-table tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.35);
}
.fee-board-table tbody tr:hover {
    background: #f3f4f6;
}
.dark .fee-board-table tbody tr:hover {
    background: rgba(30, 41, 59, 0.8);
}
.fee-board-col-student {
    min-width: 180px;
}
.fee-board-col-period {
    min-width: 52px;
    width: auto;
    text-align: center !important;
    white-space: nowrap;
}
.fee-board-col-period.fee-board-col-term {
    min-width: 72px;
}
.fee-board-col-month {
    width: 42px;
    text-align: center !important;
}
.fee-board-student-name {
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #111827;
}
.dark .fee-board-student-name {
    color: #f8fafc;
}
.fee-board-student-id {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.125rem;
}
.fee-board-phones {
    white-space: nowrap;
    color: #374151;
}
.dark .fee-board-phones {
    color: #cbd5e1;
}
.fee-board-check {
    width: 1rem;
    height: 1rem;
    accent-color: #2563eb;
    cursor: pointer;
}
.fee-board-check:disabled {
    cursor: default;
    opacity: 0.85;
}
.fee-board-empty {
    text-align: center;
    padding: 2rem 1rem !important;
    color: #9ca3af;
}
.fee-board-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
}
.fee-board-modal.hidden {
    display: none;
}
.fee-board-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}
.fee-board-modal-panel {
    position: relative;
    z-index: 1;
    width: min(100% - 2rem, 420px);
    padding: 1.25rem;
    border-radius: 0.75rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.15);
}
.dark .fee-board-modal-panel {
    background: #1e293b;
    border-color: #334155;
}

.dark #profile-menu {
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

/* ── Portal Card Styles ───────────────────────────────────── */
.portal-card {
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.portal-card:hover {
    box-shadow: 0 4px 12px -2px rgba(0,0,0,0.08), 0 2px 6px -1px rgba(0,0,0,0.04);
}
.dark .portal-card:hover {
    box-shadow: 0 4px 12px -2px rgba(0,0,0,0.3), 0 2px 6px -1px rgba(0,0,0,0.2);
}

/* ── Focus ring update ─────────────────────────────────── */
:focus-visible {
    outline: 2px solid #074DD9;
    outline-offset: 2px;
}
.dark :focus-visible {
    outline-color: #6080f8;
}

/* ── Bottom nav enhancement ───────────────────────────────── */
@media (max-width: 1023px) {
    .action-bar {
        bottom: 64px; /* Above new 16px taller mobile nav */
    }
}
