* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: #f4f6f8;
    color: #1f2937;
}
.topbar {
    min-height: 64px;
    background: #173b57;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px max(18px, calc((100% - 1120px)/2));
    gap: 18px;
}
.topbar a { color: white; text-decoration: none; }
.brand { font-size: 20px; font-weight: 800; }
nav { display: flex; gap: 15px; flex-wrap: wrap; }
.container { max-width: 1120px; margin: 0 auto; padding: 24px 16px 60px; }
h1, h2, h3 { margin-top: 0; }
h1 { font-size: clamp(25px, 5vw, 36px); margin-bottom: 6px; }
h2 { font-size: 21px; }
.muted { color: #64748b; }
.page-head, .section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}
.badge, .month-total {
    background: #dff4e9;
    color: #166534;
    padding: 10px 14px;
    border-radius: 999px;
    font-weight: 700;
    white-space: nowrap;
}
.login-card, .panel, .budget-card {
    background: white;
    border-radius: 16px;
    padding: 22px;
    box-shadow: 0 7px 24px rgba(15, 23, 42, .07);
}
.login-card { max-width: 430px; margin: 55px auto; }
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 7px; font-weight: 650; }
input, select, button {
    width: 100%;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    padding: 10px 12px;
    font: inherit;
}
button { cursor: pointer; font-weight: 750; }
.primary { background: #16794a; color: white; border-color: #16794a; }
.secondary { background: #eef2f6; color: #334155; }
.danger { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.complete { background: #173b57; color: white; border-color: #173b57; font-size: 17px; }
.small { min-height: 36px; padding: 6px 10px; }
.button-link {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 42px;
    padding: 8px 14px;
    border-radius: 10px;
    text-decoration: none;
    background: #173b57;
    color: white;
    font-weight: 700;
}
.alert { padding: 12px 15px; border-radius: 10px; margin-bottom: 16px; }
.alert.success { background: #dcfce7; color: #166534; }
.alert.error { background: #fee2e2; color: #991b1b; }
.search-row { display: grid; grid-template-columns: 1fr 130px; gap: 10px; margin-bottom: 20px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr 130px; gap: 10px; }
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.product-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 17px;
    display: grid;
    gap: 11px;
}
.product-card h3, .product-card p { margin: 0; }
.inline { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel { margin-bottom: 20px; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}
.form-grid.four { grid-template-columns: repeat(4, 1fr); }
.form-grid button { grid-column: auto; }
.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}
.stats div {
    background: white;
    padding: 18px;
    border-radius: 14px;
    box-shadow: 0 7px 24px rgba(15, 23, 42, .06);
}
.stats span, .budget-card span { display: block; color: #64748b; margin-bottom: 5px; }
.stats strong, .budget-card strong { font-size: 24px; }
.budget-card {
    display: grid;
    grid-template-columns: repeat(3, 1fr) auto;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}
.progress {
    grid-column: 1 / -1;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: #e2e8f0;
}
.progress div { height: 100%; background: #16794a; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 660px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid #e2e8f0; vertical-align: top; }
th { color: #475569; font-size: 14px; }
td small { display: block; color: #64748b; margin-top: 4px; }
.status {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    margin-top: 5px;
    text-transform: capitalize;
}
.status.pending { background: #fff7d6; color: #854d0e; }
.status.purchased { background: #dcfce7; color: #166534; }
.status.skipped { background: #e2e8f0; color: #475569; }
.purchase-form { display: grid; grid-template-columns: minmax(105px, 1fr) auto; gap: 7px; margin-bottom: 7px; }
.complete-box { margin-top: 20px; }
.history-card small { color: #64748b; }
.product-edit-row {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr auto auto;
    gap: 8px;
    align-items: center;
}
.action-row { display: flex; gap: 6px; }

@media (max-width: 850px) {
    .form-grid, .form-grid.four { grid-template-columns: 1fr 1fr; }
    .form-grid button { grid-column: 1 / -1; }
    .budget-card { grid-template-columns: 1fr 1fr; }
    .product-edit-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .container { padding-top: 18px; }
    .page-head, .section-head { align-items: flex-start; flex-direction: column; }
    .search-row, .filter-row { grid-template-columns: 1fr; }
    .stats, .budget-card { grid-template-columns: 1fr; }
    .form-grid, .form-grid.four { grid-template-columns: 1fr; }
    .inline { grid-template-columns: 1fr 1fr; }
    .login-card { margin-top: 22px; }
    .product-edit-row { grid-template-columns: 1fr; }
}

.product-list { display: grid; gap: 10px; }
.product-edit-row {
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
}


/* Wife interface V3 — mobile first */
.topbar nav a.active {
    background: #ffffff;
    color: #173b57;
    border-radius: 5px;
    padding: 4px 8px;
}

.wife-mobile-page {
    background: #eef1f3;
}

.wife-mobile-page .container {
    max-width: 760px;
    padding: 0 12px 44px;
}

.wife-mobile-page .topbar {
    max-width: 760px;
    margin: 0 auto;
    padding: 10px 16px 11px;
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
    background: #073c52;
}

.wife-mobile-page .topbar .brand {
    font-size: 21px;
}

.wife-mobile-page .topbar nav {
    gap: 4px;
    font-size: 15px;
}

.wife-mobile-page .topbar nav a {
    padding: 4px 8px;
}

.wife-shell {
    min-height: calc(100vh - 90px);
    background: #ffffff;
    padding: 8px 8px 28px;
}

.wife-tools {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #ffffff;
    padding: 5px 0 9px;
}

.live-search {
    position: relative;
    display: block;
    margin-bottom: 9px;
}

.live-search span {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 21px;
}

.live-search input {
    min-height: 42px;
    padding-left: 38px;
    border: 2px solid #29485b;
    border-radius: 4px;
    font-size: 17px;
}

.live-search.is-disabled {
    opacity: .45;
}

.wife-tabs {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    padding: 0 0 4px;
    scrollbar-width: none;
}

.wife-tabs::-webkit-scrollbar {
    display: none;
}

.wife-tab {
    flex: 0 0 auto;
    width: auto;
    min-height: 36px;
    padding: 6px 10px;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: #36b84a;
    font-size: 16px;
    font-weight: 800;
    white-space: nowrap;
}

.wife-tab.is-active {
    background: #43ba4d;
    color: #ffffff;
}

.wife-tab.cart-tab {
    background: #e9f8ed;
}

.wife-tab.cart-tab.is-active {
    background: #073c52;
    color: #ffffff;
}

.wife-list {
    display: grid;
    gap: 7px;
    padding-top: 8px;
}

.wife-item {
    display: grid;
    grid-template-columns: 16px minmax(88px, 1fr) minmax(104px, 1.25fr) 58px;
    align-items: center;
    gap: 7px;
    min-height: 52px;
    padding: 5px 7px 5px 0;
    border-radius: 12px;
    background: #073c52;
    box-shadow: 0 2px 0 rgba(2, 27, 38, .12);
    transition: transform .15s ease, background .15s ease;
}

.wife-item:active {
    transform: scale(.995);
}

.wife-item.is-added {
    background: #0a5b4d;
}

.item-dot {
    width: 15px;
    height: 15px;
    margin-left: -7px;
    border-radius: 50%;
    background: #cbd1d5;
    border: 2px solid #ffffff;
}

.wife-item.is-added .item-dot {
    background: #3fc357;
}

.wife-item-name {
    overflow: hidden;
    color: #ffffff;
    font-size: 18px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wife-request {
    min-width: 0;
    min-height: 34px;
    padding: 7px 9px;
    border: 0;
    border-radius: 4px;
    background: #ffffff;
    font-size: 13px;
}

.quick-add {
    min-height: 34px;
    padding: 6px 4px;
    border: 0;
    border-radius: 4px;
    background: #79d7f1;
    color: #05394d;
    font-size: 11px;
    font-weight: 900;
}

.quick-add.is-added {
    background: #44bf55;
    color: #ffffff;
}

.quick-add:disabled {
    opacity: .7;
}

.empty-state {
    padding: 24px 15px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    color: #64748b;
    text-align: center;
}

.cart-view {
    padding-top: 12px;
}

.cart-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 13px;
}

.cart-heading h1 {
    margin: 0 0 3px;
    font-size: 25px;
}

.cart-heading p {
    margin: 0;
    color: #64748b;
    font-size: 13px;
}

.cart-total {
    flex: 0 0 auto;
    padding: 7px 10px;
    border-radius: 999px;
    background: #e8f7ec;
    color: #16803f;
    font-size: 13px;
    font-weight: 800;
}

.custom-item-card {
    margin-bottom: 14px;
    padding: 12px;
    border-radius: 12px;
    background: #edf8f0;
}

.custom-item-card h2 {
    margin: 0 0 9px;
    font-size: 17px;
}

.custom-item-fields {
    display: grid;
    grid-template-columns: 1fr 1fr 58px;
    gap: 7px;
}

.custom-item-fields input,
.custom-item-fields button {
    min-height: 39px;
}

.custom-item-fields button {
    border: 0;
    background: #16834b;
    color: #ffffff;
}

.cart-items {
    display: grid;
    gap: 8px;
}

.cart-item {
    padding: 11px;
    border: 1px solid #d8e1e6;
    border-radius: 12px;
    background: #ffffff;
}

.cart-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.cart-item-top strong {
    font-size: 17px;
}

.cart-item-actions {
    display: grid;
    grid-template-columns: 1fr 70px 70px;
    gap: 7px;
}

.cart-item-actions input,
.cart-item-actions button {
    min-height: 38px;
    padding: 7px 8px;
}

.cart-update {
    border: 0;
    background: #073c52;
    color: #ffffff;
}

.cart-remove {
    border: 0;
    background: #fee2e2;
    color: #a41515;
}

.wife-toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 100;
    max-width: calc(100vw - 30px);
    padding: 10px 14px;
    border-radius: 999px;
    background: #153d2d;
    color: #ffffff;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 12px);
    transition: opacity .2s ease, transform .2s ease;
}

.wife-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.wife-toast.is-error {
    background: #9b1c1c;
}

[hidden] {
    display: none !important;
}

@media (min-width: 640px) {
    .wife-mobile-page .topbar {
        flex-direction: row;
        align-items: center;
    }

    .wife-item {
        grid-template-columns: 18px minmax(150px, 1fr) minmax(180px, 1fr) 72px;
        padding-right: 10px;
    }

    .wife-item-name {
        font-size: 20px;
    }

    .quick-add {
        font-size: 12px;
    }
}


/* V4: visible All Cart and simpler item maintenance */
.wife-top-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 7px;
    margin-bottom: 9px;
}

.wife-top-row .live-search {
    min-width: 0;
    margin-bottom: 0;
}

.all-cart-button {
    width: auto;
    min-height: 42px;
    padding: 7px 11px;
    border: 0;
    border-radius: 5px;
    background: #073c52;
    color: #ffffff;
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
}

.all-cart-button span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    margin-left: 3px;
    padding: 0 5px;
    border-radius: 999px;
    background: #46be55;
    color: #ffffff;
}

.all-cart-button.is-active {
    background: #42b950;
}

.item-file-error {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 7px;
    background: #fee2e2;
    color: #991b1b;
    font-size: 12px;
}

@media (max-width: 370px) {
    .all-cart-button {
        padding-inline: 8px;
        font-size: 12px;
    }
}
