/* ============================================
   DESIGN SYSTEM 
   Dark navy theme with cyan/blue accents
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Primary palette */
    --navy-950: #020617;
    --navy-900: #0f172a;
    --navy-800: #1e293b;
    --navy-700: #334155;
    --navy-600: #475569;
    --navy-500: #64748b;
    --navy-400: #94a3b8;
    --navy-300: #cbd5e1;
    --navy-200: #e2e8f0;
    --navy-100: #f1f5f9;
    --navy-50: #f8fafc;

    /* Accent colors */
    --cyan-400: #22d3ee;
    --cyan-500: #06b6d4;
    --cyan-600: #0891b2;
    --blue-400: #60a5fa;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --emerald-400: #34d399;
    --emerald-500: #10b981;
    --rose-400: #fb7185;
    --rose-500: #f43f5e;
    --amber-400: #fbbf24;
    --purple-400: #c084fc;
    --purple-500: #a855f7;

    /* Semantic */
    --bg-primary: var(--navy-900);
    --bg-secondary: var(--navy-800);
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-solid: var(--navy-800);
    --bg-input: var(--navy-900);
    --border-default: var(--navy-700);
    --border-subtle: rgba(51, 65, 85, 0.5);
    --text-primary: var(--navy-100);
    --text-secondary: var(--navy-400);
    --text-muted: var(--navy-500);
    --accent: var(--cyan-400);
    --accent-hover: var(--cyan-500);

    /* Glassmorphism */
    --glass-bg: rgba(30, 41, 59, 0.6);
    --glass-border: rgba(148, 163, 184, 0.12);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --glass-blur: blur(16px);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
    --shadow-glow-cyan: 0 0 20px rgba(34, 211, 238, 0.15);
    --shadow-glow-blue: 0 0 20px rgba(59, 130, 246, 0.15);
    --shadow-glow-rose: 0 0 20px rgba(244, 63, 94, 0.15);

    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
}

/* --- Base Reset & Typography --- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--navy-600) var(--navy-800);
}

body {
    font-family: 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--navy-950) 0%, var(--navy-900) 50%, #0c1929 100%);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Decorative background pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(34, 211, 238, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(59, 130, 246, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(168, 85, 247, 0.02) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* --- Navbar --- */
.nav-main {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.nav-logo {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--navy-50);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: color var(--transition-fast);
}

.nav-logo:hover {
    color: var(--cyan-400);
}

.nav-logo svg {
    width: 28px;
    height: 28px;
    color: var(--cyan-400);
}

.nav-link {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--navy-300);
    text-decoration: none;
    transition: all var(--transition-fast);
    position: relative;
}

.nav-link:hover {
    color: var(--cyan-400);
    background: rgba(34, 211, 238, 0.08);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 60%;
    height: 2px;
    background: var(--cyan-400);
    transition: transform var(--transition-base);
    border-radius: 1px;
}

.nav-link:hover::after {
    transform: translateX(-50%) scaleX(1);
}

.nav-user {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--navy-300);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.nav-user svg {
    width: 16px;
    height: 16px;
    color: var(--cyan-400);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue-500), var(--cyan-500));
    color: white;
    box-shadow: 0 4px 15px rgba(6, 182, 212, 0.25);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--blue-600), var(--cyan-600));
    box-shadow: 0 6px 20px rgba(6, 182, 212, 0.35);
    transform: translateY(-1px);
}

.btn-success {
    background: linear-gradient(135deg, var(--emerald-500), #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.25);
}

.btn-success:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35);
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--rose-500), #e11d48);
    color: white;
    box-shadow: 0 4px 15px rgba(244, 63, 94, 0.25);
}

.btn-danger:hover {
    box-shadow: 0 6px 20px rgba(244, 63, 94, 0.35);
    transform: translateY(-1px);
}

.btn-ghost {
    background: rgba(148, 163, 184, 0.08);
    color: var(--navy-300);
    border: 1px solid var(--border-subtle);
}

.btn-ghost:hover {
    background: rgba(148, 163, 184, 0.15);
    color: var(--navy-100);
    border-color: var(--navy-500);
}

.btn-sm {
    padding: 0.35rem 0.85rem;
    font-size: 0.78rem;
}

.btn-lg {
    padding: 0.85rem 2rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* --- Glass Card --- */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    position: relative;
    z-index: 1;
}

