/* ============================================================
   Junta de Vecinos La Foresta de Zapallar — app.css
   ============================================================
   Mobile-first, WCAG AAA contrast, large touch targets (48px).
   Designed for broad demographics including older adults.
   Fonts: Sora (headings) + DM Sans (body) loaded in base.html.
   ============================================================ */


/* ==========================================================
   1. RESET
   ========================================================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img, picture, video, canvas {
    display: block;
    max-width: 100%;
}

/* SVGs: inline by default for icon usage */
svg {
    display: inline-block;
    max-width: 100%;
    vertical-align: middle;
}

input, button, textarea, select {
    font: inherit;
}

table {
    border-collapse: collapse;
    width: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

ul, ol {
    list-style: none;
}

fieldset {
    border: none;
    padding: 0;
}

dialog {
    padding: 0;
}

/* Remove default focus outline — we apply our own */
:focus {
    outline: none;
}


/* ==========================================================
   2. CSS VARIABLES
   ========================================================== */

:root {
    /* --- Primary (Verde bosque) --- */
    --primary: #2D6A4F;
    --primary-dark: #1B4332;
    --primary-light: #52B788;
    --primary-lighter: #95D5B2;
    --primary-bg: #F0FDF4;

    /* --- Secondary (Arena) --- */
    --secondary: #B08968;
    --secondary-dark: #7F5539;
    --secondary-light: #DDB892;

    /* --- Accent (Oceano) --- */
    --accent: #457B9D;
    --accent-dark: #1D3557;
    --accent-light: #A8DADC;

    /* --- Surfaces --- */
    --bg: #FAFAF5;
    --bg-card: #FFFFFF;
    --bg-muted: #F8FAFC;
    --bg-hover: #F1F5F9;
    --border: #E2E8F0;
    --border-light: #F1F5F9;

    /* --- Text --- */
    --text: #1A1A1A;
    --text-secondary: #4A5568;
    --text-muted: #64748B;
    --text-light: #94A3B8;
    --text-on-primary: #FFFFFF;
    --text-on-dark: #FFFFFF;

    /* --- Semantic --- */
    --success: #16A34A;
    --success-bg: #F0FDF4;
    --success-border: #16A34A;
    --success-text: #166534;

    --warning: #D97706;
    --warning-bg: #FFFBEB;
    --warning-border: #D97706;
    --warning-text: #92400E;

    --danger: #DC2626;
    --danger-bg: #FEF2F2;
    --danger-border: #DC2626;
    --danger-text: #991B1B;

    --info: #2563EB;
    --info-bg: #EFF6FF;
    --info-border: #2563EB;
    --info-text: #1E40AF;

    /* --- Typography --- */
    --font-heading: 'Sora', system-ui, -apple-system, sans-serif;
    --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

    --text-xs: 0.75rem;    /* 12px */
    --text-sm: 0.875rem;   /* 14px */
    --text-base: 1.125rem; /* 18px */
    --text-lg: 1.25rem;    /* 20px */
    --text-xl: 1.5rem;     /* 24px */
    --text-2xl: 1.875rem;  /* 30px */
    --text-3xl: 2.25rem;   /* 36px */
    --text-4xl: 3rem;      /* 48px */

    --leading-tight: 1.25;
    --leading-normal: 1.7;
    --tracking-tight: -0.02em;

    /* --- Spacing --- */
    --sp-1: 0.25rem;  /* 4px */
    --sp-2: 0.5rem;   /* 8px */
    --sp-3: 0.75rem;  /* 12px */
    --sp-4: 1rem;     /* 16px */
    --sp-5: 1.25rem;  /* 20px */
    --sp-6: 1.5rem;   /* 24px */
    --sp-8: 2rem;     /* 32px */
    --sp-10: 2.5rem;  /* 40px */
    --sp-12: 3rem;    /* 48px */
    --sp-16: 4rem;    /* 64px */

    /* --- Borders --- */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* --- Shadows --- */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 12px 36px rgba(0, 0, 0, 0.16);
    --shadow-inner: inset 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-up: 0 -2px 10px rgba(0, 0, 0, 0.05);

    /* --- Transitions --- */
    --ease-fast: 150ms ease;
    --ease: 200ms ease;
    --ease-slow: 350ms ease;

    /* --- Layout --- */
    --navbar-h: 64px;
    --sidebar-w: 260px;
    --tab-bar-h: 64px;
    --container: 1200px;

    /* --- Focus ring --- */
    --ring: 0 0 0 3px rgba(45, 106, 79, 0.15);
    --ring-offset: 2px;
}


/* ==========================================================
   3. TYPOGRAPHY
   ========================================================== */

body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text);
    background-color: var(--bg);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-tight);
    color: var(--text);
    margin-bottom: var(--sp-4);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); font-weight: 600; }

p {
    margin-bottom: var(--sp-4);
    color: var(--text-secondary);
}

