/* ============================================================
   GymSaaS Design System
   ============================================================
   Organization:
     1. DESIGN TOKENS        -- CSS custom properties, role themes
     2. BASE                 -- html, body, selection, headings
     3. LAYOUT               -- sidebar, header, main, page-shell
     4. NAVIGATION           -- menu links, submenu links
     5. COMPONENTS           -- cards, buttons, alerts, forms, tables
     6. UTILITIES            -- semantic helpers, status colors
     7. TAILWIND COMPAT      -- legacy Tailwind class overrides
     8. SCROLLBAR            -- custom scrollbar styling
     9. RESPONSIVE           -- media queries
   ============================================================ */

/* ------------------------------------------------------------
   1. DESIGN TOKENS
   ------------------------------------------------------------ */
:root {
    --font-sans: "Roboto", "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
    --bg: #1a1a2e;
    --bg-accent: rgba(220, 53, 69, 0.18);
    --surface: rgba(25, 35, 60, 0.88);
    --surface-strong: rgba(30, 42, 70, 0.96);
    --surface-soft: rgba(44, 55, 85, 0.7);
    --border: rgba(220, 53, 69, 0.25);
    --border-strong: rgba(220, 53, 69, 0.4);
    --text: #e8e8f0;
    --text-muted: #c0c8e0;
    --heading: #ffffff;
    --accent: #DC3545;
    --accent-strong: #c82333;
    --accent-soft: rgba(220, 53, 69, 0.18);
    --accent-contrast: #ffffff;
    --shadow-lg: 0 24px 60px rgba(220, 53, 69, 0.25);
    --shadow-md: 0 16px 40px rgba(220, 53, 69, 0.18);
    --radius-lg: 1.25rem;
    --radius-md: 0.9rem;
}

body[data-role="app_admin"] {
    --bg-accent: rgba(74, 124, 226, 0.18);
    --accent: #4A7CE2;
    --accent-strong: #3A6CD2;
    --accent-soft: rgba(74, 124, 226, 0.18);
    --accent-contrast: #ffffff;
}

body[data-role="gym_admin"] {
    --bg-accent: rgba(220, 53, 69, 0.2);
    --accent: #DC3545;
    --accent-strong: #c82333;
    --accent-soft: rgba(220, 53, 69, 0.18);
    --accent-contrast: #ffffff;
}

body[data-role="gym_emp"] {
    --bg-accent: rgba(253, 200, 48, 0.18);
    --accent: #FDC830;
    --accent-strong: #f59e0b;
    --accent-soft: rgba(253, 200, 48, 0.16);
    --accent-contrast: #1a1203;
}

body[data-role="gym_member"] {
    --bg-accent: rgba(253, 200, 48, 0.18);
    --accent: #FDC830;
    --accent-strong: #f59e0b;
    --accent-soft: rgba(253, 200, 48, 0.17);
    --accent-contrast: #1a1203;
}

body[data-theme="ocean"] {
    --bg: #0c1b2a;
    --surface: rgba(18, 42, 65, 0.9);
    --surface-strong: rgba(15, 54, 88, 0.95);
    --border: rgba(56, 189, 248, 0.3);
    --border-strong: rgba(56, 189, 248, 0.45);
    --accent: #0ea5e9;
    --accent-strong: #0284c7;
    --accent-soft: rgba(14, 165, 233, 0.18);
    --accent-contrast: #ffffff;
}

body[data-theme="forest"] {
    --bg: #0f1f17;
    --surface: rgba(24, 47, 35, 0.9);
    --surface-strong: rgba(19, 62, 40, 0.95);
    --border: rgba(34, 197, 94, 0.3);
    --border-strong: rgba(34, 197, 94, 0.45);
    --accent: #22c55e;
    --accent-strong: #16a34a;
    --accent-soft: rgba(34, 197, 94, 0.18);
    --accent-contrast: #06230f;
}

/* ------------------------------------------------------------
   2. BASE
   ------------------------------------------------------------ */
html {
    font-family: var(--font-sans);
    -webkit-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
}

body.app-shell {
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at top left, var(--bg-accent), transparent 32%),
        radial-gradient(circle at bottom right, rgba(56, 189, 248, 0.08), transparent 26%),
        linear-gradient(180deg, #0b1220 0%, var(--bg) 100%);
}

body.app-shell::selection {
    background: var(--accent-soft);
    color: var(--heading);
}

body.sidebar-open {
    overflow: hidden;
}

a {
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--heading);
    letter-spacing: -0.02em;
}

h1[tabindex="-1"]:focus {
    outline: none;
}

main {
    color: var(--text);
}

