/*
 * AINNA Tools — responsive hub (mobile + desktop)
 * Revamp 2026-07-17: fix horizontal overflow, header offset, card grid
 */

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
    background: #ffffff;
    min-height: 100dvh;
    min-height: 100vh;
    color: #1d1d1f;
    padding-bottom: 0;
    transition: background 0.3s ease, color 0.3s ease;
    overflow-x: clip;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
}

body.tools-page .container {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    /* room for fixed theme toggle + worldcup chip */
    padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 32px;
    padding-top: max(72px, calc(56px + env(safe-area-inset-top, 0px)));
    min-width: 0;
}

body.dark-tools {
    background: #0f172a;
    color: #f0f0f0;
}

/* ---------- Ambient backgrounds ---------- */
.tools-bg-blobs {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
}
.tools-bg-blobs .blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.6;
    animation: toolsBlobFloat 8s ease-in-out infinite;
}
.tools-bg-blobs .blob-1 {
    top: -10%; left: -10%;
    width: 400px; height: 400px;
    background: #ff6b9d;
    animation-delay: 0s;
}
.tools-bg-blobs .blob-2 {
    top: 20%; right: -10%;
    width: 500px; height: 500px;
    background: #4ecdc4;
    opacity: 0.4;
    animation-delay: 2s;
}
.tools-bg-blobs .blob-3 {
    bottom: -10%; left: 30%;
    width: 400px; height: 400px;
    background: #95e1d3;
    opacity: 0.4;
    animation-delay: 4s;
}
body.dark-tools .tools-bg-blobs .blob-1 { background: rgba(255,107,157,0.15); }
body.dark-tools .tools-bg-blobs .blob-2 { background: rgba(79,70,229,0.1); }
body.dark-tools .tools-bg-blobs .blob-3 { background: rgba(16,185,129,0.12); }
@keyframes toolsBlobFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-30px) scale(1.1); }
}
.tools-bg-grid {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.05;
    background-image:
        linear-gradient(#1d1d1f 1px, transparent 1px),
        linear-gradient(90deg, #1d1d1f 1px, transparent 1px);
    background-size: 60px 60px;
}
body.dark-tools .tools-bg-grid {
    opacity: 0.03;
    background-image:
        linear-gradient(#f8fafc 1px, transparent 1px),
        linear-gradient(90deg, #f8fafc 1px, transparent 1px);
}
.tools-aurora-container {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    transition: opacity 1s ease;
}
body.dark-tools .tools-aurora-container { opacity: 1; }
.tools-aurora-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
    animation: toolsAuroraFloat 20s infinite ease-in-out;
    mix-blend-mode: screen;
}
.tools-aurora-1 {
    width: 600px; height: 600px;
    background: linear-gradient(135deg, #ff6b9d, #8b5cf6);
    top: -20%; left: -10%;
    animation-duration: 25s;
}
.tools-aurora-2 {
    width: 500px; height: 500px;
    background: linear-gradient(135deg, #00f5ff, #06f);
    top: 50%; right: -15%;
    animation-delay: -5s;
    animation-duration: 30s;
}
.tools-aurora-3 {
    width: 700px; height: 700px;
    background: linear-gradient(135deg, #8b5cf6, #ff6b9d);
    bottom: -25%; left: 30%;
    animation-delay: -10s;
    animation-duration: 28s;
}
@keyframes toolsAuroraFloat {
    0%, 100% { transform: translate(0,0) scale(1) rotate(0); }
    25% { transform: translate(10%,15%) scale(1.1) rotate(90deg); }
    50% { transform: translate(-5%,10%) scale(0.9) rotate(180deg); }
    75% { transform: translate(15%,-10%) scale(1.05) rotate(270deg); }
}

/* ---------- Header ---------- */
.tools-page-header {
    margin-bottom: 8px;
    max-width: min(100%, 720px);
    padding-right: 0;
}
/* Reserve space so fixed day/night + WC chip never cover title on narrow screens */
@media (max-width: 720px) {
    .tools-page-header {
        padding-right: 0;
        margin-bottom: 4px;
    }
    body.tools-page .container {
        /* theme slot sits top-right; keep title clear of it */
        padding-top: max(78px, calc(64px + env(safe-area-inset-top, 0px)));
    }
}

body.tools-page h1 {
    font-size: clamp(1.5rem, 4.2vw, 2rem);
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
    line-height: 1.2;
    max-width: 100%;
}
.subtitle {
    font-size: clamp(13px, 2.5vw, 15px);
    color: #86868b;
    margin-bottom: 18px;
    line-height: 1.45;
    max-width: 42rem;
}
body.dark-tools .subtitle { color: #a0a0b0; }

/* ---------- Footer spacing ---------- */
body.tools-page footer.ainna-page-footer {
    position: relative !important;
    top: 30px !important;
    bottom: auto !important;
    margin-top: 18px !important;
    margin-bottom: 0 !important;
    padding-top: 18px !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
body.tools-page footer.ainna-page-footer .ainna-page-footer-inner {
    display: grid !important;
    gap: 8px !important;
    min-width: 0;
    max-width: 100%;
}
body.tools-page footer.ainna-page-footer .ainna-page-footer-lang,
body.tools-page footer.ainna-page-footer .ainna-page-footer-vpn,
body.tools-page footer.ainna-page-footer .ainna-page-footer-links,
body.tools-page footer.ainna-page-footer .ainna-page-footer-cutout-row {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    max-width: 100%;
    min-width: 0;
}
body.tools-page footer.ainna-page-footer .ainna-page-footer-lang a {
    min-height: 32px !important;
    padding: 6px 14px !important;
}
body.tools-page footer.ainna-page-footer .ainna-page-footer-vpn {
    padding: 6px 12px !important;
    line-height: 1.3 !important;
    overflow-wrap: anywhere;
    word-break: break-word;
}
body.tools-page footer.ainna-page-footer .ainna-page-footer-links {
    gap: 8px !important;
    flex-wrap: wrap;
}
body.tools-page footer.ainna-page-footer .ainna-page-footer-cutout-row {
    min-height: var(--ainna-footer-cutout-d, var(--ainna-dock-cutout-d, 72px)) !important;
}

/* ---------- Sticky toolbar ---------- */
.tools-toolbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    padding: 10px 0 12px;
    margin: 0 -4px 18px;
    padding-left: 4px;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-bottom: 1px solid transparent;
    width: auto;
    max-width: 100%;
    min-width: 0;
}
body.dark-tools .tools-toolbar {
    background: rgba(15,23,42,0.9);
}
.tools-search {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 11px 14px;
    border-radius: 12px;
    border: 1px solid #d2d2d7;
    font-size: 16px; /* prevent iOS zoom */
    background: #fff;
    -webkit-appearance: none;
    appearance: none;
}
body.dark-tools .tools-search {
    background: #1e293b;
    border-color: #334155;
    color: #f0f0f0;
}
.tools-search:focus {
    outline: none;
    border-color: #0071e3;
    box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
}
body.dark-tools .tools-search:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(129,140,248,0.2);
}

.tools-categories {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    max-width: 100%;
    padding-bottom: 2px;
}
.tools-categories::-webkit-scrollbar { display: none; }
.tools-cat-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid #d2d2d7;
    background: #f8f9fa;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    min-height: 36px;
    touch-action: manipulation;
    white-space: nowrap;
}
.tools-cat-btn.active,
.tools-cat-btn:hover {
    background: #0071e3;
    border-color: #0071e3;
    color: #fff;
}
body.dark-tools .tools-cat-btn {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}
body.dark-tools .tools-cat-btn.active,
body.dark-tools .tools-cat-btn:hover {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

.tools-empty {
    display: none;
    text-align: center;
    color: #86868b;
    padding: 48px 12px;
}
.tools-empty.visible { display: block; }

/* ---------- Tool grid (overflow-safe) ---------- */
.tools-grid {
    display: grid;
    /* minmax(0,…) prevents 1fr from expanding past viewport (classic CSS grid bug) */
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    gap: 14px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
.tool-card.hidden { display: none !important; }
.tool-card {
    background: #f8f9fa;
    border-radius: 14px;
    padding: 16px;
    transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
    text-decoration: none;
    color: inherit;
    border: 1px solid #d2d2d7;
    opacity: 0;
    transform: translateY(12px);
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}
.tool-card.animate-in {
    opacity: 1;
    transform: translateY(0);
}
body.dark-tools .tool-card {
    background: #1e293b;
    border-color: #2a2a3e;
    color: #f0f0f0;
}
.tool-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.08);
    border-color: #0071e3;
}
body.dark-tools .tool-card:hover {
    border-color: #667eea;
    box-shadow: 0 6px 16px rgba(102,126,234,0.15);
}
.tool-card:focus-visible {
    outline: 2px solid #0071e3;
    outline-offset: 2px;
}
.tool-icon {
    font-size: 28px;
    margin-bottom: 8px;
    line-height: 1;
    flex-shrink: 0;
}
.tool-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.tool-desc {
    font-size: 12px;
    color: #86868b;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}
body.dark-tools .tool-desc { color: #94a3b8; }
.badge {
    display: inline-block;
    padding: 2px 8px;
    background: #34c759;
    color: #fff;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    margin-top: 8px;
    align-self: flex-start;
    letter-spacing: 0.02em;
}
.badge-new { background: #0071e3; }

/* Bank Statement Compiler — red glass morphism */
.tool-card.tool-card--bank-compiler {
    background: linear-gradient(135deg, rgba(254, 226, 226, 0.72), rgba(255, 255, 255, 0.45));
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(239, 68, 68, 0.38);
    box-shadow:
        0 0 18px rgba(239, 68, 68, 0.14),
        inset 0 1px 0 rgba(255, 255, 255, 0.65),
        inset 0 -1px 0 rgba(239, 68, 68, 0.08);
}
.tool-card.tool-card--bank-compiler .tool-title { color: #991b1b; }
.tool-card.tool-card--bank-compiler .tool-desc { color: #b91c1c; opacity: 0.85; }
.tool-card.tool-card--bank-compiler .badge-new {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35);
}
.tool-card.tool-card--bank-compiler:hover {
    transform: translateY(-3px);
    border-color: #ef4444;
    box-shadow:
        0 0 28px rgba(239, 68, 68, 0.32),
        0 10px 24px rgba(127, 29, 29, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.75);
}
body.dark-tools .tool-card.tool-card--bank-compiler {
    background: linear-gradient(135deg, rgba(69, 10, 10, 0.62), rgba(30, 41, 59, 0.48));
    border-color: rgba(239, 68, 68, 0.45);
    box-shadow:
        0 0 16px rgba(239, 68, 68, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        inset 0 -1px 0 rgba(239, 68, 68, 0.12);
}
body.dark-tools .tool-card.tool-card--bank-compiler .tool-title { color: #fecaca; }
body.dark-tools .tool-card.tool-card--bank-compiler .tool-desc { color: #fca5a5; opacity: 1; }
body.dark-tools .tool-card.tool-card--bank-compiler:hover {
    border-color: #f87171;
    box-shadow:
        0 0 32px rgba(239, 68, 68, 0.42),
        0 10px 26px rgba(0, 0, 0, 0.28),
        inset 0 0 0 1px rgba(248, 113, 113, 0.15);
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .tools-bg-blobs .blob,
    .tools-aurora-blob { animation: none !important; }
    .tool-card { transition: none; opacity: 1; transform: none; }
}

/* Touch: no hover lift fighting taps */
@media (hover: none) {
    .tool-card:hover { transform: none; box-shadow: none; }
    .tool-card:active {
        transform: scale(0.98);
        border-color: #0071e3;
    }
    body.dark-tools .tool-card:active { border-color: #667eea; }
    .tool-card.tool-card--bank-compiler:hover { transform: none; }
}

/* ---------- Breakpoints ---------- */
@media (max-width: 900px) {
    .tools-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
}

@media (max-width: 768px) {
    body.tools-page .container {
        padding-left: 14px;
        padding-right: 14px;
        padding-bottom: 28px;
    }
    body.tools-page footer.ainna-page-footer { top: 22px !important; }
    .tools-bg-blobs .blob { display: none; }
    .tools-aurora-container { display: none; }
    .tools-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
    .tool-card { padding: 12px; border-radius: 12px; }
    .tool-icon { font-size: 24px; margin-bottom: 6px; }
    .tool-title { font-size: 13px; }
    .tool-desc {
        font-size: 11px;
        -webkit-line-clamp: 2;
    }
    .tools-toolbar {
        margin-left: -2px;
        margin-right: -2px;
        padding-left: 2px;
        padding-right: 2px;
    }
    .tools-cat-btn {
        padding: 7px 12px;
        font-size: 11.5px;
        min-height: 34px;
    }
}

@media (max-width: 380px) {
    body.tools-page .container {
        padding-left: 12px;
        padding-right: 12px;
    }
    .tools-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .tool-card {
        padding: 14px;
        flex-direction: column;
        align-items: stretch;
    }
    .tool-icon {
        font-size: 26px;
        margin-bottom: 6px;
    }
    .tool-title {
        font-size: 14px;
        margin-bottom: 4px;
        white-space: normal;
        overflow-wrap: break-word;
    }
    .tool-desc {
        -webkit-line-clamp: 2;
        font-size: 12px;
    }
    .badge { margin-top: 8px; }
}

/* Desktop polish */
@media (min-width: 901px) {
    body.tools-page .container {
        padding: 40px 28px 40px;
        padding-top: max(48px, calc(36px + env(safe-area-inset-top, 0px)));
    }
    .tools-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 16px;
    }
    .tool-card { padding: 18px; }
    .tool-icon { font-size: 30px; }
    .tool-title { font-size: 15px; }
    .tool-desc { font-size: 13px; -webkit-line-clamp: 3; }
    .tools-search { font-size: 14px; max-width: 480px; }
}

@media (min-width: 1200px) {
    .tools-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