p:last-child {
    margin-bottom: 0;
}

strong, b {
    font-weight: 700;
}

small {
    font-size: var(--text-sm);
}

/* Links */
a:not(.btn):not(.nav-link):not(.sidebar-link):not(.tab-link):not(.pagination-link):not(.navbar-brand):not([role="menuitem"]) {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    transition: color var(--ease-fast);
}

/* Exclude navbar links from generic link styling */
.navbar-links a,
.navbar-brand,
.navbar-actions a,
.tab-bar a {
    text-decoration: none;
}

a:not(.btn):not(.nav-link):not(.sidebar-link):not(.tab-link):not(.pagination-link):not(.navbar-brand):not([role="menuitem"]):hover {
    color: var(--primary-dark);
    text-decoration-thickness: 2px;
}

a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: var(--ring-offset);
    border-radius: var(--radius-sm);
}

/* Selection */
::selection {
    background: rgba(45, 106, 79, 0.15);
    color: var(--text);
}

/* Lists inside content areas */
.content ul,
.content ol {
    margin-bottom: var(--sp-4);
    padding-left: var(--sp-6);
}

.content ul {
    list-style: disc;
}

.content ol {
    list-style: decimal;
}

.content li {
    margin-bottom: var(--sp-2);
    color: var(--text-secondary);
}

/* Code */
code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 2px 6px;
    background: var(--bg-muted);
    border-radius: var(--radius-sm);
    color: var(--primary-dark);
}

pre {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    padding: var(--sp-4);
    background: var(--bg-muted);
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: var(--sp-4);
}

pre code {
    padding: 0;
    background: none;
}

/* Horizontal rule */
hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: var(--sp-6) 0;
}


/* ==========================================================
   4. LAYOUT
   ========================================================== */

/* Container */
.container {
    width: 100%;
    max-width: var(--container);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--sp-6);
    padding-right: var(--sp-6);
}

.container-sm {
    max-width: 640px;
}

.container-md {
    max-width: 768px;
}

/* Main content wrapper — pushes footer down */
.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    padding-top: var(--sp-6);
    padding-bottom: var(--sp-12);
}

/* Admin layout with sidebar */
.admin-layout,
.layout-admin {
    display: flex;
    min-height: calc(100vh - var(--navbar-h));
}

.admin-content {
    flex: 1;
    min-width: 0; /* Prevent flex overflow */
    padding: var(--sp-8);
}

/* Admin header user info */
.admin-header-user {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

/* Admin content with tab bar padding */
.has-tab-bar {
    padding-bottom: calc(var(--tab-bar-h) + var(--sp-6));
}

@media (min-width: 1024px) {
    .has-tab-bar {
        padding-bottom: var(--sp-8);
    }
}

/* Breadcrumb navigation */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-bottom: var(--sp-6);
    padding: var(--sp-2) 0;
}

.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.breadcrumb a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.breadcrumb .separator {
    color: var(--text-light);
}

.breadcrumb .current {
    color: var(--text);
    font-weight: 600;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--sp-4);
    margin-bottom: var(--sp-8);
}

.page-title {
    margin-bottom: 0;
}

.page-header h1 {
    margin-bottom: 0;
}

.page-header p {
    font-size: var(--text-lg);
    color: var(--text-muted);
    margin-bottom: 0;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

/* Section */
.section {
    margin-bottom: var(--sp-12);
}

.section-title {
    font-size: var(--text-xl);
    margin-bottom: var(--sp-6);
    padding-bottom: var(--sp-3);
    border-bottom: 2px solid var(--border);
}

/* Grid system */
.grid-2,
.grid-3,
.grid-4 {
    display: grid;
    gap: var(--sp-6);
}

.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr; }


/* ==========================================================
   5. NAVBAR
   ========================================================== */

.navbar {
    background: var(--primary-dark);
    height: var(--navbar-h);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.navbar .container,
.navbar-inner {
    display: flex;
    align-items: center;
    height: 100%;
    gap: var(--sp-4);
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--sp-4);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-on-primary);
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: var(--tracking-tight);
    text-decoration: none;
}

.navbar-brand img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
}

.navbar-brand:hover {
    color: var(--text-on-primary);
}

.navbar-nav,
.navbar-links {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex: 1;
}

.navbar-nav::-webkit-scrollbar,
.navbar-links::-webkit-scrollbar {
    display: none;
}

/* Links inside navbar-links (public nav) — high specificity to override generic a{} rule */
.navbar .navbar-links a {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 8px 16px;
    color: #FFFFFF !important;
    font-size: var(--text-base);
    font-weight: 600;
    white-space: nowrap;
    border-radius: var(--radius-sm);
    transition: background var(--ease-fast), color var(--ease-fast);
    text-decoration: none !important;
}

