/* LivingOnBTC — Shared stylesheet for all pages
   Loaded by index.html, calculator pages, DCA simulator, 404.
   Design system: dark-first with light mode toggle, Bitcoin orange accent.
   Variables: light + dark; components: cards, buttons, inputs, tabs, layout, utilities.
*/

/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
    /* Bitcoin brand */
    --bitcoin-orange: #f7931a;
    --bitcoin-orange-light: #ffb84d;
    --bitcoin-orange-glow: rgba(247, 147, 26, 0.3);

    /* Dark mode palette (default) */
    --bg-primary: #0d1117;
    --bg-card: #161b22;
    --bg-elevated: #1c2128;
    --bg-overlay: rgba(22, 27, 34, 0.95);
    --bg-overlay-hover: rgba(30, 37, 48, 0.95);

    /* Borders */
    --border: rgba(240, 246, 252, 0.1);
    --border-hover: rgba(247, 147, 26, 0.3);
    --border-strong: #30363d;

    /* Text */
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --text-on-accent: #0d1117;

    /* Semantic colors */
    --success: #3fb950;
    --success-muted: rgba(63, 185, 80, 0.15);
    --danger: #f85149;
    --danger-muted: rgba(248, 81, 73, 0.15);
    --warning: #f39c12;
    --info: #58a6ff;
    --info-muted: rgba(88, 166, 255, 0.2);
    --accent-cyan: #58a6ff;
    --accent-purple: #a371f7;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--bitcoin-orange-glow);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Motion */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    /* Typography */
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    /* Layout */
    --max-width: 960px;
    --header-padding: 40px 20px;
    --container-padding: 40px 20px;
}

/* Light mode overrides */
body.light-mode {
    --bg-primary: #f5f7fa;
    --bg-card: #ffffff;
    --bg-elevated: #f6f8fa;
    --bg-overlay: rgba(255, 255, 255, 0.95);
    --bg-overlay-hover: rgba(246, 248, 250, 0.95);
    --border: rgba(31, 35, 40, 0.1);
    --border-strong: #d0d7de;
    --text-primary: #1a1f36;
    --text-secondary: #586069;
    --text-muted: #6a737d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* ============================================
   RESET + BASE
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-stack);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background var(--transition-normal), color var(--transition-normal);
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bitcoin-orange);
    color: var(--text-on-accent);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 700;
    text-decoration: none;
    z-index: 1000;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 10px;
    outline: 3px solid var(--accent-cyan);
    outline-offset: 2px;
}

*:focus-visible {
    outline: 2px solid var(--bitcoin-orange);
    outline-offset: 2px;
}

button:focus-visible,
.btn:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(88, 166, 255, 0.3);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--bitcoin-orange) !important;
    box-shadow: 0 0 0 3px var(--bitcoin-orange-glow);
}

/* ============================================
   LAYOUT
   ============================================ */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--container-padding);
}

main {
    min-height: calc(100vh - 200px);
}

.page-header {
    text-align: center;
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    margin: 0 0 8px;
    line-height: 1.2;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 1.05rem;
    margin: 0;
}

/* ============================================
   THEME TOGGLE
   ============================================ */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    border-color: var(--bitcoin-orange);
    color: var(--bitcoin-orange);
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: border-color var(--transition-normal), transform var(--transition-fast);
}

.card:hover {
    border-color: var(--border-hover);
}

.card-elevated {
    background: var(--bg-elevated);
    box-shadow: var(--shadow-md);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
    min-height: 44px; /* touch target */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--bitcoin-orange);
    color: var(--text-on-accent);
}

.btn-primary:hover {
    background: var(--bitcoin-orange-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
    border-color: var(--bitcoin-orange);
    color: var(--bitcoin-orange);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.form-input,
.form-select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    touch-action: manipulation;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--bitcoin-orange);
    box-shadow: 0 0 0 3px var(--bitcoin-orange-glow);
    outline: none;
}

.form-help {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ============================================
   RESULTS / METRICS
   ============================================ */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.metric {
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border);
}

.metric-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.metric-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--bitcoin-orange);
    font-variant-numeric: tabular-nums;
}

.metric-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.metric-success .metric-value { color: var(--success); }
.metric-danger .metric-value { color: var(--danger); }

