/* ============================================================
   THR Calculator — Bento Glassmorphism UI
   ============================================================ */

:root {
    --sys-bg: #eceef2;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.6);
    --glass-shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.04);

    --color-primary: #000000;
    --color-text: #1d1d1f;
    --color-text-mut: #6e6e73;

    --radius-bento: 32px;
    --radius-input: 18px;
    --radius-btn: 20px;

    --font-base: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-base);
    background-color: var(--sys-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px 16px;
    position: relative;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Ambient Background ── */
.ambient-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    background: #f4f7fb;
}

.blob {
    position: absolute;
    filter: blur(90px);
    border-radius: 50%;
    opacity: 0.5;
    animation: float 25s infinite ease-in-out alternate;
}

.blob-1 {
    width: 500px;
    height: 500px;
    background: #ffb8d8;
    top: -10%;
    left: -10%;
    animation-delay: 0s;
}

.blob-2 {
    width: 600px;
    height: 600px;
    background: #b8e2ff;
    bottom: -20%;
    right: -10%;
    animation-delay: -5s;
}

.blob-3 {
    width: 400px;
    height: 400px;
    background: #dab8ff;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1) rotate(0deg);
    }

    100% {
        transform: translate(80px, 40px) scale(1.15) rotate(10deg);
    }
}

/* ── Bento Grid ── */
.bento-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    width: 100%;
    max-width: 900px;
    margin: auto;
    grid-auto-rows: min-content;
    transition: all 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (min-width: 768px) {
    .bento-grid {
        grid-template-columns: repeat(12, 1fr);
    }

    .item-header {
        grid-column: span 12;
    }

    .item-info {
        grid-column: span 12;
    }

    .item-form {
        grid-column: span 6;
        grid-row: 3 / 5;
    }

    .item-result {
        grid-column: span 6;
        grid-row: 3;
    }

    .item-breakdown {
        grid-column: span 6;
        grid-row: 4;
    }
}

/* ── Glass Cards ── */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-bento);
    box-shadow: var(--glass-shadow);
    padding: 36px;
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.4s ease;
}

.glass:hover {
    transform: translateY(-2px) scale(1.005);
    box-shadow: 0 16px 48px 0 rgba(31, 38, 135, 0.08);
}

/* ── Typo & Details ── */
.text-gradient {
    background: linear-gradient(135deg, #1d1d1f 0%, #434343 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -1.2px;
}

.subtitle {
    color: var(--color-text-mut);
    font-size: 16px;
    font-weight: 500;
    margin-top: 6px;
}

.item-header {
    padding: 32px 36px;
}

.item-info {
    padding: 24px 36px;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
}

.info-content {
    display: flex;
    align-items: center;
    gap: 18px;
}

.info-icon {
    color: var(--color-primary);
    flex-shrink: 0;
}

.info-text p {
    font-size: 15px;
    color: var(--color-text-mut);
    margin-bottom: 3px;
    line-height: 1.4;
}

.info-text strong {
    color: var(--color-text);
    font-weight: 700;
}

/* ── Forms ── */
.item-form {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.field-group label {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-mut);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-left: 2px;
}

.mt-3 {
    margin-top: 24px;
}

.mt-4 {
    margin-top: 36px;
}

input[type="date"],
input[type="text"],
.input-currency input {
    width: 100%;
    background: rgba(255, 255, 255, 0.5);
    border: 1.5px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-input);
    padding: 18px;
    font-size: 17px;
    font-family: inherit;
    font-weight: 600;
    color: var(--color-text);
    transition: all 0.25s ease;
    outline: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.01);
}

input[type="date"]:focus,
input[type="text"]:focus,
.input-currency input:focus {
    background: #fff;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

.input-currency {
    position: relative;
}

.currency-prefix {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-mut);
    font-weight: 600;
    font-size: 17px;
    pointer-events: none;
}

.input-currency input {
    padding-left: 54px;
}

/* Error animation */
@keyframes shakeX {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-6px);
    }

    75% {
        transform: translateX(6px);
    }
}

.invalid {
    border-color: #FF3B30 !important;
    animation: shakeX .4s ease;
}

