/* Scoped to .sp so it won't fight with Main.css */
.sp {
    --sp-ink: #12261f;
    --sp-muted: #5d6f68;
    --sp-bg: #eef3f1;
    --sp-card: #ffffff;
    --sp-line: #dbe5e1;
    --sp-accent: #00FF00;
    --sp-accent-dark: #00D100;
    --sp-danger: #d6403f;
    --sp-warn: #b86e00;
    font-family: 'Be Vietnam Pro', 'Segoe UI', Arial, sans-serif;
    color: var(--sp-ink);
    background: var(--sp-bg);
    min-height: 100vh;
    padding: 2.5rem 3rem;
    box-sizing: border-box;
    line-height: 1.5;
}

.sp *,
.sp *::before,
.sp *::after {
    box-sizing: border-box;
}

.sp>* {
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}

.sp h1,
.sp h2 {
    margin: 0;
    line-height: 1.2;
    text-align: left;
}

.sp h1 {
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    font-weight: 700;
}

.sp h2 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: .9rem;
}

/* header */
.sp-head {
    /* margin-top: 5em; */
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    z-index: 1;
}

.sp-head h1 {
    margin-bottom: .5rem;
}

.sp-who {
    margin: 0 0 .25rem;
    color: var(--sp-muted);
    font-size: .9rem;
}

.sp-month {
    display: flex;
    gap: .5rem;
}

/* summary */
.sp-summary {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.sp-total {
    background: var(--sp-ink);
    color: #fff;
    border-radius: 14px;
    padding: 1.4rem 1.5rem;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    text-align: center;
}

.sp-total-stats {
    display: flex;
    gap: 1.3rem;
}

.sp-total .sp-total-mounth {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    text-align: center;
    gap: 1rem;
}

.sp-label {
    font-size: 1rem;
    color: #b9cfc6;
}

.sp-total strong {
    font-size: clamp(1rem, 6vw, 1.8rem);
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.1;
    word-break: break-word;
}

.sp-delta {
    font-size: .85rem;
    color: #b9cfc6;
}

.sp-delta.up {
    color: #ffb4a8;
}

.sp-delta.down {
    color: #8ff0c4;
}

.sp-stats {
    margin: 0;
    display: grid;
    gap: .6rem;
}

.sp-stats>div {
    background: var(--sp-card);
    border: 1px solid var(--sp-line);
    border-radius: 10px;
    padding: .7rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .75rem;
}

.sp-stats dt {
    color: var(--sp-muted);
    font-size: .88rem;
}

.sp-stats dd {
    margin: 0;
    font-weight: 600;
    text-align: right;
}

/* cards */
.sp-card {
    background: var(--sp-card);
    border: 1px solid var(--sp-line);
    border-radius: 14px;
    padding: 1.2rem 1.3rem;
    margin-bottom: 1rem;
}

.sp-charts {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1rem;
    margin-bottom: 0;
}

.sp-charts .sp-card {
    margin-bottom: 1rem;
}

.sp-chart {
    position: relative;
    height: 260px;
}

/* add form */
.sp-add {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: .75rem;
    align-items: end;
}

.sp label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .85rem;
    color: var(--sp-muted);
}

.sp input[type=text],
.sp input[type=number],
.sp input[type=search],
.sp select {
    font: inherit;
    color: var(--sp-ink);
    padding: .65rem .8rem;
    border: 1px solid var(--sp-line);
    border-radius: 8px;
    background: #fff;
    width: 100%;
    min-height: 44px;
}

.sp input:focus,
.sp select:focus {
    outline: 1px solid var(--sp-accent);
    outline-offset: -1px;
    border-color: var(--sp-accent);
}

.sp-errors {
    margin: .75rem 0 0;
    padding-left: 1.1rem;
    color: var(--sp-danger);
    font-size: .88rem;
}

.sp-hint {
    margin: .75rem 0 0;
    font-size: .85rem;
    color: var(--sp-warn);
}

/* buttons */
.sp-btn {
    font: inherit;
    font-weight: 600;
    font-size: .92rem;
    min-height: 44px;
    padding: 0 1.1rem;
    border-radius: 30px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background-color .15s, border-color .15s;
}

.sp-btn.primary {
    background-color: white;
    color: #000;
    box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
    border: none;
}

.sp-btn.primary:hover {
    background: #dedede;
}

.sp-btn.danger {
    background: var(--sp-danger);
    color: #fff;
}

.sp-btn.danger:hover {
    background: #b83332;
}

.sp-btn.ghost {
    background: #fff;
}

.sp-btn.ghost:hover {
    border-color: var(--sp-accent);
}

.sp-btn.disabled {
    opacity: .4;
    pointer-events: none;
}

.sp-btn:focus-visible,
.sp-icon:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 2px;
}

/* list */
.sp-listhead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: .6rem;
}

.sp-listhead h2 {
    margin: 0;
}