.glass-card-hover {
    transition: all var(--transition-base);
}

.glass-card-hover:hover {
    border-color: rgba(34, 211, 238, 0.2);
    box-shadow: var(--glass-shadow), var(--shadow-glow-cyan);
    transform: translateY(-2px);
}

/* --- Metric Cards --- */
.metric-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    position: relative;
    overflow: hidden;
    transition: all var(--transition-base);
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.metric-card:hover {
    border-color: rgba(148, 163, 184, 0.2);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.metric-card.accent-cyan::before {
    background: linear-gradient(90deg, var(--cyan-400), var(--blue-400));
}

.metric-card.accent-emerald::before {
    background: linear-gradient(90deg, var(--emerald-400), var(--emerald-500));
}

.metric-card.accent-purple::before {
    background: linear-gradient(90deg, var(--purple-400), var(--purple-500));
}

.metric-card.accent-amber::before {
    background: linear-gradient(90deg, var(--amber-400), #f59e0b);
}

.metric-card.accent-rose::before {
    background: linear-gradient(90deg, var(--rose-400), var(--rose-500));
}

.metric-card.accent-blue::before {
    background: linear-gradient(90deg, var(--blue-400), var(--blue-500));
}

.metric-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--navy-400);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--navy-100);
    line-height: 1.2;
}

.metric-value.text-cyan {
    color: var(--cyan-400);
}

.metric-value.text-emerald {
    color: var(--emerald-400);
}

.metric-value.text-rose {
    color: var(--rose-400);
}

.metric-value.text-purple {
    color: var(--purple-400);
}

.metric-value.text-amber {
    color: var(--amber-400);
}

.metric-value.text-blue {
    color: var(--blue-400);
}

/* --- Dark Table --- */
.table-dark {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table-dark thead th {
    background: var(--navy-900);
    color: var(--navy-300);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.85rem 1rem;
    border-bottom: 2px solid var(--navy-700);
    white-space: nowrap;
}

.table-dark thead th:first-child {
    border-radius: var(--radius-md) 0 0 0;
}

.table-dark thead th:last-child {
    border-radius: 0 var(--radius-md) 0 0;
}

.table-dark tbody tr {
    transition: background var(--transition-fast);
}

.table-dark tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.3);
}

.table-dark tbody tr:hover {
    background: rgba(34, 211, 238, 0.05);
}

.table-dark tbody td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: var(--navy-200);
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

/* --- Forms --- */
.form-input {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    outline: none;
}

.form-input:focus {
    border-color: var(--cyan-500);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15), 0 0 20px rgba(6, 182, 212, 0.1);
}

.form-input::placeholder {
    color: var(--navy-600);
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--navy-300);
    margin-bottom: 0.5rem;
}

.form-help {
    font-size: 0.78rem;
    color: var(--navy-500);
    margin-top: 0.35rem;
}

.form-error {
    font-size: 0.78rem;
    color: var(--rose-400);
    margin-top: 0.35rem;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.2em;
    padding-right: 2.5rem;
}

textarea.form-input {
    resize: vertical;
    min-height: 100px;
}

/* --- Progress Bars --- */
.progress-track {
    width: 100%;
    height: 8px;
    background: var(--navy-800);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease-out;
}

.progress-fill.fill-cyan {
    background: linear-gradient(90deg, var(--cyan-500), var(--cyan-400));
    box-shadow: 0 0 10px rgba(34, 211, 238, 0.3);
}

.progress-fill.fill-emerald {
    background: linear-gradient(90deg, var(--emerald-500), var(--emerald-400));
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-cyan {
    background: rgba(34, 211, 238, 0.12);
    color: var(--cyan-400);
    border: 1px solid rgba(34, 211, 238, 0.2);
}

.badge-emerald {
    background: rgba(16, 185, 129, 0.12);
    color: var(--emerald-400);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-rose {
    background: rgba(244, 63, 94, 0.12);
    color: var(--rose-400);
    border: 1px solid rgba(244, 63, 94, 0.2);
}

.badge-amber {
    background: rgba(251, 191, 36, 0.12);
    color: var(--amber-400);
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.badge-purple {
    background: rgba(168, 85, 247, 0.12);
    color: var(--purple-400);
    border: 1px solid rgba(168, 85, 247, 0.2);
}

/* --- Alerts / Messages --- */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    backdrop-filter: blur(8px);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--blue-400);
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: var(--emerald-400);
}

.alert-warning {
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.2);
    color: var(--amber-400);
}

