/* FamilyKudos — mobile-first, big touch targets. */

:root {
    --bg: #f4f1ea;
    --card: #ffffff;
    --ink: #1f2a24;
    --muted: #6b7570;
    --line: #e2ddd2;
    --green: #2d6a4f;
    --green-soft: #d8f3dc;
    --red: #c0392b;
    --red-soft: #fde2df;
    --accent: #2d6a4f;
    --amber: #d9a520;
    --amber-soft: #fdf3d0;
    --radius: 16px;
    --tap: 52px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 17px;
    color: var(--ink);
    background: var(--bg);
    padding-bottom: calc(72px + var(--safe-bottom));
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 {
    margin: 0;
    font-weight: 700;
}

h2 {
    font-size: 1.15rem;
    margin: 20px 0 10px;
}

p {
    margin: 0 0 10px;
}

a {
    color: inherit;
    text-decoration: none;
}

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

.small {
    font-size: 0.85rem;
}

.error {
    color: var(--red);
}

.ok {
    color: var(--green);
}

.hidden,
[hidden] {
    display: none !important;
}

/* Top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(10px + var(--safe-top)) 16px 10px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.topbar h1 {
    font-size: 1.25rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-size: 2rem;
    line-height: 1;
    color: var(--accent);
    padding: 0 0 6px;
}

/* Views */
.view {
    padding: 16px;
    max-width: 640px;
    margin: 0 auto;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card {
    display: block;
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.member-card {
    position: relative;
    min-height: var(--tap);
}

.member-name {
    font-weight: 700;
    font-size: 1.1rem;
}

.member-balance {
    font-size: 2rem;
    font-weight: 800;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

.bar {
    height: 8px;
    background: var(--line);
    border-radius: 4px;
    margin-top: 10px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--green);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.bar-fill.low {
    background: var(--red);
}

.big-balance {
    text-align: center;
    padding: 24px 16px;
}

.big-balance .amount {
    font-size: 3rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.balance-block.minutes {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.big-balance .balance-block.minutes .amount {
    font-size: 2.2rem;
}

.balance-block.minutes .bar-fill {
    background: #3a86c8;
}

.balance-block.minutes .bar-fill.low {
    background: var(--red);
}

.unit-label {
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: 0 20px;
    border-radius: 14px;
    border: 0;
    font-size: 1.05rem;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    width: 100%;
}

.btn.secondary {
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--line);
}

.btn.danger {
    background: var(--red);
}

.btn:disabled {
    opacity: 0.5;
}

.btn-google {
    background: #fff;
    color: #1f1f1f;
    border: 1px solid #dadce0;
}

.btn-apple {
    background: #000;
    color: #fff;
}

.link {
    background: none;
    border: 0;
    color: var(--accent);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 10px 8px;
    min-height: 44px;
    cursor: pointer;
}

.link.danger {
    color: var(--red);
}

/* Item buttons (log screen) */
.item-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.item-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 6px;
    min-height: 84px;
    padding: 12px;
    border-radius: var(--radius);
    border: 2px solid transparent;
    background: var(--card);
    font-size: 1rem;
    font-weight: 600;
    text-align: left;
    color: var(--ink);
    cursor: pointer;
}

.item-btn.penalty {
    background: var(--red-soft);
}

.item-btn.reward {
    background: var(--green-soft);
}

.item-btn.custom {
    background: var(--card);
    border-style: dashed;
    border-color: var(--line);
}

.item-btn:active {
    border-color: var(--accent);
}

.item-amount {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.item-btn.penalty .item-amount {
    color: var(--red);
}

.item-btn.reward .item-amount {
    color: var(--green);
}

/* Lists */
ul.list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
}

.list-row, .event-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    min-height: var(--tap);
}

.list-row:last-child, .event-row:last-child {
    border-bottom: 0;
}

.list-row.inactive .row-title {
    text-decoration: line-through;
    color: var(--muted);
}

.row-main, .event-main {
    flex: 1;
    min-width: 0;
}

.row-title, .event-label {
    font-weight: 600;
}

.row-amount, .event-amount {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.event-amount.negative, .row-amount.negative {
    color: var(--red);
}

.event-amount.positive, .row-amount.positive {
    color: var(--green);
}

.event-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.event-actions .link {
    padding: 4px 6px;
    min-height: 32px;
}

.event-note {
    white-space: pre-wrap;
}

/* Charts */
.chart-card {
    padding: 12px 12px 8px;
}

.chart {
    width: 100%;
    height: auto;
    display: block;
}

.chart-axis {
    stroke: var(--line);
    stroke-width: 2;
}

.bar-reward {
    fill: var(--green);
}

.bar-penalty {
    fill: var(--red);
}

.bar-warning {
    fill: var(--amber);
}

.chart-label {
    font-size: 13px;
    fill: var(--muted);
    font-family: inherit;
}

.chart-totals {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 6px 4px 2px;
}

.chart-totals .positive {
    color: var(--green);
}

.chart-totals .negative {
    color: var(--red);
}

.chart-totals .warning,
.event-amount.warning,
.row-amount.warning {
    color: var(--amber);
}

.event-row.warning,
.list-row.warning {
    background: var(--amber-soft);
}

.badge-warning {
    align-self: flex-end;
    font-size: 0.8rem;
    font-weight: 700;
    color: #7a5b0a;
    background: var(--amber-soft);
    border-radius: 10px;
    padding: 2px 8px;
}

.badge-warning.used {
    color: #fff;
    background: var(--red);
}

.chart-card .unit-label {
    margin: 6px 4px 2px;
}

/* Chips for picking a member */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.chip {
    min-height: 44px;
    padding: 0 16px;
    border-radius: 22px;
    border: 1px solid var(--line);
    background: var(--card);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
}

.chip.selected {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Forms */
label.field {
    display: block;
    margin-bottom: 14px;
}

label.field > span {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 4px;
}

input[type="text"], input[type="number"], select, textarea {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    font-size: 1.05rem;
    font-family: inherit;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
}

textarea {
    min-height: 72px;
    resize: vertical;
}

label.check {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    font-weight: 600;
}

label.check input {
    width: 24px;
    height: 24px;
}

.amount-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.amount-input input {
    font-size: 1.6rem;
    font-weight: 700;
    text-align: right;
}

.amount-input .currency {
    font-size: 1.4rem;
    font-weight: 700;
}

.row-inline {
    display: flex;
    gap: 8px;
    align-items: center;
}

.row-inline > * {
    flex: 1;
}

/* Full-screen form (log an event, edit a rule, ...) */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

.sheet {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    min-height: 0;
    overflow: auto;
    background: var(--bg);
    padding: calc(16px + var(--safe-top)) 16px 0;
}

.sheet-title {
    font-size: 1.5rem;
    margin: 6px 0 18px;
}

.sheet-body {
    flex: 1;
}

.sheet-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 10px;
    padding: 12px 0 calc(16px + var(--safe-bottom));
    background: var(--bg);
}

/* Tab bar */
.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom);
}

.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 60px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}

.tabbar a.active {
    color: var(--accent);
}

.tab-icon {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(84px + var(--safe-bottom));
    transform: translateX(-50%);
    background: var(--ink);
    color: #fff;
    padding: 10px 18px;
    border-radius: 20px;
    font-weight: 600;
    z-index: 30;
    max-width: 90vw;
}

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

.message {
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--card);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 20px 0 10px;
}

.section-head h2 {
    margin: 0;
}

.period-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 8px 0 12px;
}

.period-nav .icon-btn {
    font-size: 1.6rem;
    padding-bottom: 4px;
}

.period-nav .period-label {
    font-weight: 700;
}

.invite-link {
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
    background: var(--card);
    padding: 8px 10px;
    border-radius: 10px;
    margin: 6px 0;
}

/* Login page */
body.login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-card .logo {
    border-radius: 22px;
    margin-bottom: 12px;
}

.login-card h1 {
    font-size: 1.8rem;
    margin-bottom: 6px;
}

.login-card .stack {
    margin-top: 20px;
}
