/* instrumenta-mobile -- the look the installable single-file apps (the ledgers) share.

   Layout and components only: the app screen, cards, fields, buttons, the custom select,
   the install prompt, toast, the maintenance overlay. The PALETTE is the app's: it declares
   these custom properties itself (and a prefers-color-scheme: light override), and they are
   what every rule below reads:

     --bg --card --accent --text --muted --border --input --error --success --shadow

   The defaults here are the base tokens, at zero specificity (:where), so an app's own
   :root block wins no matter which comes first. Apart from those properties and transparent
   black/white washes, the only colours below are the few that mean the same thing in every
   theme and every app, so they do not follow the palette: the +/- sign toggle (red / green),
   the toast (always a dark chip, with a green or red edge) and the offline banner (dark red).
   mobile.test.mjs pins exactly that set.

   Generated from src/mobile.css by build.mjs; edit the source. */

:where(:root) {
    --bg: var(--i-bg);
    --card: var(--i-card);
    --accent: var(--i-accent);
    --text: var(--i-text);
    --muted: var(--i-muted);
    --border: var(--i-border-strong);
    --input: var(--i-input-bg);
    --error: var(--i-error);
    --success: var(--i-success);
    --shadow: var(--i-shadow);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ── Auth screen ─────────────────────────────────────────── */
/* Shown by JS (display:flex); the shared <i-signin> does its own centring. */
#auth-screen > i-signin { flex: 1; }


.hidden { display: none !important; }

/* ── Main app screen ─────────────────────────────────────── */
#app-screen {
    display: none;
}

.app-card {
    background: var(--card);
    padding: 16px 14px 24px;
    min-height: 100vh;
    max-width: 600px;
    margin: 0 auto;
}

.app-branding {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border);
}

.app-logo {
    width: 50px;
    height: 50px;
    object-fit: contain;
    flex-shrink: 0;
}

.app-branding-text h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
}