.alert-error {
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.2);
    color: var(--rose-400);
}

/* --- Footer --- */
.footer-main {
    background: var(--navy-950);
    border-top: 1px solid var(--glass-border);
    position: relative;
}

.footer-main::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--cyan-500), var(--blue-500), transparent);
}

/* --- Animations --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(34, 211, 238, 0.2);
    }

    50% {
        box-shadow: 0 0 20px rgba(34, 211, 238, 0.4);
    }
}

.animate-fade-in-up {
    animation: fadeInUp 0.5s ease-out both;
}

.animate-fade-in {
    animation: fadeIn 0.4s ease-out both;
}

/* Stagger children */
.stagger-children>*:nth-child(1) {
    animation-delay: 0.05s;
}

.stagger-children>*:nth-child(2) {
    animation-delay: 0.1s;
}

.stagger-children>*:nth-child(3) {
    animation-delay: 0.15s;
}

.stagger-children>*:nth-child(4) {
    animation-delay: 0.2s;
}

.stagger-children>*:nth-child(5) {
    animation-delay: 0.25s;
}

.stagger-children>*:nth-child(6) {
    animation-delay: 0.3s;
}

/* --- Modal Overlay --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: var(--navy-800);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 28rem;
    width: 100%;
    margin: 1rem;
    animation: fadeInUp 0.3s ease-out;
}

/* --- Section Headers --- */
.section-title {
    font-size: 1.5rem;
    font-weight: 300;
    color: var(--navy-100);
    letter-spacing: -0.01em;
}

.section-title .highlight {
    color: var(--cyan-400);
    font-weight: 600;
}

/* --- Risk Grid --- */
.risk-cell {
    text-align: center;
    padding: 0.75rem;
    background: var(--navy-900);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.risk-cell:hover {
    border-color: var(--cyan-500);
    background: rgba(6, 182, 212, 0.06);
}

.risk-cell .risk-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--navy-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.3rem;
}

.risk-cell .risk-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--cyan-400);
}

.risk-cell .risk-unit {
    font-size: 0.65rem;
    color: var(--navy-500);
}

/* --- Utility Colors --- */
.text-positive {
    color: var(--emerald-400) !important;
}

.text-negative {
    color: var(--rose-400) !important;
}

.text-cyan {
    color: var(--cyan-400) !important;
}

.text-blue {
    color: var(--blue-400) !important;
}

.text-purple {
    color: var(--purple-400) !important;
}

.text-amber {
    color: var(--amber-400) !important;
}

.text-muted {
    color: var(--navy-400) !important;
}

.text-white {
    color: var(--navy-100) !important;
}

/* --- Login Page Hero Background --- */
.auth-background {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.auth-background::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(34, 211, 238, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(59, 130, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(168, 85, 247, 0.04) 0%, transparent 60%);
    pointer-events: none;
}

.auth-card {
    background: rgba(30, 41, 59, 0.75);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: var(--radius-xl);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
}

/* --- HTMX transitions (keep existing behavior) --- */
[hx-target] {
    cursor: pointer;
}

.htmx-swapping {
    opacity: 0;
    transition: opacity 200ms ease-out;
}

.htmx-settling {
    opacity: 1;
    transition: opacity 200ms ease-in;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .metric-value {
        font-size: 1.2rem;
    }

    .section-title {
        font-size: 1.25rem;
    }

    .auth-card {
        margin: 1rem;
        padding: 2rem;
    }
}

/* --- Tailwind Overrides for dark inputs (applied via Django form rendering) --- */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="tel"],
input[type="number"],
input[type="date"],
select,
textarea {
    background-color: var(--bg-input) !important;
    border-color: var(--border-default) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-sm) !important;
    padding: 0.7rem 1rem !important;
    font-family: inherit !important;
    font-size: 0.9rem !important;
    transition: all var(--transition-fast) !important;
    outline: none !important;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
    border-color: var(--cyan-500) !important;
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15), 0 0 20px rgba(6, 182, 212, 0.1) !important;
}

/* Date input icon color fix for dark theme */
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
}