/* ============================================
   TABS
   ============================================ */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 12px 18px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.tab.active {
    color: var(--bitcoin-orange);
    border-bottom-color: var(--bitcoin-orange);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn var(--transition-normal);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   CHARTS
   ============================================ */
.chart-wrapper {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin: 20px 0;
    border: 1px solid var(--border);
}

.chart-wrapper canvas {
    max-width: 100%;
    height: auto !important;
}

/* ============================================
   COUNTRIES / GRID
   ============================================ */
.country-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.country-pill {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    cursor: pointer;
    text-align: center;
    transition: all var(--transition-fast);
    font-size: 0.95rem;
    color: var(--text-primary);
    font-family: inherit;
    font-weight: 500;
}

.country-pill:hover {
    border-color: var(--bitcoin-orange);
    transform: translateY(-1px);
}

.country-pill.active {
    background: var(--bitcoin-orange);
    color: var(--text-on-accent);
    border-color: var(--bitcoin-orange);
}

/* ============================================
   LOADING / SKELETON
   ============================================ */
.skeleton {
    background: linear-gradient(90deg,
        var(--bg-elevated) 0%,
        var(--bg-overlay-hover) 50%,
        var(--bg-elevated) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    min-height: 40px;
}

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

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(13, 17, 23, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    z-index: 10;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--bitcoin-orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   FOOTER
   ============================================ */
.site-footer {
    text-align: center;
    margin-top: 60px;
    padding-top: 30px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
}

.site-footer .footer-nav {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.site-footer .footer-nav a {
    color: var(--bitcoin-orange);
    text-decoration: none;
    transition: color 0.2s ease;
}

.site-footer .footer-nav a:hover {
    color: var(--bitcoin-orange-light);
    text-decoration: underline;
}

.footer-disclaimer {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1rem;
    font-style: italic;
}

/* ============================================
   TABLES
   ============================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 0.95rem;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg-elevated);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

/* ============================================
   ALERTS
   ============================================ */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    border-left: 4px solid;
    background: var(--bg-elevated);
}

.alert-success { border-left-color: var(--success); background: var(--success-muted); }
.alert-danger { border-left-color: var(--danger); background: var(--danger-muted); }
.alert-info { border-left-color: var(--info); background: var(--info-muted); }

/* ============================================
   INDEX (HUB) SPECIFIC
   ============================================ */
.hub-header {
    text-align: center;
    margin-bottom: 50px;
}

.hub-header h1 {
    font-size: clamp(2.2rem, 6vw, 3.2rem);
    margin: 0 0 12px;
}

.hub-subtitle {
    color: var(--text-secondary);
    font-size: 1.2rem;
    margin: 0;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

.tool-card {
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform var(--transition-normal),
                border-color var(--transition-normal),
                background var(--transition-normal);
}

.tool-card:hover,
.tool-card:focus-visible {
    transform: translateY(-4px);
    border-color: var(--bitcoin-orange);
    background: var(--bg-overlay-hover);
    outline: none;
}

.tool-card-icon {
    font-size: 2.4rem;
    color: var(--bitcoin-orange);
    margin-bottom: 14px;
    display: block;
}

.tool-card h2 {
    font-size: 1.3rem;
    margin: 0 0 8px;
}

.tool-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin: 0;
}

.tool-card .tool-badge {
    display: inline-block;
    background: var(--bitcoin-orange);
    color: var(--text-on-accent);
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 999px;
    font-weight: 700;
    margin-left: 6px;
    vertical-align: middle;
}

/* ============================================
   ERROR / 404
   ============================================ */
.error-page {
    min-height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.error-code {
    font-size: clamp(5rem, 15vw, 9rem);
    font-weight: 800;
    background: linear-gradient(135deg, var(--bitcoin-orange), var(--bitcoin-orange-light));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    line-height: 1;
    margin-bottom: 16px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
    :root {
        --container-padding: 24px 16px;
    }
    .page-header h1 { font-size: 1.8rem; }
    .metric-value { font-size: 1.3rem; }
    .tabs { gap: 0; }
    .tab { padding: 10px 12px; font-size: 0.85rem; }
}

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

/* ============================================
   PRINT
   ============================================ */
@media print {
    body { background: white; color: black; }
    .theme-toggle, .site-footer, .skip-link { display: none; }
    .card { border: 1px solid #ccc; box-shadow: none; }
}

/* ============================================
   SCROLLBAR (webkit/modern)
   ============================================ */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--bitcoin-orange);
}