.sp-filter {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.sp-filter input[type=search] {
    width: 170px;
}

.sp-filter select {
    width: auto;
}

.sp-tablewrap {
    overflow-x: auto;
}

.sp table {
    width: 100%;
    border-collapse: collapse;
}

.sp th,
.sp td {
    padding: .75rem .6rem;
    border-bottom: 1px solid var(--sp-line);
    text-align: left;
    background: transparent;
}

.sp th {
    font-size: .82rem;
    font-weight: 600;
    color: var(--sp-muted);
}

.sp td.num,
.sp th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.sp td.act,
.sp th.act {
    text-align: right;
    white-space: nowrap;
}

.sp tbody tr:hover {
    background: #f6faf8;
}

.sp-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--sp-line);
    background: #fff;
    color: var(--sp-ink);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: .25rem;
}

.sp-icon:hover {
    border-color: var(--sp-accent);
    color: var(--sp-accent);
}

.sp-icon.danger:hover {
    border-color: var(--sp-danger);
    color: #fff;
    background: var(--sp-danger);
}

.sp-empty {
    color: var(--sp-muted);
    text-align: center;
    padding: 2rem 0 1rem;
    margin: 0;
}

/* dialogs */
.sp-dialog {
    border: 0;
    border-radius: 14px;
    padding: 1.4rem;
    width: min(92vw, 400px);
    font-family: 'Be Vietnam Pro', 'Segoe UI', Arial, sans-serif;
    color: #12261f;
    background-color: white;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    flex-direction: column;
}

.sp-dialog::backdrop {
    background: rgba(10, 25, 20, .55);
}

.sp-dialog form {
    display: grid;
    gap: .9rem;
}

.sp-dialog h2 {
    margin: 0;
    font-size: 1.15rem;
}

.sp-dialog label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    font-size: .85rem;
    color: #5d6f68;
}

.sp-dialog input {
    font: inherit;
    padding: .65rem .8rem;
    border: 1px solid #dbe5e1;
    background-color: white;
    color: black;
    border-radius: 8px;
    min-height: 44px;
}

.sp-dialog input:focus {
    outline: 2px solid #95ffd9;
    outline-offset: 1px;
}

.sp-del-text {
    margin: 0;
    padding: .75rem;
    background: #f6faf8;
    border-radius: 8px;
    font-weight: 600;
}

.sp-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1.5rem;
}

.sp-dialog .sp-btn {
    font-family: inherit;
    color: #000;
    background-color: var(--sp-danger);
    border: none;
    box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
}

.sp-dialog .sp-btn:hover {
    background: whitesmoke;
}

/* toasts */
.sp-toasts {
    position: fixed;
    top: 4.5rem;
    right: 1rem;
    z-index: 9999;
    display: grid;
    gap: .5rem;
    max-width: min(92vw, 340px);
}

.sp-toast {
    padding: .75rem 1rem;
    border-radius: 8px;
    color: #fff;
    font-size: .9rem;
    background: #2b6cb0;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
    transition: opacity .4s, transform .4s;
}

.sp-toast.success {
    background: var(--sp-accent);
}

.sp-toast.error {
    background: var(--sp-danger);
}

.sp-toast.gone {
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
}

/* Google Ad Container Styles */
#google-ad-container {
    grid-column: 1 / -1;
    /* Spans full width of the grid parent */
    margin-top: 20px;
    padding: 15px;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 8px;
    text-align: center;
}

.ad-label {
    color: #666;
    font-size: 12px;
    margin-bottom: 5px;
}

.ad-placeholder {
    width: 100%;
    height: 100px;
    background: #eee;
    border: 1px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
}




/* living cost section */
.sp {
    --sp-up: #d6403f;
    --sp-down: #0a8f4a;
}

.sp-card[id] {
    scroll-margin-top: 5rem;
}

.sp-living-form {
    grid-template-columns: 1fr 1fr auto;
}

.sp-hint-muted {
    color: var(--sp-muted);
}

.sp-living-chart {
    margin: 1.2rem 0;
}

.sp-cmp {
    margin-top: .6rem;
}

.sp-cmp-cap {
    text-align: left;
    font-size: .88rem;
    font-weight: 600;
    color: var(--sp-muted);
    padding: .4rem .6rem;
    caption-side: top;
}

.sp-cmp-total td {
    font-weight: 700;
    border-bottom: 0;
}

.sp-chg {
    font-weight: 600;
    white-space: nowrap;
}

.sp-chg.up {
    color: var(--sp-up);
}

.sp-chg.down {
    color: var(--sp-down);
}

.sp-chg.none {
    color: var(--sp-muted);
    font-weight: 400;
}

/* intro + how-to (details) */
.sp-guide summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    font-size: 1.05rem;
    font-weight: 600;
    min-height: 44px;
}

.sp-guide summary::-webkit-details-marker {
    display: none;
}

.sp-guide summary::after {
    content: "";
    flex: none;
    width: .6rem;
    height: .6rem;
    border-right: 2px solid var(--sp-muted);
    border-bottom: 2px solid var(--sp-muted);
    transform: rotate(45deg);
    transition: transform .15s;
}

.sp-guide[open] summary::after {
    transform: rotate(-135deg);
}

.sp-guide summary:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 4px;
    border-radius: 6px;
}

.sp-guide-body {
    max-width: 68ch;
    margin-top: .6rem;
    padding-top: 1rem;
    border-top: 1px solid var(--sp-line);
}