[x-cloak] {
    display: none !important;
}

::selection {
    background: var(--accent-soft);
    color: var(--heading);
}

/* ------------------------------------------------------------
   3. LAYOUT
   ------------------------------------------------------------ */
#app-sidebar,
header,
.app-surface,
.app-card {
    backdrop-filter: blur(14px);
}

#app-sidebar {
    background: linear-gradient(180deg, rgba(10, 15, 27, 0.97) 0%, rgba(17, 24, 39, 0.94) 100%);
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

header {
    background: rgba(9, 17, 31, 0.82);
    border-color: var(--border);
}

.app-main {
    position: relative;
}

.app-page-shell {
    position: relative;
}

.app-page-shell::before {
    content: "";
    position: absolute;
    inset: -1rem -0.5rem auto;
    height: 12rem;
    border-radius: 2rem;
    background: linear-gradient(135deg, var(--accent-soft), transparent 65%);
    pointer-events: none;
    filter: blur(6px);
    opacity: 0.85;
}

.app-page-shell > * {
    position: relative;
}

.page-table-wrapper {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.page-table-wrapper table {
    min-width: 100%;
}

.page-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-panel-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* ------------------------------------------------------------
   4. NAVIGATION
   ------------------------------------------------------------ */
.app-menu-link,
.app-submenu-link {
    display: block;
    width: 100%;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text);
}

.app-menu-link {
    padding: 0.625rem 0.75rem;
}

.app-submenu-link {
    margin-left: 1rem;
    width: calc(100% - 1rem);
    padding: 0.625rem 0.75rem;
    color: #c3cfde;
}

.app-menu-link:hover,
.app-submenu-link:hover {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--heading);
}

.app-menu-link.is-active,
.app-menu-link.active,
.app-submenu-link.is-active,
.app-submenu-link.active {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: var(--accent-contrast);
    border-color: transparent;
    box-shadow: 0 12px 26px color-mix(in srgb, var(--accent) 32%, transparent);
    font-weight: 700;
}

/* ------------------------------------------------------------
   5. COMPONENTS
   ------------------------------------------------------------ */

/* --- Cards --- */
.app-card {
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-strong) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.app-card-muted {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.74) 0%, rgba(15, 23, 42, 0.9) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* --- Buttons --- */
.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.65rem 1rem;
    border-radius: 0.9rem;
    border: 1px solid transparent;
    font-weight: 600;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.app-btn:hover {
    transform: translateY(-1px);
}

.app-btn-primary {
    color: var(--accent-contrast);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    box-shadow: 0 14px 30px color-mix(in srgb, var(--accent) 28%, transparent);
}

.app-btn-secondary {
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border);
}

.app-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-strong);
}

.app-btn-info {
    color: #03131a;
    background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
    box-shadow: 0 14px 30px rgba(14, 165, 233, 0.25);
}

.app-btn-warning {
    color: #1c0d03;
    background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
    box-shadow: 0 14px 30px rgba(249, 115, 22, 0.25);
}

.app-btn-amber {
    color: #1c1404;
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    box-shadow: 0 14px 30px rgba(245, 158, 11, 0.24);
}

.app-btn-danger {
    color: #210507;
    background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
    box-shadow: 0 14px 30px rgba(239, 68, 68, 0.24);
}

/* --- Alerts --- */
.app-alert {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    font-size: 0.92rem;
}

.app-alert-error {
    border-color: rgba(248, 113, 113, 0.28);
    background: rgba(127, 29, 29, 0.18);
    color: #fca5a5;
}

.app-alert-danger {
    border-color: rgba(248, 113, 113, 0.28);
    background: rgba(127, 29, 29, 0.18);
    color: #fca5a5;
}

.app-alert-success {
    border-color: rgba(74, 222, 128, 0.22);
    background: rgba(20, 83, 45, 0.24);
    color: #bbf7d0;
}

.app-alert-info {
    border-color: rgba(56, 189, 248, 0.24);
    background: rgba(8, 47, 73, 0.26);
    color: #bae6fd;
}

/* --- Form Controls --- */
.app-input,
.app-select,
.app-textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.95rem;
    background: rgba(15, 23, 42, 0.74);
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.35;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

select.app-input,
select.app-select {
    padding-right: 2.5rem;
}

select.app-input option,
select.app-select option {
    background: #1e2a46;
    color: var(--text);
}

.app-input:focus,
.app-select:focus,
.app-textarea:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent);
}

.app-input.invalid,
.app-select.invalid,
.app-textarea.invalid,
input.invalid,
select.invalid,
textarea.invalid {
    border-color: #f87171;
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.16);
}