.navbar .navbar-links a:hover {
    color: #FFFFFF !important;
    background: rgba(255, 255, 255, 0.15);
}

.navbar .navbar-links a.active {
    color: #FFFFFF !important;
    background: rgba(255, 255, 255, 0.22);
    font-weight: 700;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 8px 16px;
    color: #FFFFFF;
    font-size: var(--text-base);
    font-weight: 600;
    white-space: nowrap;
    border-radius: var(--radius-sm);
    transition: background var(--ease-fast), color var(--ease-fast);
    text-decoration: none;
}

.nav-link:hover {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.15);
}

.nav-link.active {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.22);
    font-weight: 700;
}

/* SVG icons inside nav links */
.nav-icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.nav-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

/* Navbar actions (right side) */
.navbar-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-left: auto;
    flex-shrink: 0;
}

/* User avatar / badge in navbar */
.navbar-user {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 6px 12px;
    color: var(--text-on-dark);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: background var(--ease-fast);
}

.navbar-user:hover {
    background: rgba(255, 255, 255, 0.1);
}


/* ==========================================================
   6. SIDEBAR (Admin)
   ========================================================== */

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    height: calc(100vh - var(--navbar-h));
    position: sticky;
    top: var(--navbar-h);
    overflow-y: auto;
    padding: var(--sp-4) 0;
    flex-shrink: 0;
}

.sidebar-section {
    margin-bottom: var(--sp-6);
}

.sidebar-heading,
.sidebar-section-title {
    padding: var(--sp-2) var(--sp-5);
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--sp-1);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    margin: 0 var(--sp-2);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius);
    transition: all var(--ease-fast);
    text-decoration: none;
    position: relative;
}

.sidebar-link:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 600;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--primary);
    border-radius: 0 2px 2px 0;
}

.sidebar-icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.sidebar-link.active .sidebar-icon {
    color: var(--primary);
}

.sidebar-icon svg {
    width: 100%;
    height: 100%;
}

/* Sidebar badge (counts) */
.sidebar-badge {
    margin-left: auto;
    font-size: var(--text-xs);
    font-weight: 600;
    background: var(--bg-muted);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.sidebar-link.active .sidebar-badge {
    background: rgba(45, 106, 79, 0.1);
    color: var(--primary);
}

/* Sidebar divider */
.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: var(--sp-4) var(--sp-5);
}


/* ==========================================================
   7. TAB BAR (Mobile bottom navigation)
   ========================================================== */

.tab-bar {
    display: none; /* Hidden on desktop, shown via media query */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tab-bar-h);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-up);
    z-index: 100;
    align-items: center;
    justify-content: space-around;
    padding: 0 var(--sp-2);
}

.tab-bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 100%;
    padding: 0 var(--sp-2);
}

/* Direct links in tab-bar (no wrapper needed) */
.tab-bar > a,
.tab-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--sp-1) var(--sp-2);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--radius);
    transition: color var(--ease-fast);
    min-width: 56px;
    flex: 1;
}

.tab-bar > a:hover,
.tab-link:hover {
    color: var(--text-secondary);
}

.tab-bar > a.active,
.tab-link.active {
    color: var(--primary);
    font-weight: 600;
}

.tab-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-icon svg {
    width: 22px;
    height: 22px;
}

.tab-label {
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
}


/* ==========================================================
   8. CARDS
   ========================================================== */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-6);
    transition: box-shadow var(--ease);
}

.card:hover {
    box-shadow: var(--shadow);
}

/* Clickable card */
a.card,
.card-clickable {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

a.card:hover,
.card-clickable:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary-lighter);
}

/* Card header */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: var(--sp-4);
    margin-bottom: var(--sp-4);
    border-bottom: 1px solid var(--border-light);
}

.card-header h2,
.card-header h3,
.card-header h4 {
    margin-bottom: 0;
}

/* Card body */
.card-body {
    flex: 1;
}

/* Card footer */
.card-footer {
    padding-top: var(--sp-4);
    margin-top: var(--sp-4);
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-3);
}

/* Card with no padding (for tables, lists inside) */
.card-flush {
    padding: 0;
}

.card-flush .card-header {
    padding: var(--sp-4) var(--sp-6);
    margin-bottom: 0;
}

.card-flush .card-body {
    padding: 0;
}

.card-flush .card-footer {
    padding: var(--sp-4) var(--sp-6);
    margin-top: 0;
}

/* Colored top border variant */
.card-accent {
    border-top: 3px solid var(--primary);
}

.card-accent-warning {
    border-top: 3px solid var(--warning);
}

.card-accent-danger {
    border-top: 3px solid var(--danger);
}

.card-accent-info {
    border-top: 3px solid var(--info);
}