.sp-guide-body p {
    margin: 0 0 .5rem;
    line-height: 1.7;
}

.sp-guide-body p strong {
    display: block;
    margin-top: .9rem;
}

.sp-guide-body p:first-child strong {
    margin-top: 0;
}

/* mobile */
@media (max-width: 680px) {
    .sp>* {
        width: 100vw;
        padding: 1rem;
        margin: auto;
    }
    .sp {
        padding:0;
        
    }

    .sp-summary,
    .sp-charts {
        grid-template-columns: 1fr;
        padding-top: 0;
    }

    .sp-add,
    .sp-living-form {
        grid-template-columns: 1fr;
    }

    .sp-add .sp-btn {
        grid-column: 1 / -1;
    }

    .sp-filter,
    .sp-filter input[type=search],
    .sp-filter select {
        width: 100%;
    }

    .sp-chart {
        height: 230px;
    }

    /* Reduce container padding to save horizontal space */
    section.sp-summary {
        padding: 2rem 1rem;
        grid-template-columns: 1fr;
    }

    /* Optimize the total stats container */
    .sp-total {
        padding: 1rem;
        width: 100%;
        height: auto;
        /* Allow height to grow with content */
        align-items: center;
    }

    /* Ensure child elements stack or wrap properly */
    .sp-total-stats {
        flex-direction: column;
        /* Stack stats vertically if they are too wide */
        width: 100%;
        gap: 0.5rem;
        margin: 0.5rem 0;
    }

    .sp-total .sp-total-mounth {
        gap: 0;
    }

    .sp-delta {
        font-size: 0.8rem;
        margin-top: 0.5rem;
    }

}


@media (prefers-reduced-motion: reduce) {

    .sp-toast,
    .sp-btn {
        transition: none;
    }
}

/* floating draggable quick-jump button (lives outside .sp, so no scoped vars) */
.sp-fab {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 10000;
    font-family: 'Be Vietnam Pro', 'Segoe UI', Arial, sans-serif;
}

.sp-fab-bar {
    display: inline-flex;
    align-items: stretch;
    min-height: 48px;
    border: 2px solid #00FF00;
    border-radius: 30px;
    background: #12261f;
    color: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
    transition: box-shadow .15s, transform .15s;
}

.sp-fab:hover .sp-fab-bar {
    box-shadow: 0 8px 22px rgba(0, 0, 0, .35);
}

.sp-fab-main,
.sp-fab-toggle {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}

.sp-fab-main {
    padding: 0 .4rem 0 .75rem;
    font-size: .92rem;
    font-weight: 600;
    cursor: grab;
    touch-action: none;
    /* lets touch drag without scrolling the page */
    user-select: none;
    -webkit-user-select: none;
    border-radius: 30px 0 0 30px;
}

.sp-fab-toggle {
    padding: 0 .85rem 0 .4rem;
    cursor: pointer;
    min-width: 44px;
    justify-content: center;
    border-radius: 0 30px 30px 0;
}

.sp-fab-toggle svg {
    transition: transform .15s;
}

.sp-fab.open .sp-fab-toggle svg {
    transform: rotate(180deg);
}

.sp-fab-main:focus-visible,
.sp-fab-toggle:focus-visible {
    outline: 3px solid #00FF00;
    outline-offset: 3px;
}

.sp-fab.dragging .sp-fab-bar {
    transform: scale(1.05);
    transition: none;
}

.sp-fab.dragging .sp-fab-main {
    cursor: grabbing;
}

.sp-fab-grip {
    color: #8fa89d;
    font-size: 1.1rem;
    line-height: 1;
}

/* quick-jump menu: padding (not margin) as the gap, so hover never breaks between bar and menu */
.sp-fab-menu {
    position: absolute;
    left: 0;
    bottom: 100%;
    padding-bottom: .5rem;
    display: none;
    flex-direction: column;
    gap: .35rem;
    min-width: 190px;
}

.sp-fab.down .sp-fab-menu {
    bottom: auto;
    top: 100%;
    padding-bottom: 0;
    padding-top: .5rem;
}

.sp-fab.align-right .sp-fab-menu {
    left: auto;
    right: 0;
}

.sp-fab.open .sp-fab-menu,
.sp-fab:focus-within .sp-fab-menu {
    display: flex;
}

@media (hover: hover) {
    .sp-fab:hover .sp-fab-menu {
        display: flex;
    }
}

.sp-fab.dragging .sp-fab-menu {
    display: none !important;
}

.sp-fab-menu button {
    font: inherit;
    font-size: .9rem;
    font-weight: 600;
    min-height: 44px;
    padding: 0 1rem;
    text-align: left;
    color: #fff;
    background: #12261f;
    border: 1px solid #00FF00;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
}

.sp-fab-menu button:hover,
.sp-fab-menu button:focus-visible {
    background: #1d3d32;
    outline: none;
}

@media (prefers-reduced-motion: reduce) {

    .sp-guide summary::after,
    .sp-fab-bar,
    .sp-fab-toggle svg {
        transition: none;
    }
}