.validation-message {
    display: block;
    margin-top: 0.35rem;
    color: #f87171;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.35;
}

.validation-errors {
    margin: 0.5rem 0 1rem;
    padding-left: 1.25rem;
    color: #f87171;
    font-size: 0.88rem;
    font-weight: 600;
}

.app-label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--heading);
    font-weight: 600;
}

.app-label-sm {
    font-size: 0.88rem;
    color: var(--text);
}

.app-help-text {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--text-muted);
}

.app-check-card {
    border: 1px solid var(--border);
    border-radius: 0.95rem;
    background: rgba(255, 255, 255, 0.035);
}

/* --- Table --- */
.app-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.72);
}

.app-table thead {
    background: rgba(255, 255, 255, 0.03);
}

.app-table tr + tr td {
    border-top: 1px solid var(--border);
}

/* --- Table Enhancements --- */
.app-table tbody tr {
    transition: background-color 0.15s ease;
}

.app-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

.app-table tbody tr.is-selected {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    border-left: 3px solid var(--accent);
}

.app-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.app-table th.sortable::after {
    content: "";
    display: inline-block;
    margin-left: 0.35rem;
    vertical-align: middle;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    opacity: 0.3;
}

.app-table th.sortable.sorted-asc::after {
    border-bottom: 5px solid var(--accent);
    opacity: 1;
}

.app-table th.sortable.sorted-desc::after {
    border-top: 5px solid var(--accent);
    opacity: 1;
}

/* --- Empty / Loading States --- */
.app-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

.app-empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.app-empty-state-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.app-empty-state-desc {
    font-size: 0.88rem;
    color: var(--text-muted);
    max-width: 24rem;
}

.app-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.app-loading::before {
    content: "";
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: app-spin 0.6s linear infinite;
}

@keyframes app-spin {
    to { transform: rotate(360deg); }
}

/* --- Badge --- */
.app-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--heading);
    font-size: 0.8rem;
    font-weight: 600;
}

/* --- Links --- */
.app-link {
    font-weight: 600;
}

.app-link:hover {
    text-decoration: underline;
}

.app-link-primary {
    color: #7dd3fc;
}

.app-link-danger {
    color: #fca5a5;
}

.app-link-accent {
    color: var(--accent);
}

/* --- Login --- */
.app-login-shell {
    min-height: 100vh;
    padding: 2rem 1rem;
    color: var(--text);
    background:
        radial-gradient(circle at top center, var(--bg-accent), transparent 28%),
        linear-gradient(180deg, #060c18 0%, var(--bg) 100%);
}

.app-login-card {
    width: 100%;
    max-width: 32rem;
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.95) 0%, rgba(17, 24, 39, 0.96) 100%);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(18px);
}

.app-login-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.app-login-logo {
    display: block;

    height: 4.5rem;
}

.app-login-title {
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--heading);
}

.app-login-input {
    width: 100%;
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.95rem;
    background: rgba(15, 23, 42, 0.8);
    color: var(--text);
}

.app-login-input::placeholder {
    color: var(--text-muted);
}

.app-login-button {
    width: 100%;
    padding: 0.9rem 1rem;
    border-radius: 1rem;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: var(--accent-contrast);
    font-weight: 700;
    box-shadow: 0 16px 34px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* ------------------------------------------------------------
   6. UTILITIES
   ------------------------------------------------------------ */
.app-text-muted {
    color: var(--text-muted);
}

.app-heading {
    color: var(--heading);
}

.app-border {
    border-color: var(--border);
}

.app-surface {
    background-color: var(--surface);
}

.app-hover:hover {
    background-color: var(--surface-strong);
}

.app-accent {
    color: var(--accent);
}

.app-bg-accent {
    background-color: var(--accent);
}

.app-text-success {
    color: #4ade80;
}

.app-text-warning {
    color: #fbbf24;
}

.app-text-orange {
    color: #FDC830;
}

.app-text-pink {
    color: #f472b6;
}

.app-page-title {
    margin-bottom: 1rem;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--heading);
}

.app-page-title-tight {
    margin-bottom: 0.25rem;
}

.app-page-subtitle {
    margin-bottom: 1rem;
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--text-muted);
}

.app-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.app-status-success {
    color: #86efac;
}

.app-status-warning {
    color: #fcd34d;
}

.app-status-danger {
    color: #fca5a5;
}

.app-status-info {
    color: #7dd3fc;
}

.app-muted {
    color: var(--text-muted);
}