/* ==========================================================
   9. STAT CARDS (Dashboard)
   ========================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--sp-6);
    margin-bottom: var(--sp-8);
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-6);
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    transition: box-shadow var(--ease), transform var(--ease);
}

.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.5rem;
}

.stat-icon svg {
    width: 24px;
    height: 24px;
}

/* Icon background variants */
.stat-icon-green {
    background: var(--primary-bg);
    color: var(--primary);
}

.stat-icon-blue {
    background: var(--info-bg);
    color: var(--info);
}

.stat-icon-amber {
    background: var(--warning-bg);
    color: var(--warning);
}

.stat-icon-red {
    background: var(--danger-bg);
    color: var(--danger);
}

.stat-icon-sand {
    background: #FDF2E9;
    color: var(--secondary-dark);
}

.stat-content {
    min-width: 0;
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: var(--tracking-tight);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    font-weight: 500;
    line-height: 1.3;
    margin-top: 2px;
}

/* Stat delta (change indicator) */
.stat-delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-xs);
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    margin-top: var(--sp-1);
}

.stat-delta-up {
    background: #DCFCE7;
    color: #166534;
}

.stat-delta-down {
    background: #FEE2E2;
    color: #991B1B;
}


/* ==========================================================
   10. BUTTONS
   ========================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: 48px;
    padding: 12px 24px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--ease);
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: var(--ring-offset);
}

.btn:disabled,
.btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary */
.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-primary:active {
    background: #153B28;
}

/* Secondary */
.btn-secondary {
    background: var(--bg-card);
    color: #374151;
    border-color: #D1D5DB;
}

.btn-secondary:hover {
    background: #F9FAFB;
    border-color: #9CA3AF;
}

.btn-secondary:active {
    background: #F3F4F6;
}

/* Danger */
.btn-danger {
    background: var(--danger);
    color: var(--text-on-primary);
    border-color: var(--danger);
}

.btn-danger:hover {
    background: #B91C1C;
    border-color: #B91C1C;
}

.btn-danger:active {
    background: #991B1B;
}

/* Ghost (no bg, no border) */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* Outline primary */
.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: var(--text-on-primary);
}

/* Sizes */
.btn-sm {
    min-height: 36px;
    padding: 6px 16px;
    font-size: var(--text-sm);
    border-radius: var(--radius-sm);
}

.btn-lg {
    min-height: 56px;
    padding: 16px 32px;
    font-size: var(--text-lg);
    border-radius: var(--radius-lg);
}

/* Full width */
.btn-block {
    display: flex;
    width: 100%;
}

/* Icon inside button */
.btn-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.btn-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

/* Icon-only button */
.btn-icon-only {
    min-height: 44px;
    min-width: 44px;
    padding: 10px;
}

/* Button group */
.btn-group {
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
}


/* ==========================================================
   11. FORMS
   ========================================================== */

.form-group {
    margin-bottom: var(--sp-5);
}

.form-label {
    display: block;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
    font-size: var(--text-sm);
}

.form-label-required::after {
    content: ' *';
    color: var(--danger);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    border: 1px solid #D1D5DB;
    border-radius: var(--radius);
    font-size: 1rem;
    color: var(--text);
    background: var(--bg-card);
    transition: border-color var(--ease-fast), box-shadow var(--ease-fast);
    -webkit-appearance: none;
    appearance: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-light);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
    outline: none;
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
    background: var(--bg-muted);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Error state */
.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
    border-color: var(--danger);
}

.form-input.is-invalid:focus,
.form-select.is-invalid:focus,
.form-textarea.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.form-error {
    display: block;
    color: var(--danger-text);
    font-size: var(--text-sm);
    margin-top: var(--sp-1);
    font-weight: 500;
}

/* Success state */
.form-input.is-valid {
    border-color: var(--success);
}

/* Help text */
.form-help {
    display: block;
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin-top: var(--sp-1);
}

/* Select dropdown arrow */
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='%2364748B'%3E%3Cpath d='M4.427 6.427l3.396 3.396a.25.25 0 00.354 0l3.396-3.396A.25.25 0 0011.396 6H4.604a.25.25 0 00-.177.427z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

/* Textarea */
.form-textarea {
    min-height: 120px;
    resize: vertical;
}

/* Checkbox & Radio */
.form-check {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    margin-bottom: var(--sp-3);
    cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-top: 2px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.form-check-label {
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

/* Input group (input + button side by side) */
.input-group {
    display: flex;
    gap: 0;
}

.input-group .form-input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.input-group .btn {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* File input */
.form-file {
    padding: var(--sp-3);
}

.form-file::file-selector-button {
    padding: 8px 16px;
    margin-right: var(--sp-3);
    border: 1px solid #D1D5DB;
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--ease-fast);
}

.form-file::file-selector-button:hover {
    background: var(--bg-hover);
}

/* Form layout helpers */
.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-4);
}


