:root {
    --primary: #6d28d9;
    --primary-dark: #5b21b6;
    --primary-light: #8b5cf6;
    --accent: #f59e0b;
    --accent-2: #ec4899;
    --ink: #1e1b2e;
    --muted: #6b7280;
    --line: #e7e5ef;
    --bg: #f5f4fb;
    --card: #ffffff;
    --green: #16a34a;
    --red: #dc2626;
    --blue: #2563eb;
    --shadow: 0 10px 30px rgba(76, 29, 149, .08);
    --shadow-lg: 0 20px 45px rgba(76, 29, 149, .16);
    --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background:
        radial-gradient(900px 520px at 100% -8%, #e7defe 0%, transparent 55%),
        radial-gradient(820px 520px at -8% 4%, #ffe0f0 0%, transparent 52%),
        radial-gradient(760px 620px at 50% 118%, #d9ecff 0%, transparent 55%),
        linear-gradient(180deg, #f6f5fc 0%, #f1eefb 100%);
    background-attachment: fixed;
    color: var(--ink);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }

/* ---------- Header ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, .85);
    backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--line);
}

.app-header-inner {
    max-width: 1140px;
    margin: 0 auto;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); }

.brand-emblem {
    width: 46px; height: 46px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--accent-2));
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow);
    flex: 0 0 auto;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-weight: 800; font-size: 16px; }
.brand-sub { font-size: 11.5px; color: var(--muted); font-weight: 500; }

.user-chip {
    display: flex; align-items: center; gap: 10px;
    background: var(--card);
    border: 1px solid var(--line);
    padding: 6px 8px 6px 6px;
    border-radius: 999px;
    box-shadow: var(--shadow);
}

.user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: #fff; font-weight: 700; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.1; }
.user-name { font-weight: 700; font-size: 13px; }
.user-role { font-size: 11px; color: var(--muted); }

.btn-logout {
    margin-left: 4px;
    background: #f3f0fb;
    color: var(--primary-dark);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 700;
    border: 1px solid var(--line);
}
.btn-logout:hover { background: var(--primary); color: #fff; }

/* ---------- Layout ---------- */
.app-main { flex: 1 0 auto; width: 100%; }

.container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 26px 18px 48px;
}
.container-narrow { max-width: 760px; }

.page-head { margin-bottom: 20px; }
.page-title { font-size: 24px; font-weight: 800; margin: 0; }
.page-sub { color: var(--muted); margin: 4px 0 0; font-size: 14px; }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}
.card + .card { margin-top: 18px; }
.card-title {
    font-size: 16px; font-weight: 800; margin: 0 0 16px;
    padding-left: 14px; position: relative;
}
.card-title::before {
    content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 5px; height: 20px; border-radius: 6px;
    background: linear-gradient(180deg, var(--primary), var(--accent-2));
}

/* ---------- Stat tiles ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat {
    border: none;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
    color: #fff;
}
.stat::after {
    content: '';
    position: absolute; right: -24px; top: -24px;
    width: 110px; height: 110px; border-radius: 50%;
    background: rgba(255, 255, 255, .18);
}
.stat::before {
    content: '';
    position: absolute; right: 16px; bottom: -18px;
    width: 70px; height: 70px; border-radius: 50%;
    background: rgba(255, 255, 255, .12);
}
.stat-label { color: rgba(255, 255, 255, .9); font-size: 12.5px; font-weight: 600; position: relative; }
.stat-value { font-size: 30px; font-weight: 800; margin-top: 6px; position: relative; color: #fff; }
.stat.amber  { background: linear-gradient(135deg, #f59e0b 0%, #f97316 100%); }
.stat.green  { background: linear-gradient(135deg, #16a34a 0%, #10b981 100%); }
.stat.blue   { background: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%); }
.stat.violet { background: linear-gradient(135deg, #7c3aed 0%, #c026d3 100%); }
.stat.amber .stat-value, .stat.green .stat-value, .stat.blue .stat-value, .stat.violet .stat-value { color: #fff; }

/* ---------- Hero banner ---------- */
.hero {
    position: relative;
    overflow: hidden;
    border-radius: 22px;
    padding: 28px 30px;
    margin-bottom: 22px;
    color: #fff;
    background: linear-gradient(120deg, #6d28d9 0%, #9333ea 42%, #ec4899 100%);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
}
.hero::before {
    content: '';
    position: absolute; inset: 0;
    background-image:
        radial-gradient(circle at 18% 30%, rgba(255,255,255,.18) 0, transparent 22%),
        radial-gradient(circle at 85% 75%, rgba(255,255,255,.14) 0, transparent 26%),
        repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 14px, transparent 14px 28px);
    opacity: .9;
}
.hero-content { position: relative; z-index: 1; }
.hero-eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.hero-title { font-size: 26px; font-weight: 800; margin: 6px 0 4px; }
.hero-sub { opacity: .92; margin: 0; font-size: 14px; max-width: 560px; }
.hero-actions { position: relative; z-index: 1; }
.hero-actions .btn { background: #fff; color: var(--primary-dark); box-shadow: 0 8px 20px rgba(0,0,0,.18); }
.hero-actions .btn:hover { background: #f6f1ff; }
.hero-emoji { position: relative; z-index: 1; font-size: 64px; line-height: 1; filter: drop-shadow(0 6px 12px rgba(0,0,0,.25)); }

/* ---------- AI analyzing loader ---------- */
.ai-loader {
    position: fixed; inset: 0; z-index: 300;
    display: none; align-items: center; justify-content: center; flex-direction: column;
    background: radial-gradient(circle at 50% 40%, rgba(109,40,217,.85), rgba(30,27,46,.92));
    backdrop-filter: blur(8px);
    color: #fff; text-align: center; padding: 24px;
}
.ai-loader.show { display: flex; }
.ai-loader .ring {
    width: 86px; height: 86px; border-radius: 50%;
    border: 6px solid rgba(255,255,255,.22);
    border-top-color: #fff; border-right-color: #f0abfc;
    animation: thcspin .9s linear infinite;
}
@keyframes thcspin { to { transform: rotate(360deg); } }
.ai-loader .scanwrap { position: relative; margin-bottom: 22px; }
.ai-loader .scanwrap .chip {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 30px; animation: thcpulse 1.4s ease-in-out infinite;
}
@keyframes thcpulse { 0%,100% { transform: scale(1); opacity: .9; } 50% { transform: scale(1.18); opacity: 1; } }
.ai-loader h3 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.ai-loader p { margin: 0; opacity: .85; font-size: 14px; }
.ai-loader .dots::after { content: ''; animation: thcdots 1.4s steps(4, end) infinite; }
@keyframes thcdots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.ai-loader .steps { margin-top: 18px; font-size: 12.5px; opacity: .8; display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.ai-loader .steps span { background: rgba(255,255,255,.12); padding: 6px 12px; border-radius: 999px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; cursor: pointer;
    font-family: inherit; font-weight: 700; font-size: 14px;
    padding: 12px 20px; border-radius: 12px;
    transition: transform .05s ease, box-shadow .2s ease, background .2s ease;
    text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--accent-2)); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { box-shadow: var(--shadow-lg); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(1.05); }
.btn-danger { background: #fff; color: var(--red); border: 1px solid #f3c6c6; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { background: #f3f0fb; color: var(--primary-dark); }
.btn-ghost:hover { background: #e9e3fb; }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 24px; font-size: 15px; }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.input, .select, .textarea, input[type=text], input[type=tel], select, textarea {
    width: 100%;
    font-family: inherit; font-size: 15px;
    padding: 13px 14px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, .textarea:focus, input:focus, select:focus, textarea:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, .15);
}
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Login ---------- */
.auth-wrap {
    min-height: calc(100vh - 230px);
    display: flex; align-items: center; justify-content: center;
    padding: 30px 18px;
}
.auth-card {
    width: 100%; max-width: 880px;
    background: var(--card);
    border-radius: 26px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--line);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
/* Left decorative hero panel */
.auth-hero {
    position: relative;
    padding: 36px 32px;
    color: #fff;
    background: linear-gradient(150deg, #6d28d9 0%, #9333ea 45%, #ec4899 100%);
    display: flex; flex-direction: column; justify-content: space-between;
    overflow: hidden;
}
.auth-hero::before {
    content: ''; position: absolute; inset: 0;
    background-image:
        radial-gradient(circle at 80% 15%, rgba(255,255,255,.20) 0, transparent 24%),
        radial-gradient(circle at 12% 88%, rgba(255,255,255,.15) 0, transparent 26%),
        repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 16px, transparent 16px 32px);
}
.auth-hero > * { position: relative; z-index: 1; }
.auth-logo {
    width: 60px; height: 60px; margin-bottom: 18px;
    border-radius: 18px; background: rgba(255,255,255,.20);
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 800;
    border: 1px solid rgba(255,255,255,.25);
}
.auth-hero h1 { font-size: 24px; margin: 0 0 8px; line-height: 1.25; }
.auth-hero p { margin: 0; opacity: .92; font-size: 14px; }
.auth-feats { list-style: none; padding: 0; margin: 20px 0 0; display: flex; flex-direction: column; gap: 12px; }
.auth-feats li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; font-weight: 600; }
.auth-feats li .fi {
    width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
    background: rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.auth-top { display: none; }
.auth-body { padding: 36px 34px; display: flex; flex-direction: column; justify-content: center; }
.auth-body h2 { margin: 0 0 4px; font-size: 20px; }
.auth-body .lead { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.phone-input { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; }
.phone-input:focus-within { border-color: var(--primary-light); box-shadow: 0 0 0 4px rgba(139,92,246,.15); }
.phone-cc { padding: 13px 12px; background: #f3f0fb; font-weight: 700; color: var(--primary-dark); border-right: 1px solid var(--line); }
.phone-input input { border: none; box-shadow: none !important; }
.demo-box { margin-top: 20px; background: #faf9ff; border: 1px dashed var(--line); border-radius: 14px; padding: 14px 16px; }
.demo-box h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.demo-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; }
.demo-row b { font-weight: 700; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-pending { background: #fff7e6; color: #b45309; }
.badge-approved { background: #e8f0ff; color: #1d4ed8; }
.badge-rejected { background: #fdeaea; color: #b91c1c; }
.badge-funded { background: #e7f7ec; color: #15803d; }

.stage-chip { display: inline-block; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #f1ebff; color: var(--primary-dark); }

/* ---------- Submission grid ---------- */
.sub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.sub-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.sub-photo { aspect-ratio: 16/10; width: 100%; object-fit: cover; background: #ece9f6; display: block; }
.sub-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.sub-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sub-ref { font-weight: 800; font-size: 14px; }
.sub-meta { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.sub-meta b { color: var(--ink); font-weight: 600; }
.sub-actions { display: flex; gap: 8px; margin-top: auto; }
.sub-actions .btn { flex: 1; padding: 10px; font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th, table.grid td { padding: 12px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
table.grid tr:hover td { background: #faf9ff; }

/* ---------- Detail / capture layout ---------- */
.split { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; align-items: start; }
.media-pane { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #0f0a1e; min-height: 280px; display: flex; align-items: center; justify-content: center; }
.media-pane img, .media-pane video { width: 100%; display: block; }
.media-placeholder { color: #cbbff0; text-align: center; padding: 40px 20px; }
.media-placeholder .big { font-size: 40px; }

.capture-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.capture-tabs button { flex: 1; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; text-align: right; }

.ai-box { background: linear-gradient(135deg, #f3ebff, #ffe9f6); border: 1px solid #ead9ff; border-radius: 14px; padding: 14px 16px; margin-top: 12px; }
.ai-box .ai-stage { font-size: 18px; font-weight: 800; color: var(--primary-dark); }
.confbar { height: 8px; border-radius: 999px; background: #e7e0f7; overflow: hidden; margin-top: 8px; }
.confbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent-2)); }
.ai-tags { margin-top: 10px; font-size: 12px; color: var(--muted); font-weight: 600; }

#map { width: 100%; height: 240px; border-radius: var(--radius); border: 1px solid var(--line); }

.alert { padding: 12px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 600; margin-bottom: 16px; }
.alert-success { background: #e7f7ec; color: #15803d; }
.alert-error { background: #fdeaea; color: #b91c1c; }
.alert-info { background: #eaf1ff; color: #1d4ed8; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .big { font-size: 46px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.tabs { display: inline-flex; background: #f1ecfb; border-radius: 999px; padding: 4px; gap: 4px; margin-bottom: 18px; }
.tabs a { padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--muted); }
.tabs a.active { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(30,27,46,.5); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 18px; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 20px; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
    .split { grid-template-columns: 1fr; }
    .brand-sub { display: none; }
    .brand-title { font-size: 14px; }
    .auth-card { grid-template-columns: 1fr; max-width: 440px; }
    .auth-hero { padding: 26px 26px 22px; }
    .auth-hero h1 { font-size: 20px; }
    .auth-feats { display: none; }
    .hero-emoji { display: none; }
}
@media (max-width: 560px) {
    .container { padding: 18px 14px 40px; }
    .page-title { font-size: 20px; }
    .user-meta { display: none; }
    .btn-logout span { display: inline; }
    .app-footer { font-size: 11px; }
}

.app-footer {
    flex-shrink: 0;
    text-align: center;
    padding: 18px;
    color: var(--muted);
    font-size: 12.5px;
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.6);
    display: flex; flex-direction: column; gap: 2px;
}
.footer-note { font-size: 11px; opacity: .8; }
