@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ==========================================================================
   CSS VARIABLES & DESIGN SYSTEM (Light Mode Default)
   ========================================================================== */
:root {
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --secondary: #7C3AED;
    --secondary-hover: #6D28D9;
    --success: #22C55E;
    --success-hover: #16A34A;
    --warning: #F59E0B;
    --danger: #EF4444;
    --bg-main: #F8FAFC;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-hover: rgba(255, 255, 255, 0.95);
    --text-main: #0F172A;
    --text-muted: #64748B;
    --text-light: #F8FAFC;
    --border: #E2E8F0;
    --border-focus: #2563EB;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.04);
    --glass-blur: blur(12px);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --header-height: 72px;
}

/* ==========================================================================
   CSS RESET & CORE
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    outline: none;
    border: none;
}

button {
    cursor: pointer;
    background: none;
}

ul {
    list-style: none;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ==========================================================================
   LAYOUT STRUCTURE
   ========================================================================== */
.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
}

.main-content {
    flex: 1;
    padding-top: calc(var(--header-height) + 24px);
    padding-bottom: 48px;
}

/* Sticky Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    display: flex;
    align-items: center;
    transition: var(--transition);
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.logo-link span {
    color: var(--text-main);
    font-weight: 700;
}

/* Navigation Links */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 24px;
}

.nav-link {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
}

.nav-link:hover, .nav-link.active {
    color: var(--primary);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Search Bar in Header */
.search-container {
    position: relative;
    width: 240px;
    transition: var(--transition);
}

.search-container:focus-within {
    width: 300px;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    transition: var(--transition);
}

.search-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-input {
    background: transparent;
    width: 100%;
    font-size: 0.875rem;
}

.search-icon-btn, .voice-search-btn {
    color: var(--text-muted);
    font-size: 1rem;
    padding: 2px;
}

.voice-search-btn:hover {
    color: var(--primary);
}

/* Autocomplete Results Panel */
.search-results-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background-color: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    max-height: 350px;
    overflow-y: auto;
    z-index: 1100;
    display: none;
}

.search-results-panel.active {
    display: block;
}

.search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

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

.search-item:hover {
    background-color: rgba(37, 99, 235, 0.05);
}

.search-item-info {
    display: flex;
    flex-direction: column;
}

.search-item-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.search-item-category {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.search-highlight {
    background-color: rgba(245, 158, 11, 0.2);
    font-weight: 700;
}

/* Icons & Settings Controls */
.icon-btn {
    font-size: 1.25rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background-color: var(--bg-card);
    transition: var(--transition);
}

.icon-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Mobile Menu Toggle */
.mobile-menu-btn {
    display: none;
}

/* ==========================================================================
   CARDS & WRAPPERS
   ========================================================================== */
.card {
    background-color: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-glass);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-xl);
    border-color: rgba(37, 99, 235, 0.2);
}

/* ==========================================================================
   FORM CONTROLS (Input sliders & Numbers)
   ========================================================================== */
.form-group {
    margin-bottom: 20px;
}

.form-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.form-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.input-val-display {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    transition: var(--transition);
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-suffix {
    position: absolute;
    right: 16px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
}

.range-slider {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    -webkit-appearance: none;
    margin-top: 10px;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: var(--transition);
}

.range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.2);
}

/* Button Layouts */
.btn-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    margin-top: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.btn-primary {
    background-color: var(--primary);
    color: var(--text-light);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-secondary {
    background-color: var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   RESULTS LAYOUT
   ========================================================================== */
.result-box {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.05), rgba(124, 58, 237, 0.05));
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
}

.result-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.result-val {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--primary);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.result-mini-card {
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
}

.result-mini-title {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}

.result-mini-val {
    font-size: 1.1rem;
    font-weight: 700;
}

/* ==========================================================================
   CHARTS & CANVAS
   ========================================================================== */