/* ==========================================================
   12. TABLES
   ========================================================== */

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead th {
    background: var(--bg-muted);
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    font-size: var(--text-xs);
    letter-spacing: 0.05em;
    padding: var(--sp-3) var(--sp-4);
    text-align: left;
    white-space: nowrap;
    border-bottom: 2px solid var(--border);
}

.table tbody td {
    padding: var(--sp-3) var(--sp-4);
    color: #334155;
    border-bottom: 1px solid var(--border-light);
    font-size: var(--text-sm);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background: var(--bg-muted);
}

/* Striped */
.table-striped tbody tr:nth-child(even) {
    background: var(--bg-muted);
}

/* Compact */
.table-compact thead th,
.table-compact tbody td {
    padding: var(--sp-2) var(--sp-3);
}

/* Table inside flush card */
.card-flush .table thead th:first-child {
    padding-left: var(--sp-6);
}

.card-flush .table thead th:last-child {
    padding-right: var(--sp-6);
}

.card-flush .table tbody td:first-child {
    padding-left: var(--sp-6);
}

.card-flush .table tbody td:last-child {
    padding-right: var(--sp-6);
}


/* ==========================================================
   13. BADGES
   ========================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

.badge-success {
    background: #DCFCE7;
    color: #166534;
}

.badge-warning {
    background: #FEF3C7;
    color: #92400E;
}

.badge-danger {
    background: #FEE2E2;
    color: #991B1B;
}

.badge-info {
    background: #DBEAFE;
    color: #1E40AF;
}

.badge-neutral {
    background: #F1F5F9;
    color: #475569;
}

.badge-primary {
    background: var(--primary-bg);
    color: var(--primary);
}

/* Large badge */
.badge-lg {
    padding: 4px 14px;
    font-size: var(--text-sm);
}

/* Badge with dot indicator */
.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
}

.badge-success.badge-dot::before { background: #16A34A; }
.badge-warning.badge-dot::before { background: #D97706; }
.badge-danger.badge-dot::before { background: #DC2626; }
.badge-info.badge-dot::before { background: #2563EB; }


/* ==========================================================
   14. ALERTS
   ========================================================== */

.alert {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 16px 20px;
    border-radius: var(--radius);
    border-left: 4px solid;
    margin-bottom: var(--sp-4);
    font-size: var(--text-sm);
    line-height: 1.6;
}

.alert p {
    margin-bottom: 0;
    color: inherit;
}

.alert-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.alert-error {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger-text);
}

.alert-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.alert-info {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info-text);
}

.alert-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.alert-icon svg {
    width: 18px;
    height: 18px;
}

.alert-content {
    flex: 1;
    min-width: 0;
}

/* Dismiss button inside alert */
.alert-dismiss {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--sp-1);
    color: inherit;
    opacity: 0.6;
    transition: opacity var(--ease-fast);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.alert-dismiss:hover {
    opacity: 1;
}

/* Flash messages container */
.flash-messages {
    padding: var(--sp-3) var(--sp-4);
    max-width: var(--container);
    margin: 0 auto;
}


/* ==========================================================
   15. PROGRESS BARS
   ========================================================== */

.progress-bar {
    height: 8px;
    background: #E2E8F0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-lg {
    height: 12px;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
    min-width: 0;
}

.progress-fill.green {
    background: var(--primary);
}

.progress-fill.yellow {
    background: var(--warning);
}

.progress-fill.red {
    background: var(--danger);
}

.progress-fill.blue {
    background: var(--info);
}

/* Progress with label */
.progress-labeled {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.progress-labeled .progress-bar {
    flex: 1;
}

.progress-percent {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 3ch;
    text-align: right;
}

/* Lot coverage progress (specific use case) */
.lote-progress {
    margin-top: var(--sp-2);
}

.lote-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-1);
}

.lote-progress-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.lote-progress-value {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
}


/* ==========================================================
   16. CHARTS (CSS-only bar chart)
   ========================================================== */

.chart-container {
    padding: var(--sp-4) 0;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 200px;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.chart-bar {
    flex: 1;
    min-width: 30px;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    position: relative;
    transition: height 0.5s ease, background var(--ease-fast);
    cursor: default;
}

.chart-bar:hover {
    background: var(--primary-dark);
}

.chart-bar-secondary {
    background: var(--secondary);
}

.chart-bar-secondary:hover {
    background: var(--secondary-dark);
}

.chart-label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.chart-value {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Y-axis labels */
.chart-y-axis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 200px;
    padding-right: var(--sp-2);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-align: right;
    min-width: 40px;
}

.chart-wrapper {
    display: flex;
    gap: var(--sp-2);
}

.chart-wrapper .chart-bars {
    flex: 1;
}

/* Legend */
.chart-legend {
    display: flex;
    gap: var(--sp-4);
    margin-top: var(--sp-4);
    justify-content: center;
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.chart-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}


/* ==========================================================
   17. PAGINATION
   ========================================================== */

.pagination {
    display: flex;
    gap: var(--sp-2);
    justify-content: center;
    align-items: center;
    margin-top: var(--sp-6);
}

.pagination a,
.pagination span,
.pagination-link {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--ease-fast);
    border: 1px solid transparent;
}

.pagination a:hover,
.pagination-link:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.pagination .active,
.pagination-link.active {
    background: var(--primary);
    color: var(--text-on-primary);
    font-weight: 600;
}

.pagination .disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Pagination info text */
.pagination-info {
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-align: center;
    margin-top: var(--sp-2);
}


/* ==========================================================
   18. FOOTER
   ========================================================== */

.footer {
    background: var(--primary-dark);
    padding: var(--sp-12) 0 var(--sp-6) 0;
    color: #C8E6C9;
    margin-top: auto;
}

.footer h3,
.footer h4,
.footer h5 {
    color: var(--text-on-primary);
    margin-bottom: var(--sp-4);
}

.footer p {
    color: #C8E6C9;
    font-size: var(--text-sm);
    line-height: 1.7;
}

.footer a {
    color: #E8F5E9;
    text-decoration: none;
    transition: color var(--ease-fast);
}

.footer a:hover {
    color: #FFFFFF;
    text-decoration: underline;
}

.footer-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-8);
    margin-bottom: var(--sp-8);
}