/* Button */
.btn-primary {
    width: 100%;
    background: #007AFF;
    /* Apple Blue */
    color: #fff;
    border: none;
    border-radius: var(--radius-btn);
    padding: 20px 24px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 8px 24px rgba(0, 122, 255, 0.25);
}

.btn-primary:hover {
    background: #006ce6;
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(0, 122, 255, 0.35);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.15);
}

/* Bento Hide/Show Animation via height */
.hide-bento {
    display: none !important;
}

.show-bento {
    display: flex;
    flex-direction: column;
    animation: popIn 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.96) translateY(24px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ── Result ── */
.item-result {
    background: linear-gradient(135deg, #007AFF 0%, #005bb5 100%);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    justify-content: center;
    box-shadow: 0 16px 40px rgba(0, 122, 255, 0.15);
}

.result-label {
    font-size: 14px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    margin-bottom: 12px;
    letter-spacing: 1px;
}

.result-amount-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 16px;
}

.currency-symbol {
    font-size: 24px;
    font-weight: 700;
    margin-top: 6px;
    color: rgba(255, 255, 255, 0.5);
}

.result-amount {
    font-size: clamp(32px, 8vw, 56px);
    /* Fluid typography */
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    word-break: break-all;
    /* Prevents overflow completely */
}

.result-desc {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.6;
}

/* ── Breakdown ── */
.breakdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.item-breakdown h3 {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 0;
    letter-spacing: -0.5px;
}

.btn-print {
    background: transparent;
    color: var(--color-text-mut);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-print:hover {
    color: var(--color-text);
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.2);
}

.breakdown-row {
    display: flex;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    font-size: 15px;
    opacity: 0;
    transform: translateY(8px);
    animation: rowFade 0.5s ease forwards;
}

@keyframes rowFade {
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.breakdown-row.total {
    border-bottom: none;
    border-top: 2px solid rgba(0, 0, 0, 0.1);
    font-weight: 700;
    margin-top: 8px;
    padding-top: 18px;
    font-size: 16px;
}

.b-label {
    color: var(--color-text-mut);
}

.b-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.total .b-label {
    color: var(--color-text);
}

.total .b-value {
    color: var(--color-text);
}

@media (max-width: 768px) {
    .glass {
        padding: 24px;
        border-radius: 24px;
    }

    .item-header {
        padding: 24px;
    }

    .text-gradient {
        font-size: 28px;
    }

    .result-amount {
        font-size: 42px;
    }

    .btn-primary {
        padding: 18px;
        font-size: 16px;
    }

    input[type="date"],
    .input-currency input {
        padding: 16px;
    }

    .item-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
}

/* ── Image Export Receipt ── */
.receipt-wrapper {
    position: fixed;
    top: -9999px;
    left: -9999px;
    z-index: -999;
}

.receipt-export {
    width: 480px;
    background: #ffffff;
    padding: 48px 40px;
    border-radius: 20px;
    color: #1d1d1f;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
}

.receipt-brand {
    text-align: center;
    margin-bottom: 24px;
}

.receipt-brand h2 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.receipt-brand p {
    font-size: 14px;
    color: #6e6e73;
    font-weight: 500;
}

.receipt-divider {
    height: 2px;
    background: #1d1d1f;
    margin: 24px 0;
}

.receipt-divider.dashed {
    background: transparent;
    border-top: 2px dashed #d2d2d7;
}

.receipt-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.receipt-row {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
}

.receipt-row.total {
    font-weight: 800;
    font-size: 18px;
    margin-top: 8px;
    padding-top: 18px;
    border-top: 2px solid rgba(0, 0, 0, 0.05);
}

.r-label {
    color: #6e6e73;
}

.r-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #1d1d1f;
}

.receipt-footer {
    text-align: center;
    margin-top: 32px;
}

.receipt-footer p {
    font-size: 14px;
    line-height: 1.6;
    color: #1d1d1f;
    margin-bottom: 24px;
}

.receipt-date {
    font-size: 12px;
    font-weight: 600;
    color: #86868b;
    text-transform: uppercase;
    letter-spacing: 1px;
}