:root {
    --primary: #0f6e6e;
    --primary-dark: #0a4f4f;
    --bg: #f4f7f6;
    --card: #ffffff;
    --text: #1c2b2b;
    --muted: #6b7b7b;
    --danger: #d64545;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    padding-bottom: env(safe-area-inset-bottom);
}

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

.login-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 24px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    text-align: center;
}

.login-emoji { font-size: 48px; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-form label { font-size: 13px; color: var(--muted); font-weight: 600; }

.login-form select,
.login-form input {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #dde5e3;
    font-size: 16px;
    background: #fafcfb;
}

.error-box {
    background: #fdecec;
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 16px;
}

.login-form button, .submit-btn {
    margin-top: 8px;
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.login-form button:active, .submit-btn:active { background: var(--primary-dark); }

/* ---------- App shell ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--primary);
    color: white;
    padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
}
.topbar-title { font-size: 18px; }
.topbar-user { font-size: 14px; display: flex; align-items: center; gap: 10px; opacity: 0.95; }
.logout-link { color: white; text-decoration: none; font-size: 18px; opacity: 0.85; }
.topbar-trip { display: flex; align-items: center; gap: 4px; margin-left: auto; margin-right: 10px; }
.topbar-trip select { width: auto; max-width: 150px; padding: 6px 8px; border: 1px solid rgba(255,255,255,.45); border-radius: 7px; background: rgba(255,255,255,.12); color: white; font-size: 12px; }
.topbar-trip select option { color: #1c2b2b; background: white; }
.topbar-new-trip { border: 0; border-radius: 7px; padding: 5px 7px; background: rgba(255,255,255,.18); color: white; font-size: 16px; cursor: pointer; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }

.trip-bar {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 16px;
}
.trip-select-field { margin: 0; flex: 1; min-width: 0; }
#new-trip-btn { flex-shrink: 0; }
#trip_id { height: auto; }
#new-trip-btn.secondary-btn { height: 46px; box-sizing: border-box; }
.secondary-btn, .text-btn {
    border: 1px solid var(--primary);
    color: var(--primary);
    background: white;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}
.secondary-btn:active { background: #e6f2f1; }
.full-width { width: 100%; }
.hidden { display: none; }

/* ---------- Totals ---------- */
.totals {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}
.total-pill {
    background: var(--card);
    border-radius: 999px;
    padding: 8px 16px;
    font-weight: 700;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    cursor: pointer;
    border: 0;
    color: var(--text);
    font-family: inherit;
}
.total-pill span { color: var(--primary); }
.total-pill em { font-style: normal; color: var(--text); }
.conversion-normal { font-weight: 400; }
.overview-card { flex: 1; min-width: 0; text-align: left; border: 0; background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: 0 2px 8px rgba(0,0,0,.05); cursor: pointer; color: var(--text); }
.overview-card span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.overview-card strong { color: var(--primary); font-size: 14px; line-height: 1.35; }
.overview-card em { font-style: normal; color: var(--text); }
.tab-nav { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 16px; padding-bottom: 2px; }
.tab-btn { flex: 0 0 auto; border: 1px solid #cddbd8; background: white; color: var(--primary); border-radius: 999px; padding: 9px 12px; font-size: 12px; font-weight: 700; cursor: pointer; }
.tab-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.summary-details { display: flex; flex-direction: column; gap: 8px; }
.summary-details .daily-row { padding: 12px; font-size: 14px; }
.summary-details .daily-row { cursor: pointer; }
.summary-details .daily-row span:last-child { font-weight: 700; }
.summary-details .daily-row span:last-child span { font-weight: 400; }
.summary-details .daily-row span:first-child { font-weight: 600; }
.summary-link { cursor: pointer; }
.summary-details .daily-row em { display: inline-block; margin-left: 6px; font-style: normal; color: var(--primary); }
.summary-details .daily-grand-total em { color: #ffe066; font-size: 1.05em; }
.summary-details .daily-grand-total em strong { color: #ffe066; }
.summary-final { white-space: nowrap; }
.new-expense-details { margin-bottom: 24px; }
.new-expense-details > summary { list-style: none; cursor: pointer; background: white; border: 1px solid #d7e4e1; border-radius: 10px; padding: 10px 14px; color: var(--primary); font-size: 14px; font-weight: 700; box-shadow: 0 1px 5px rgba(0,0,0,.04); }
.new-expense-details > summary::-webkit-details-marker { display: none; }
.new-expense-details > summary { position: relative; padding-right: 42px; }
.new-expense-details > summary::after { content: ''; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; border-right: 2px solid var(--primary); border-bottom: 2px solid var(--primary); transform: translateY(-65%) rotate(45deg); transition: transform .18s ease; }
.new-expense-details[open] > summary { background: #f0f8f7; }
.new-expense-details[open] > summary::after { transform: translateY(-35%) rotate(225deg); }
.new-expense-details .expense-form { margin-top: 8px; margin-bottom: 0; }
.daily-grand-total span span { font-weight: 400; }
.daily-grand-total em { font-style: normal; margin-left: 6px; }
.exchange-rate { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.exchange-rate label { color: var(--muted); font-size: 12px; font-weight: 700; }
.exchange-rate input { max-width: 130px; padding: 8px 10px; }
.home-cash-summary { display: flex; gap: 8px; margin-bottom: 16px; }
.home-cash-card { flex: 1; background: #e7f3f1; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.home-cash-card span { color: var(--muted); font-size: 11px; }
.home-cash-card strong { color: var(--primary); font-size: 16px; }

/* ---------- Cash ---------- */
.cash-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 16px;
}
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-heading h2 { margin: 0; font-size: 16px; color: var(--muted); }
.text-btn { padding: 6px 0; border: 0; }
.cash-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cash-card { background: #f0f8f7; border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 3px; }
.cash-card span, .cash-card small { color: var(--muted); font-size: 11px; }
.cash-card strong { color: var(--primary); font-size: 16px; }
.cash-card.over-budget { background: #fdecec; }
.cash-card.over-budget strong { color: var(--danger); }
.trip-cost-section { margin-top: 16px; }
.total-cost-card { background: #e7f3f1; }
.trip-cost-items { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.trip-cost-section .cash-summary { display: flex; flex-direction: column; gap: 8px; }
.trip-cost-section .cash-summary > .cash-card,
.trip-cost-section .cash-summary > .expense-item { width: 100%; min-width: 0; }
.cash-form { padding-top: 14px; }
.cash-expense-heading { margin: 20px 0 10px; font-size: 15px; color: var(--muted); }

/* ---------- Form ---------- */
.expense-form {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}

.row { display: flex; gap: 10px; }
.field { flex: 1; margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.field.grow { flex: 1.4; }
.currency-field { flex: 0.8; }

.field label { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }

input[type="text"], input[type="number"], input[type="date"], select {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #dde5e3;
    font-size: 16px;
    background: #fafcfb;
    width: 100%;
}
textarea { padding: 12px 14px; border-radius: 10px; border: 1px solid #dde5e3; font: inherit; font-size: 16px; background: #fafcfb; width: 100%; resize: vertical; }
.optional-label { font-weight: 400; text-transform: none; letter-spacing: normal; }

.segmented {
    display: flex;
    border: 1px solid #dde5e3;
    border-radius: 10px;
    overflow: hidden;
}
.seg-btn {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: #fafcfb;
    font-size: 14px;
    cursor: pointer;
    color: var(--text);
}
.seg-btn + .seg-btn { border-left: 1px solid #dde5e3; }
.seg-btn.active { background: var(--primary); color: white; font-weight: 700; }

.submit-btn { width: 100%; margin-top: 4px; }

/* ---------- List ---------- */
.list-section h2 { font-size: 16px; margin: 0 0 10px; color: var(--muted); }

.daily-summary { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.daily-row { background: #e9f4f3; border-radius: 9px; padding: 9px 11px; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.daily-row > span:last-child { text-align: right; }
.daily-grand-total { background: var(--primary); color: white; font-weight: 700; }

.expense-list { display: flex; flex-direction: column; gap: 8px; }

.expense-item {
    background: var(--card);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 6px rgba(0,0,0,0.04);
}

.expense-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.expense-title { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.expense-meta { font-size: 12px; color: var(--muted); }

.expense-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.expense-amount { font-weight: 700; font-size: 15px; white-space: nowrap; }
.expense-method { font-size: 18px; }
.note-btn { border: 0; background: transparent; font-size: 17px; padding: 3px; cursor: pointer; }
.note-btn:hover, .note-btn:focus { transform: scale(1.12); }
.note-modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; padding: 16px; background: rgba(20, 35, 35, .45); }
.note-modal.hidden { display: none; }
.note-modal-card { width: min(100%, 480px); background: white; border-radius: 18px; padding: 18px; box-shadow: 0 12px 35px rgba(0,0,0,.22); animation: note-slide-up .18s ease-out; }
.note-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.note-modal-head h2 { margin: 0; font-size: 18px; color: var(--primary); }
.note-modal-close { border: 0; background: #edf5f3; color: var(--primary); border-radius: 50%; width: 32px; height: 32px; font-size: 24px; line-height: 1; cursor: pointer; }
.note-modal-card p { margin: 14px 0 2px; white-space: pre-wrap; line-height: 1.5; color: var(--text); overflow-wrap: anywhere; }
.note-modal-message { margin: 14px 0 2px; }
.note-modal-view { margin: 14px 0 2px; white-space: pre-wrap; line-height: 1.5; overflow-wrap: anywhere; }
@keyframes note-slide-up { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.delete-btn {
    border: none;
    background: transparent;
    color: var(--danger);
    font-size: 14px;
    opacity: .45;
    cursor: pointer;
    padding: 4px 6px;
}
.delete-btn:hover { opacity: .9; }
.note-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.note-modal-actions .submit-btn { width: auto; margin-top: 0; padding: 10px 16px; }
.note-modal-actions .secondary-btn { padding: 10px 16px; }

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 40px 0;
    font-size: 14px;
}

@media (min-width: 600px) {
    main { padding: 24px; }
}

@media (max-width: 380px) {
    .topbar-title { font-size: 15px; }
    .topbar-trip { margin-right: 4px; }
    .topbar-trip select { max-width: 105px; }
    .trip-bar { align-items: stretch; flex-direction: column; }
    .cash-summary { grid-template-columns: 1fr; }
}