.footer-bottom {
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    padding-top: var(--sp-6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
    text-align: center;
}

.footer-bottom p {
    margin-bottom: 0;
    font-size: var(--text-xs);
    color: #A5D6A7;
}

/* Footer list of links */
.footer-links {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.footer-links a {
    font-size: var(--text-sm);
    padding: var(--sp-1) 0;
}


/* ==========================================================
   19. MODAL / DIALOG
   ========================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin-bottom: 0;
}

.modal-body {
    padding: var(--sp-6);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-6);
    border-top: 1px solid var(--border);
}


/* ==========================================================
   20. EMPTY STATES
   ========================================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--sp-12) var(--sp-6);
    text-align: center;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    color: var(--text-light);
    margin-bottom: var(--sp-4);
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: var(--sp-2);
}

.empty-state p {
    color: var(--text-muted);
    max-width: 360px;
    margin-bottom: var(--sp-6);
}


/* ==========================================================
   21. AVATARS
   ========================================================== */

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-sm {
    width: 32px;
    height: 32px;
}

.avatar-lg {
    width: 56px;
    height: 56px;
}

.avatar-xl {
    width: 80px;
    height: 80px;
}

/* Avatar placeholder (initials) */
.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-bg);
    color: var(--primary);
    font-weight: 700;
    font-size: var(--text-sm);
}

.avatar-placeholder.avatar-lg {
    font-size: var(--text-lg);
}

/* Directorio avatar — circular frame with green accent */
.avatar-directorio {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    border: 4px solid #52B788;
    box-shadow: 0 4px 16px rgba(27, 67, 50, 0.25),
                0 0 0 4px rgba(82, 183, 136, 0.12);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    margin: 0 auto;
    flex-shrink: 0;
}
.avatar-directorio:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(27, 67, 50, 0.35),
                0 0 0 6px rgba(82, 183, 136, 0.18);
}
.avatar-directorio img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.avatar-directorio--placeholder {
    background: linear-gradient(135deg, #2D6A4F, #40916C);
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-directorio__initials {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}


/* ==========================================================
   22. DROPDOWN
   ========================================================== */

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 50;
    min-width: 200px;
    margin-top: var(--sp-1);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-1) 0;
    display: none;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--ease-fast);
    text-decoration: none;
}

.dropdown-item:hover {
    background: var(--bg-muted);
    color: var(--text);
}

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: var(--sp-1) 0;
}


/* ==========================================================
   23. TOAST / NOTIFICATION
   ========================================================== */

.toast-container {
    position: fixed;
    top: calc(var(--navbar-h) + var(--sp-4));
    right: var(--sp-4);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    max-width: 400px;
    width: calc(100% - var(--sp-8));
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-4);
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    animation: slideInRight 0.3s ease;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info { border-left: 4px solid var(--info); }


/* ==========================================================
   24. TABS (content tabs, not bottom tab bar)
   ========================================================== */

.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: var(--sp-6);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab {
    padding: var(--sp-3) var(--sp-5);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--ease-fast), border-color var(--ease-fast);
    text-decoration: none;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}


/* ==========================================================
   25. LISTS
   ========================================================== */

/* Item list (e.g., list of vecinos, certificados) */
.list-item {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    padding: var(--sp-4);
    border-bottom: 1px solid var(--border-light);
    transition: background var(--ease-fast);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: var(--bg-muted);
}