.app-branding-text p {
    margin: 2px 0 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.app-header h1 { margin: 0; font-size: 1.4rem; }

/* The shared account menu (base/base.js), themed from this app's palette. */
i-account, i-signin {
    --i-account-bg: var(--card);
    --i-account-accent-hover: var(--accent);
    --i-account-surface: var(--input);
    --i-account-text: var(--text);
    --i-account-muted: var(--muted);
    --i-account-border: var(--border);
    --i-account-border-strong: var(--border);
    --i-account-accent: var(--accent);
    --i-account-error: var(--error);
    --i-account-success: var(--success);
    --i-account-input-bg: var(--input);
    --i-account-shadow: var(--shadow);
}

/* form fields */
.field { margin-bottom: 16px; }

.field label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 7px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.field input,
.field textarea {
    width: 100%;
    padding: 15px 16px;
    border-radius: 10px;
    border: 2px solid var(--border);
    font-size: 1.1rem;
    background: var(--input);
    color: var(--text);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    font-family: inherit;
}
.field input:focus,
.field textarea:focus { border-color: var(--accent); }

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

/* Amount row */
.amount-row {
    display: flex;
    border-radius: 10px;
    border: 2px solid var(--border);
    overflow: hidden;
}
.amount-row:focus-within { border-color: var(--accent); }

.sign-toggle {
    width: 3.6rem;
    flex-shrink: 0;
    align-self: stretch;
    border: none;
    border-radius: 0;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    appearance: none;
    -webkit-appearance: none;
    margin: -2px 0 -2px -2px;
}
.sign-toggle.neg { background: #ef4444; }
.sign-toggle.pos { background: #10b981; }

.amount-input {
    flex: 1;
    padding: 15px 16px;
    border: none !important;
    border-radius: 0 !important;
    font-family: monospace;
    font-size: 1.5rem;
    background: var(--input);
    color: var(--text);
    outline: none;
}

/* Submit button */
.submit-btn {
    width: 100%;
    padding: 17px;
    border-radius: 10px;
    border: none;
    font-size: 1.15rem;
    font-weight: 700;
    background: var(--accent);
    color: white;
    cursor: pointer;
    margin-top: 8px;
    transition: opacity 0.2s;
    position: relative;
    letter-spacing: 0.02em;
}
.submit-btn:disabled { opacity: 0.7; cursor: not-allowed; }
.submit-btn.loading { color: transparent; }
.submit-btn.loading::after {
    content: "";
    position: absolute;
    width: 1.25rem;
    height: 1.25rem;
    top: 50%; left: 50%;
    margin: -0.625rem 0 0 -0.625rem;
    border: 3px solid white;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #1e293b;
    color: #e5e7eb;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.95rem;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
    transition: transform 0.3s ease;
    z-index: 1000;
    white-space: nowrap;
    max-width: calc(100vw - 32px);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-left: 4px solid #22c55e; }
.toast.error   { border-left: 4px solid #ef4444; }

/* Offline banner */
.offline-banner {
    display: none;
    background: #7f1d1d;
    color: #fca5a5;
    text-align: center;
    padding: 8px;
    font-size: 0.85rem;
    border-radius: 8px;
    margin-bottom: 14px;
}

/* Schema loading state */
.schema-loading {
    text-align: center;
    padding: 40px 0;
    color: var(--muted);
    font-size: 0.9rem;
}

/* ── Custom searchable select ─────────────────────────────── */
.cs-wrap { position: relative; }

.cs-trigger {
    width: 100%;
    padding: 15px 46px 15px 16px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--input);
    color: var(--text);
    font-size: 1.1rem;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
    min-height: 54px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    touch-action: manipulation;
}
.cs-trigger:focus,
.cs-wrap.open .cs-trigger { border-color: var(--accent); }

.cs-display.cs-placeholder { color: var(--muted); }

.cs-chevron {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--muted);
    pointer-events: none;
    transition: transform 0.2s;
}
.cs-wrap.open .cs-chevron { transform: translateY(-50%) rotate(180deg); }

.cs-panel {
    position: absolute;
    z-index: 200;
    top: calc(100% + 4px);
    left: -14px;
    right: -14px;
    background: var(--card);
    border: 2px solid var(--accent);
    border-radius: 10px;
    box-shadow: 0 8px 28px var(--shadow);
    overflow: hidden;
}
.cs-panel[hidden] { display: none; }

.cs-search-bar {
    padding: 8px 8px 6px;
    border-bottom: 1px solid var(--border);
}

.cs-search {
    width: 100%;
    padding: 12px 14px;
    border-radius: 8px;
    border: 2px solid var(--border);
    background: var(--input);
    color: var(--text);
    font-size: 1.1rem;
    font-family: inherit;
    outline: none;
}
.cs-search:focus { border-color: var(--accent); }

.cs-list {
    list-style: none;
    margin: 0;
    padding: 4px;
    max-height: 220px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.cs-option {
    padding: 14px 16px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 1.05rem;
    transition: background 0.1s;
    user-select: none;
    -webkit-user-select: none;
}
.cs-option:hover        { background: rgba(59,130,246,0.12); }
.cs-option.cs-focused   { background: rgba(59,130,246,0.15); }
.cs-option.cs-selected  { background: rgba(59,130,246,0.18); color: var(--accent); font-weight: 500; }

.cs-no-results {
    padding: 14px;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
}

/* ── Section divider ─────────────────────────────────────── */
.section-divider {
    height: 1px;
    background: var(--border);
    margin: 18px 0 16px;
    opacity: 0.6;
}

/* ── Install Prompt Overlay ──────────────────────────────── */
.install-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 1);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.install-card {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 32px 24px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-width: 360px;
    width: 100%;
}

.install-header {
    margin-bottom: 20px;
}

.app-icon {
    width: 80px;
    height: 80px;
    border-radius: 18px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    margin: 0 auto 16px;
    display: block;
    object-fit: contain;
    background: rgba(59, 130, 246, 0.1);
    padding: 8px;
}

.app-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
    letter-spacing: -0.02em;
}

.app-description {
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

.instruction {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 24px;
    line-height: 1.6;
    background: rgba(59, 130, 246, 0.08);
    padding: 14px 12px;
    border-radius: 10px;
    border-left: 3px solid var(--accent);
}

.ios-share-icon {
    display: inline-block;
    margin: 0 4px;
    vertical-align: middle;
    width: 18px;
    height: 18px;
}

.ios-share-icon svg {
    width: 100%;
    height: 100%;
    color: var(--accent);
}

.install-overlay.hidden {
    display: none;
}

/* ── Maintenance Overlay ─────────────────────────────────── */
.maintenance-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.97);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.maintenance-overlay.hidden {
    display: none;
}

.maintenance-card {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 36px 28px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-width: 340px;
    width: 100%;
}

.maintenance-icon {
    font-size: 2.8rem;
    margin-bottom: 16px;
    line-height: 1;
}

.maintenance-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}

.maintenance-msg {
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.6;
    margin-bottom: 24px;
}

.maintenance-retry-btn {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
}

.maintenance-retry-btn:hover {
    opacity: 0.85;
}

@media (prefers-color-scheme: light) {
    .maintenance-overlay {
        background: rgba(226, 232, 240, 0.97);
    }
}

@media (prefers-color-scheme: light) {
    .install-overlay {
        background: rgba(226, 232, 240, 1);
    }

    .app-icon {
        background: rgba(29, 78, 216, 0.08);
    }

    .instruction {
        background: rgba(29, 78, 216, 0.08);
        border-left-color: var(--accent);
    }

    .install-close-btn:hover {
        background: rgba(29, 78, 216, 0.1);
    }
}

/* ── Image picker ────────────────────────────────────────── */
.img-pick-btn {
    width: 100%;
    padding: 18px 16px;
    border-radius: 10px;
    border: 2px dashed var(--border);
    background: var(--input);
    color: var(--muted);
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: border-color 0.15s, color 0.15s;
    touch-action: manipulation;
}
.img-pick-btn:hover, .img-pick-btn:focus {
    border-color: var(--accent);
    color: var(--text);
    outline: none;
}
.img-pick-btn svg { flex-shrink: 0; }
.img-upload-btn {
    width: 100%;
    padding: 9px 14px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: border-color 0.15s, color 0.15s;
    touch-action: manipulation;
    margin-top: 6px;
}
.img-upload-btn:hover,
.img-upload-btn:focus {
    border-color: var(--accent);
    color: var(--text);
    outline: none;
}
.img-upload-btn svg {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    opacity: 0.7;
}

.img-preview-wrap {
    position: relative;
    display: inline-block;
    width: 100%;
}
.img-preview {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 10px;
    display: block;
    border: 2px solid var(--border);
}
.img-remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.65);
    color: white;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.img-upload-status {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 6px;
    text-align: center;
    min-height: 1.2em;
}