.chart-container {
    position: relative;
    width: 100%;
    height: 250px;
    margin-top: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chart-canvas {
    max-width: 100%;
    max-height: 100%;
}

/* ==========================================================================
   ADSENSE UNITS placeholders
   ========================================================================== */
.adsense-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.02);
    border: 1px dashed var(--border);
    padding: 10px;
    margin: 20px 0;
    overflow: hidden;
    position: relative;
    text-align: center;
}

.adsense-unit::before {
    content: 'Advertisement';
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: block;
}

.ads-top-banner {
    min-height: 90px;
    width: 728px;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.ads-sidebar {
    min-height: 600px;
    width: 300px;
    max-width: 100%;
}

.ads-inline {
    min-height: 250px;
    width: 100%;
}

.ads-sticky-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 90px;
    z-index: 999;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ads-close-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background: var(--text-muted);
    color: var(--bg-main);
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   AI ASSISTANT FLOAT UI
   ========================================================================== */
.ai-assistant-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 2000;
    font-family: var(--font-sans);
}

.ai-assistant-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--text-light);
    box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: var(--transition);
}

.ai-assistant-trigger:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 12px 32px rgba(124, 58, 237, 0.5);
}

.ai-assistant-panel {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 360px;
    height: 480px;
    background-color: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9);
    opacity: 0;
    pointer-events: none;
    transform-origin: bottom right;
    transition: var(--transition);
}

.ai-assistant-panel.active {
    transform: scale(1);
    opacity: 1;
    pointer-events: auto;
}

.ai-header {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--text-light);
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-header-title {
    font-size: 1rem;
    font-weight: 700;
}

.ai-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.ai-msg-bot {
    background-color: var(--border);
    align-self: flex-start;
}

.ai-msg-user {
    background-color: var(--primary);
    color: var(--text-light);
    align-self: flex-end;
}

.ai-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.5);
}

.ai-input {
    flex: 1;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.875rem;
}

.ai-input:focus {
    border-color: var(--primary);
}

.ai-send-btn, .ai-mic-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.ai-send-btn:hover, .ai-mic-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.ai-mic-btn.listening {
    background-color: var(--danger);
    color: var(--text-light);
    animation: pulse 1.5s infinite;
}

/* ==========================================================================
   BREADCRUMBS & GENERAL UI
   ========================================================================== */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.breadcrumbs a:hover {
    color: var(--primary);
}

.breadcrumb-separator {
    font-size: 0.75rem;
}

/* Calculator Grid Page structure */
.calculator-grid {
    display: grid;
    grid-template-columns: 7fr 5fr;
    gap: 32px;
    align-items: start;
}

/* Info Section (Formula, FAQs, etc.) */
.calc-info-section {
    margin-top: 48px;
    border-top: 1px solid var(--border);
    padding-top: 32px;
}

.calc-info-section h2, .calc-info-section h3 {
    margin-bottom: 16px;
}

.calc-info-section p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.step-by-step-box {
    background-color: var(--bg-card);
    border-left: 4px solid var(--secondary);
    padding: 16px;
    margin-bottom: 24px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* Amortization / Detailed breakdown tables */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin-top: 24px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.calc-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.calc-table th {
    background-color: rgba(37, 99, 235, 0.05);
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 2px solid var(--border);
}

.calc-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

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

.calc-table tr:hover td {
    background-color: rgba(0, 0, 0, 0.01);
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
.footer {
    background-color: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 48px 0 24px 0;
    margin-top: auto;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2fr repeat(4, 1fr);
    gap: 32px;
    margin-bottom: 32px;
}

.footer-brand h3 {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 12px;
}

.footer-brand p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.footer-col h4 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.footer-col ul {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.footer-col a {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.footer-col a:hover {
    color: var(--primary);
}

.footer-bottom {
    border-top: 1px solid var(--border);
    padding-top: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ==========================================================================
   ANIMATIONS & KEYFRAMES
   ========================================================================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.animate-fade {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