.list-item-content {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.list-item-subtitle {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.list-item-actions {
    display: flex;
    gap: var(--sp-2);
    flex-shrink: 0;
}

/* Description list */
.desc-list dt {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: var(--sp-1);
}

.desc-list dd {
    color: var(--text);
    margin-bottom: var(--sp-4);
}


/* ==========================================================
   26. TIMELINE
   ========================================================== */

.timeline {
    position: relative;
    padding-left: var(--sp-8);
}

.timeline::before {
    content: '';
    position: absolute;
    left: 11px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: var(--sp-6);
}

.timeline-dot {
    position: absolute;
    left: calc(-1 * var(--sp-8) + 4px);
    top: 4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--primary);
}

.timeline-dot-success { border-color: var(--success); }
.timeline-dot-danger { border-color: var(--danger); }
.timeline-dot-warning { border-color: var(--warning); }

.timeline-time {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: var(--sp-1);
}

.timeline-content {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}


/* ==========================================================
   27. UTILITIES
   ========================================================== */

/* --- Text alignment --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

/* --- Text size --- */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: 2rem; }
.text-3xl { font-size: var(--text-3xl); }

/* --- Font weight --- */
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* --- Text color --- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success-text); }
.text-danger { color: var(--danger-text); }
.text-warning { color: var(--warning-text); }
.text-info { color: var(--info-text); }
.text-primary { color: var(--primary); }
.text-white { color: var(--text-on-primary); }

/* --- Background --- */
.bg-muted { background: var(--bg-muted); }
.bg-primary { background: var(--primary); }
.bg-primary-light { background: var(--primary-bg); }
.bg-white { background: var(--bg-card); }

/* --- Margins --- */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--sp-1); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }
.mb-6 { margin-bottom: var(--sp-6); }
.mb-8 { margin-bottom: var(--sp-8); }

.ml-0 { margin-left: 0; }
.ml-1 { margin-left: var(--sp-1); }
.ml-2 { margin-left: var(--sp-2); }
.ml-3 { margin-left: var(--sp-3); }
.ml-4 { margin-left: var(--sp-4); }
.ml-auto { margin-left: auto; }

.mr-0 { margin-right: 0; }
.mr-1 { margin-right: var(--sp-1); }
.mr-2 { margin-right: var(--sp-2); }
.mr-3 { margin-right: var(--sp-3); }
.mr-4 { margin-right: var(--sp-4); }
.mr-auto { margin-right: auto; }

.mx-auto { margin-left: auto; margin-right: auto; }
.my-4 { margin-top: var(--sp-4); margin-bottom: var(--sp-4); }
.my-6 { margin-top: var(--sp-6); margin-bottom: var(--sp-6); }
.my-8 { margin-top: var(--sp-8); margin-bottom: var(--sp-8); }

/* --- Padding --- */
.p-0 { padding: 0; }
.p-1 { padding: var(--sp-1); }
.p-2 { padding: var(--sp-2); }
.p-3 { padding: var(--sp-3); }
.p-4 { padding: var(--sp-4); }
.p-5 { padding: var(--sp-5); }
.p-6 { padding: var(--sp-6); }
.p-8 { padding: var(--sp-8); }

.px-4 { padding-left: var(--sp-4); padding-right: var(--sp-4); }
.px-6 { padding-left: var(--sp-6); padding-right: var(--sp-6); }
.py-2 { padding-top: var(--sp-2); padding-bottom: var(--sp-2); }
.py-4 { padding-top: var(--sp-4); padding-bottom: var(--sp-4); }
.py-6 { padding-top: var(--sp-6); padding-bottom: var(--sp-6); }
.py-8 { padding-top: var(--sp-8); padding-bottom: var(--sp-8); }

/* --- Display --- */
.hidden { display: none; }
.block { display: block; }
.inline-block { display: inline-block; }
.inline-flex { display: inline-flex; }

/* --- Flex --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }
.gap-8 { gap: var(--sp-8); }

/* --- Width --- */
.w-full { width: 100%; }
.max-w-sm { max-width: 24rem; }
.max-w-md { max-width: 28rem; }
.max-w-lg { max-width: 32rem; }
.max-w-xl { max-width: 36rem; }
.min-w-0 { min-width: 0; }

/* --- Overflow --- */
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }

/* --- Border --- */
.border { border: 1px solid var(--border); }
.border-t { border-top: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.rounded { border-radius: var(--radius); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

/* --- Shadow --- */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow { box-shadow: var(--shadow); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-none { box-shadow: none; }

/* --- Position --- */
.relative { position: relative; }
.absolute { position: absolute; }
.sticky { position: sticky; }

/* --- Screen reader only --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* --- Skip link (visible only on focus) --- */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--sp-4);
    z-index: 9999;
    padding: var(--sp-3) var(--sp-6);
    background: var(--primary);
    color: var(--text-on-primary);
    border-radius: 0 0 var(--radius) var(--radius);
    font-weight: 600;
    text-decoration: none;
    transition: top var(--ease-fast);
}

.skip-link:focus {
    top: 0;
}

/* --- Truncate --- */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* --- Cursor --- */
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }

/* --- Opacity --- */
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }

/* --- Divider --- */
.divider {
    height: 1px;
    background: var(--border);
    margin: var(--sp-6) 0;
}

/* --- Visually separate sections --- */
.section-gap {
    margin-bottom: var(--sp-8);
}


/* ==========================================================
   28. HTMX & ANIMATIONS
   ========================================================== */

/* Fade in */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.2s ease forwards;
}

/* Slide in from right (toasts) */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Slide up (modals) */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* HTMX transitions */
.htmx-settling {
    animation: fadeIn 0.2s ease forwards;
}

.htmx-swapping {
    opacity: 0;
    transition: opacity 0.1s ease;
}

.htmx-added {
    animation: fadeIn 0.3s ease forwards;
}

/* Loading indicator */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-flex;
}

/* Spinner */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* Skeleton loading */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-muted) 25%, var(--bg-hover) 50%, var(--bg-muted) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius);
}

.skeleton-text {
    height: 1em;
    margin-bottom: var(--sp-2);
}

.skeleton-heading {
    height: 1.5em;
    width: 60%;
    margin-bottom: var(--sp-4);
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* Pulse (for notification dots) */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}


/* ==========================================================
   29. PRINT
   ========================================================== */

@media print {
    /* Hide non-essential UI */
    .navbar,
    .sidebar,
    .tab-bar,
    .footer,
    .btn,
    .btn-group,
    .toast-container,
    .dropdown-menu,
    .modal-backdrop,
    .pagination,
    .no-print {
        display: none !important;
    }

    /* Reset layout */
    body {
        background: white;
        color: black;
        font-size: 12pt;
    }

    .app-wrapper {
        min-height: auto;
    }

    .admin-layout,
    .layout-admin {
        display: block;
    }

    .admin-content {
        padding: 0;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    /* Cards print flat */
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    /* Links show URL */
    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }

    a.btn[href]::after {
        content: none;
    }

    /* Tables */
    .table thead th {
        background: #f0f0f0 !important;
    }
}


/* ==========================================================
   30. RESPONSIVE
   ========================================================== */

/* --- Mobile: up to 639px (default — mobile first) --- */

/* Mobile: show tab bar, hide sidebar */
@media (max-width: 639px) {
    .tab-bar {
        display: flex;
    }

    .sidebar {
        display: none;
    }

    /* Add bottom padding for tab bar */
    .app-main {
        padding-bottom: calc(var(--tab-bar-h) + var(--sp-6));
    }

    /* Full-width cards on mobile */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Compact header on mobile */
    h1 { font-size: var(--text-2xl); }
    h2 { font-size: var(--text-xl); }

    /* Stack form rows */
    .form-row {
        grid-template-columns: 1fr;
    }

    /* Container padding */
    .container {
        padding-left: var(--sp-4);
        padding-right: var(--sp-4);
    }

    /* Admin content padding */
    .admin-content {
        padding: var(--sp-4);
    }

    /* Button sizes on mobile */
    .btn {
        font-size: 1rem;
    }

    /* Footer single column */
    .footer-grid {
        grid-template-columns: 1fr;
        gap: var(--sp-6);
    }

    /* Navbar compact */
    .navbar .container {
        padding-left: var(--sp-3);
        padding-right: var(--sp-3);
    }

    .navbar-brand {
        font-size: var(--text-base);
    }
}

/* --- Small phone: up to 479px --- */
@media (max-width: 479px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Stack button groups */
    .btn-group {
        flex-direction: column;
    }

    .btn-group .btn {
        width: 100%;
    }

    /* Modal full width */
    .modal {
        max-width: 100%;
        margin: var(--sp-4);
        border-radius: var(--radius-lg);
    }
}

/* --- Tablet: 640px+ --- */
@media (min-width: 640px) {
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .footer-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- Desktop: 1024px+ --- */
@media (min-width: 1024px) {
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Show sidebar, hide tab bar */
    .sidebar {
        display: block;
    }

    .tab-bar {
        display: none;
    }

    .footer-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .footer-bottom {
        flex-direction: row;
        justify-content: space-between;
    }
}

/* --- Large desktop: 1280px+ --- */
@media (min-width: 1280px) {
    :root {
        --container: 1280px;
    }
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


/* ==========================================================
   31. DARK MODE (prepared, not active)
   ========================================================== */

/*
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0F172A;
        --bg-card: #1E293B;
        --bg-muted: #334155;
        --bg-hover: #475569;
        --border: #334155;
        --border-light: #1E293B;

        --text: #F1F5F9;
        --text-secondary: #CBD5E1;
        --text-muted: #94A3B8;
        --text-light: #64748B;

        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    }
}
*/