/* ------------------------------------------------------------
   7. TAILWIND COMPATIBILITY LAYER
   ------------------------------------------------------------
   These overrides map legacy Tailwind utility classes to our
   CSS custom properties so that views using raw Tailwind
   classes still render correctly. Reduced !important usage
   by scoping under html.dark for higher specificity.
   ------------------------------------------------------------ */
html.dark .bg-gray-900 {
    background-color: var(--bg);
}

html.dark .bg-gray-800 {
    background-color: var(--surface);
}

html.dark .bg-gray-700 {
    background-color: var(--surface-strong);
}

html.dark .text-white {
    color: var(--heading);
}

html.dark .text-gray-200 {
    color: var(--text);
}

html.dark .text-gray-300,
html.dark .text-gray-400,
html.dark .text-gray-500 {
    color: var(--text-muted);
}

html.dark .text-cyan-400 {
    color: var(--accent);
}

html.dark .text-green-400 {
    color: #86efac;
}

html.dark .text-yellow-300,
html.dark .text-yellow-400,
html.dark .text-orange-300 {
    color: #E4B43B;
}

html.dark .text-pink-400 {
    color: #f9a8d4;
}

html.dark .border-gray-600,
html.dark .border-gray-700 {
    border-color: var(--border);
}

html.dark .shadow,
html.dark .shadow-lg,
html.dark .shadow-xl,
html.dark .shadow-2xl {
    box-shadow: var(--shadow-md);
}

html.dark .hover\:bg-gray-700:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

html.dark .hover\:text-white:hover {
    color: var(--heading);
}

html.dark .hover\:underline:hover {
    text-decoration: underline;
}

/* --- Missing text colors --- */
html.dark .text-red-400,
html.dark .text-red-300 {
    color: #fca5a5;
}

html.dark .text-red-200 {
    color: #fecaca;
}

html.dark .text-green-300 {
    color: #86efac;
}

html.dark .text-yellow-200 {
    color: #fef08a;
}

html.dark .text-cyan-300 {
    color: var(--accent);
}

html.dark .text-emerald-300 {
    color: #6ee7b7;
}

html.dark .text-pink-300 {
    color: #f9a8d4;
}

/* --- Background opacity variants --- */
html.dark .bg-gray-900\/50 {
    background-color: rgba(15, 23, 42, 0.5);
}

html.dark .bg-gray-900\/60 {
    background-color: rgba(15, 23, 42, 0.6);
}

html.dark .bg-white\/5 {
    background-color: rgba(255, 255, 255, 0.05);
}

html.dark .bg-white\/10 {
    background-color: rgba(255, 255, 255, 0.1);
}

html.dark .bg-black\/60 {
    background-color: rgba(0, 0, 0, 0.6);
}

/* --- Border opacity variants --- */
html.dark .border-cyan-500\/20 {
    border-color: color-mix(in srgb, var(--accent) 20%, transparent);
}

html.dark .border-red-500\/30 {
    border-color: rgba(239, 68, 68, 0.3);
}

html.dark .border-red-500\/10 {
    border-color: rgba(239, 68, 68, 0.1);
}

html.dark .border-red-500\/20 {
    border-color: rgba(239, 68, 68, 0.2);
}

/* --- Danger/warning backgrounds --- */
html.dark .bg-red-500\/10 {
    background-color: rgba(239, 68, 68, 0.1);
}

html.dark .bg-yellow-500\/10 {
    background-color: rgba(234, 179, 8, 0.1);
}

/* --- Hover variants --- */
html.dark .hover\:text-cyan-400:hover {
    color: var(--accent);
}

html.dark .hover\:bg-red-500\/20:hover {
    background-color: rgba(239, 68, 68, 0.2);
}

html.dark .hover\:text-red-200:hover {
    color: #fecaca;
}

/* --- Gradient class for admin hero banner --- */
html.dark .app-gradient-hero {
    background: linear-gradient(135deg, var(--bg) 0%, var(--surface-strong) 50%, color-mix(in srgb, var(--accent) 12%, var(--bg)) 100%);
    border-color: color-mix(in srgb, var(--accent) 20%, transparent);
}

/* ------------------------------------------------------------
   8. SCROLLBAR
   ------------------------------------------------------------ */
.app-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--accent) 45%, #334155) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 34%, #334155);
}

*::-webkit-scrollbar-track {
    background: transparent;
}

/* ------------------------------------------------------------
   9. RESPONSIVE
   ------------------------------------------------------------ */
@media (max-width: 1023px) {
    body:has(#app-sidebar[data-open="true"]) {
        overflow: hidden;
    }

    .app-page-shell::before {
        inset: -0.5rem 0 auto;
        height: 8rem;
    }
}
