/* Rural Funding — Design System
 * Extracted from layouts/app.blade.php for browser caching.
 */

:root {
    --color-primary: #5B9BD5;
    --color-primary-dark: #4A8BC5;
    --color-primary-deeper: #3A7BB5;
    --color-primary-light: #e8f1fa;
    --color-accent: #E4A41E;
    --color-accent-hover: #d49618;
    --color-text: #222222;
    --color-text-secondary: #5a6270;
    --color-text-light: #8b95a5;
    --color-bg: #f4f6f9;
    --color-white: #ffffff;
    --color-border: #e3e7ed;
    --color-border-light: #f0f2f5;
    --font-heading: 'Lato', sans-serif;
    --font-body: 'Lato', -apple-system, BlinkMacSystemFont, sans-serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(94,106,135,0.1);
    --shadow-lg: 0 4px 20px rgba(94,106,135,0.12);
    --radius: 10px;
    --radius-lg: 14px;
    --radius-pill: 9999px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; }
body { font-family: var(--font-body); color: var(--color-text); background: var(--color-bg); line-height: 1.6; font-size: 0.938rem; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
img, video, iframe, svg { max-width: 100%; height: auto; }
a { color: var(--color-primary-deeper); text-decoration: none; transition: color 0.2s; word-wrap: break-word; }
a:hover { color: var(--color-primary-dark); text-decoration: none; }

/* Navbar */
.navbar { background: #1e2a3e; color: #fff; padding: 0 2rem; display: flex; align-items: center; justify-content: space-between; height: 60px; position: sticky; top: 0; z-index: 100; }
.navbar-brand { font-family: var(--font-body); font-size: 1.5rem; font-weight: 800; color: #fff; letter-spacing: -0.01em; white-space: nowrap; }
.navbar-brand:hover { text-decoration: none; color: #fff; }
.navbar-nav { display: flex; gap: 0.1rem; align-items: center; list-style: none; }
.navbar-nav a { color: #fff; padding: 0.5rem 0.9rem; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; transition: all 0.2s; border-bottom: 2px solid transparent; }
.navbar-nav a:hover, .navbar-nav a.active { color: #fff; text-decoration: none; border-bottom-color: #fff; }

/* User Sub-nav */
.user-subnav { background: #263248; padding: 0 2rem; display: flex; align-items: center; justify-content: space-between; height: 38px; position: sticky; top: 60px; z-index: 99; border-bottom: 1px solid rgba(255,255,255,0.08); }
.user-subnav-links { display: flex; gap: 0; align-items: center; list-style: none; }
.user-subnav-links a { color: rgba(255,255,255,0.7); padding: 0.4rem 0.85rem; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; transition: all 0.2s; border-bottom: 2px solid transparent; }
.user-subnav-links a:hover { color: #fff; text-decoration: none; border-bottom-color: rgba(255,255,255,0.4); }
.user-subnav-links a.active { color: #fff; border-bottom-color: var(--color-accent); }
.user-subnav-right { display: flex; align-items: center; gap: 0.5rem; }
.user-subnav-name { color: rgba(255,255,255,0.85); font-size: 0.75rem; font-weight: 600; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }
.container-wide { max-width: 1300px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Cards */
.card { background: var(--color-white); border-radius: var(--radius-lg); border: 1px solid var(--color-border); box-shadow: var(--shadow-sm); margin-bottom: 1.25rem; transition: box-shadow 0.2s; }
.card:hover { box-shadow: var(--shadow-md); }
.card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--color-border); font-family: var(--font-heading); font-weight: 600; font-size: 1.05rem; letter-spacing: 0.01em; display: flex; align-items: center; justify-content: space-between; color: var(--color-text); }
.card-body { padding: 1.5rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.6rem 1.4rem; border-radius: 6px; border: 2px solid transparent; font-size: 0.85rem; font-weight: 700; font-family: var(--font-body); cursor: pointer; transition: all 0.2s; text-transform: uppercase; letter-spacing: 0.04em; }
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); color: #fff; }
.btn-secondary { background: var(--color-white); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); border-color: #cdd3dc; color: var(--color-text); }
.btn-accent { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn-accent:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.75rem; }
.btn-lg { padding: 0.75rem 2rem; font-size: 0.9rem; }
.btn-outline { background: transparent; }
.btn-white { background: #fff; color: var(--color-text); border-color: #fff; }
.btn-white:hover { background: #f0f0f0; border-color: #f0f0f0; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.03em; font-family: var(--font-heading); }
.form-control { width: 100%; padding: 0.6rem 0.85rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: 0.875rem; background: var(--color-white); font-family: var(--font-body); transition: border-color 0.2s, box-shadow 0.2s; }
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(91,155,213,0.15); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.7rem 0.85rem; background: var(--color-bg); border-bottom: 2px solid var(--color-border); font-weight: 600; color: var(--color-text-secondary); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; font-family: var(--font-heading); }
td { padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--color-border-light); }
tr:hover td { background: #f8f9fb; }

/* Badges */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: var(--radius-pill); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; line-height: 1.2; text-align: center; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }

/* Alerts */
.alert { padding: 0.85rem 1.25rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef9c3; color: #854d0e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

.disclaimer { background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius); padding: 0.6rem 0.85rem; font-size: 0.82rem; color: #92400e; margin-bottom: 0.5rem; }

/* Filter Bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; padding: 1rem 1.5rem; background: var(--color-bg); border-bottom: 1px solid var(--color-border); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.filter-bar .form-group { margin-bottom: 0; min-width: 160px; }

/* Pagination */
.pagination { display: flex; gap: 0.25rem; list-style: none; margin-top: 1rem; justify-content: center; }
.pagination li a, .pagination li span { padding: 0.4rem 0.8rem; border-radius: 6px; font-size: 0.85rem; border: 1px solid var(--color-border); color: var(--color-text-secondary); display: block; transition: all 0.2s; }
.pagination li a:hover { background: var(--color-primary-light); border-color: var(--color-primary); color: var(--color-primary-deeper); }
.pagination li.active span { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.pagination li.disabled span { color: #cbd5e1; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--color-white); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; box-shadow: var(--shadow-sm); }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--color-text); font-family: var(--font-heading); }
.stat-card .stat-label { font-size: 0.8rem; color: var(--color-text-light); margin-top: 0.15rem; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* Section headings */
.section-heading { font-family: var(--font-heading); font-size: 1.35rem; font-weight: 600; color: var(--color-text); margin-bottom: 1rem; letter-spacing: 0.01em; }

/* Footer */
.footer { background: #2a2f3d; color: rgba(255,255,255,0.65); padding: 2.5rem 1.5rem; margin-top: 3rem; text-align: center; font-size: 0.82rem; }
.footer a { color: rgba(255,255,255,0.8); }
.footer a:hover { color: #fff; }
.footer-links { display: flex; justify-content: center; gap: 1.5rem; margin-bottom: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.78rem; }

/* Hamburger toggle (hidden on desktop) */
.navbar-toggle { display: none; background: none; border: none; cursor: pointer; padding: 0.5rem; flex-direction: column; gap: 4px; }
.navbar-toggle span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; transition: all 0.3s; }

/* Hide tagline early so brand doesn't wrap */
@media (max-width: 1024px) {
    .navbar-tagline { display: none !important; }
}

/* ============================================
   RESPONSIVE — 768px (tablets + hamburger menu)
   ============================================ */
@media (max-width: 768px) {
    /* Navbar → hamburger menu */
    .navbar { flex-wrap: wrap; height: auto; min-height: 54px; padding: 0 1rem; }
    .navbar > div:first-child { flex: 1; min-width: 0; }
    .navbar-toggle { display: flex; }
    .navbar-nav { display: none; width: 100%; flex-direction: column; padding: 0.25rem 0 0.5rem; border-top: 1px solid rgba(255,255,255,0.1); }
    .navbar-nav.open { display: flex; }
    .navbar-nav li { width: 100%; }
    .navbar-nav a { display: block; padding: 0.6rem 0.5rem; border-bottom: none; font-size: 0.8rem; }
    .navbar-nav a:hover, .navbar-nav a.active { border-bottom: none; background: rgba(255,255,255,0.08); border-radius: 4px; }
    .navbar-brand { font-size: 1rem; white-space: nowrap; line-height: 1.1; }

    /* Hide beta badge and tagline on tablet/mobile */
    .navbar-beta, .navbar-tagline { display: none !important; }

    /* User subnav stacks */
    .user-subnav { flex-direction: column; height: auto; padding: 0.4rem 1rem; gap: 0.15rem; top: auto; position: relative; }
    .user-subnav-links { flex-wrap: wrap; justify-content: center; gap: 0; }
    .user-subnav-right { justify-content: center; padding-bottom: 0.25rem; }

    /* Grids single column */
    .grid-2, .grid-3 { grid-template-columns: 1fr; }

    /* Filter bar stacks */
    .filter-bar { flex-direction: column; }
    .filter-bar .form-group { min-width: 100%; }

    /* Hide hero search label and filter link on mobile */
    .hero-search-label, .hero-filter-link { display: none !important; }

    /* Container */
    .container { padding: 1.25rem 1rem; }

    /* Cards */
    .card-header { padding: 0.75rem 1rem; font-size: 0.95rem; }
    .card-body { padding: 1rem; }

    /* Footer */
    .footer { padding: 2rem 1rem; margin-top: 2rem; }
    .footer-links { flex-wrap: wrap; gap: 0.75rem; }

    /* Stats */
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

    /* Catch-all: prevent ANY element from causing horizontal overflow */
    .container > * { max-width: 100%; overflow-wrap: break-word; word-wrap: break-word; }

    /* Flex containers with inline gap should wrap */
    [style*="display: flex"], [style*="display:flex"] { flex-wrap: wrap !important; }

    /* Force inline font sizes down for headings */
    h1[style*="font-size"] { font-size: 1.3rem !important; }
    h2[style*="font-size"] { font-size: 1.15rem !important; }

    /* Prevent fixed-width inline styles from overflowing */
    [style*="min-width"] { min-width: 0 !important; }
    [style*="flex-basis"] { flex-basis: auto !important; }
}

/* ============================================
   RESPONSIVE — 640px (mobile phones)
   ============================================ */
@media (max-width: 640px) {
    /* Container tighter padding */
    .container { padding: 1rem 0.75rem; }

    /* Grids tighter gap */
    .grid-2, .grid-3 { gap: 0.75rem; }
    .stats-grid { grid-template-columns: 1fr; gap: 0.5rem; }

    /* Table horizontal scroll */
    .table-wrap { -webkit-overflow-scrolling: touch; }
    table { min-width: 500px; }

    /* Footer stacks vertically */
    .footer { padding: 1.5rem 1rem; margin-top: 1.5rem; }
    .footer-links { flex-direction: column; gap: 0.4rem; align-items: center; }
    .footer p { font-size: 0.78rem; }

    /* Cards tighter */
    .card-header { padding: 0.65rem 0.85rem; font-size: 0.9rem; }
    .card-body { padding: 0.85rem; }

    /* Buttons */
    .btn { font-size: 0.8rem; padding: 0.55rem 1rem; }
    .btn-lg { padding: 0.6rem 1.25rem; font-size: 0.85rem; }

    /* Stat cards tighter */
    .stat-card { padding: 1rem 1.15rem; }
    .stat-card .stat-value { font-size: 1.4rem; }

    /* Pagination */
    .pagination { flex-wrap: wrap; }
    .pagination li a, .pagination li span { padding: 0.35rem 0.6rem; font-size: 0.78rem; }

    /* Alerts */
    .alert { padding: 0.65rem 0.85rem; font-size: 0.82rem; }

    /* Navbar even tighter */
    .navbar { min-height: 50px; }
    .navbar-brand { font-size: 1.1rem; }

    /* Force headings smaller — override inline styles */
    h1[style*="font-size"] { font-size: 1.2rem !important; }
    h2[style*="font-size"] { font-size: 1.05rem !important; }

    /* All images/media contained */
    img, video, iframe { max-width: 100% !important; height: auto !important; }

    /* Inline flex gaps — tighter on mobile */
    [style*="gap: 1.5rem"] { gap: 0.75rem !important; }
    [style*="gap: 2rem"] { gap: 1rem !important; }
    [style*="gap: 3rem"] { gap: 1rem !important; }

    /* Prevent large padding from eating mobile space */
    [style*="padding: 2rem"] { padding: 1rem !important; }
    [style*="padding: 2.5rem"] { padding: 1.25rem !important; }
    [style*="padding: 3rem"] { padding: 1.25rem !important; }
}

/* ============================================
   RESPONSIVE — 480px (small phones)
   ============================================ */
@media (max-width: 480px) {
    .container { padding: 0.75rem 0.5rem; }
    .card-body { padding: 0.75rem; }
    .filter-bar { padding: 0.75rem; }
    .stat-card .stat-value { font-size: 1.25rem; }

    /* Even smaller headings on small phones */
    h1[style*="font-size"] { font-size: 1.1rem !important; }
    h2[style*="font-size"] { font-size: 1rem !important; }
}

/* ============================================
   Admin mobile preview — force mobile layout via class
   ============================================ */
html.force-mobile .navbar { flex-wrap: wrap; height: auto; min-height: 54px; padding: 0 1rem; }
html.force-mobile .navbar > div:first-child { flex: 1; min-width: 0; }
html.force-mobile .navbar-toggle { display: flex; }
html.force-mobile .navbar-nav { display: none; width: 100%; flex-direction: column; padding: 0.25rem 0 0.5rem; border-top: 1px solid rgba(255,255,255,0.1); }
html.force-mobile .navbar-nav.open { display: flex; }
html.force-mobile .navbar-nav li { width: 100%; }
html.force-mobile .navbar-nav a { display: block; padding: 0.6rem 0.5rem; border-bottom: none; font-size: 0.8rem; }
html.force-mobile .navbar-brand { font-size: 1rem !important; white-space: nowrap !important; line-height: 1.1 !important; }
html.force-mobile .navbar-beta, html.force-mobile .navbar-tagline { display: none !important; }
html.force-mobile .user-subnav { flex-direction: column; height: auto; padding: 0.4rem 1rem; gap: 0.15rem; top: auto; position: relative; }
html.force-mobile .user-subnav-links { flex-wrap: wrap; justify-content: center; gap: 0; }
html.force-mobile .user-subnav-right { justify-content: center; padding-bottom: 0.25rem; }
html.force-mobile .grid-2, html.force-mobile .grid-3 { grid-template-columns: 1fr; }
html.force-mobile .filter-bar { flex-direction: column; }
html.force-mobile .filter-bar .form-group { min-width: 100%; }
html.force-mobile .container { padding: 1rem 0.75rem; }
html.force-mobile .card-header { padding: 0.65rem 0.85rem; font-size: 0.9rem; }
html.force-mobile .card-body { padding: 0.85rem; }
html.force-mobile .stats-grid { grid-template-columns: 1fr; }
html.force-mobile .footer-links { flex-direction: column; gap: 0.4rem; align-items: center; }
html.force-mobile .hero-search-label, html.force-mobile .hero-filter-link { display: none !important; }

/* Utilities */
.text-muted { color: var(--color-text-light); }
.text-sm { font-size: 0.8rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
