:root {
    --brand: #07C160;
    --brand-pressed: #06AD56;
    --page: #EDEDED;
    --surface: #FFFFFF;
    --text: #191919;
    --muted: #888888;
    --divider: #E5E5E5;
    --bubble-mine: #95EC69;
    --bubble-theirs: #FFFFFF;
    --transfer: #FA9D3B;
    --transfer-done: #F8C98F;
    --danger: #E64340;
    --secondary: #F2F2F2;
    --tabs-height: 58px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --page: #111111;
        --surface: #1E1E1E;
        --text: #EDEDED;
        --muted: #9A9A9A;
        --divider: #2C2C2C;
        --bubble-mine: #3EB575;
        --bubble-theirs: #2C2C2C;
        --secondary: #2C2C2C;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--page);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
h1 { font-size: 17px; font-weight: 600; margin: 0; }
h2 { font-size: 13px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; margin: 20px 16px 6px; }
.page h2, .card h2 { margin-left: 0; margin-right: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.error { color: var(--danger); }

/* Buttons and fields */
button, .button {
    font: inherit;
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--secondary);
    color: var(--text);
}
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--brand); color: #fff; }
.primary:hover:not(:disabled) { background: var(--brand-pressed); }
.secondary { background: var(--secondary); color: var(--text); }
.danger { color: var(--danger); }
.wide { width: 100%; height: 48px; font-size: 17px; }
button.small { padding: 6px 12px; font-size: 14px; }
.link { background: none; color: var(--brand); padding: 4px 8px; }
.center { display: block; margin: 8px auto; }

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--divider);
    border-radius: 8px;
    padding: 10px 12px;
    width: 100%;
    outline: none;
}
input:focus, select:focus { border-color: var(--brand); }

/* Start-up and sign-in */
.splash, .signin {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
}
.signin { max-width: 360px; margin: 0 auto; }
.signin h1 { font-size: 26px; }
.logo {
    width: 64px; height: 64px;
    border-radius: 16px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    font-size: 32px;
    display: flex; align-items: center; justify-content: center;
}
.logo.large { width: 88px; height: 88px; font-size: 44px; border-radius: 22px; }
.logo.small { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; display: inline-flex; }
.splash .logo { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* Shell: sidebar on wide screens, tab bar at the bottom on phones */
.shell { display: flex; min-height: 100vh; }
.tabs {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--divider);
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 16px; }
.tab {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text);
    position: relative;
}
.tab:hover { background: var(--secondary); }
.tab.active { color: var(--brand); background: var(--secondary); font-weight: 600; }
.tab .icon { font-size: 20px; width: 24px; text-align: center; }
.tab .badge { margin-left: auto; }
.content { flex: 1; min-width: 0; max-width: 820px; background: var(--page); display: flex; flex-direction: column; }
.offline { background: #FFF4D6; color: #7A5B00; font-size: 13px; text-align: center; padding: 4px; }

@media (max-width: 700px) {
    .shell { flex-direction: column; }
    .tabs {
        order: 2;
        position: fixed;
        top: auto; bottom: 0; left: 0; right: 0;
        width: auto;
        height: calc(var(--tabs-height) + env(safe-area-inset-bottom));
        padding: 4px 0 env(safe-area-inset-bottom);
        flex-direction: row;
        border-right: 0;
        border-top: 1px solid var(--divider);
        z-index: 10;
    }
    .brand { display: none; }
    .tab { flex: 1; flex-direction: column; gap: 2px; padding: 4px; font-size: 11px; background: none !important; }
    .tab .badge { position: absolute; top: 2px; left: 55%; margin: 0; }
    .content { max-width: none; padding-bottom: calc(var(--tabs-height) + env(safe-area-inset-bottom)); }
}

/* Top bar */
.bar {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--page);
    border-bottom: 1px solid var(--divider);
    padding: 0 48px;
}
.bar h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-back, .bar-action {
    position: absolute;
    top: 0; bottom: 0;
    display: flex; align-items: center;
    padding: 0 16px;
    font-size: 26px;
    color: var(--text);
    background: none;
}
.bar-back { left: 0; font-size: 32px; }
.bar-action { right: 0; }
.bar-action.text { font-size: 15px; color: var(--brand); border-radius: 0; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); }
.page .list { border-radius: 10px; overflow: hidden; }
.row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--divider);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--secondary); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-top, .row-bottom { display: flex; align-items: center; gap: 8px; }
.name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name.large { font-size: 20px; font-weight: 600; }
.row-top .name { flex: 1; }
.time { font-size: 12px; color: var(--muted); }
.preview { flex: 1; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chevron { color: var(--muted); font-size: 22px; }
.tick { color: var(--brand); font-size: 20px; }
.row .icon { font-size: 22px; }
.badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.avatar {
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    color: #fff;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--divider);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.empty { text-align: center; padding: 64px 24px; display: flex; flex-direction: column; gap: 12px; align-items: center; color: var(--muted); }

/* Pages with sections */
.page { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 4px; }
.card { background: var(--surface); border-radius: 10px; padding: 4px 16px 16px; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.card .list { background: none; }
.card .row { padding-left: 0; padding-right: 0; }
.inline-form { display: flex; gap: 8px; }
.inline-form button { flex-shrink: 0; }
.inline-form .narrow { max-width: 120px; }
.search { margin: 12px 0 0; }
.group-bar { display: flex; gap: 8px; margin-top: 8px; }
.group-bar button { flex-shrink: 0; }
.profile { display: flex; align-items: center; gap: 16px; background: var(--surface); border-radius: 10px; padding: 20px 16px; margin: 12px 0; }
.status { font-weight: 600; margin: 0; }
.status.ok { color: var(--brand); }
.balance { display: flex; justify-content: space-between; font-size: 18px; }
.notice { background: #FFF4D6; color: #7A5B00; border-radius: 8px; padding: 10px 12px; }

/* Forms */
.form { padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field .label { font-size: 13px; color: var(--muted); }
.field .value { font-size: 17px; padding: 6px 0; }
.amount { font-size: 28px; font-weight: 600; }

/* Chat */
.chat { display: flex; flex-direction: column; height: 100vh; }
@media (max-width: 700px) { .chat { height: calc(100vh - var(--tabs-height) - env(safe-area-inset-bottom)); } }
.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 10px; }
.stamp { align-self: center; font-size: 12px; color: var(--muted); background: rgba(0, 0, 0, .06); padding: 2px 8px; border-radius: 4px; }
.message { display: flex; gap: 8px; align-items: flex-start; max-width: 80%; }
.message.mine { align-self: flex-end; flex-direction: row-reverse; }
.message-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.message.mine .message-body { align-items: flex-end; }
.bubble {
    background: var(--bubble-theirs);
    padding: 9px 12px;
    border-radius: 6px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.4;
}
.mine .bubble { background: var(--bubble-mine); color: #111; }
.bubble.muted { font-style: italic; }
.delivery { font-size: 12px; color: var(--muted); background: none; padding: 0; }
.delivery.failed { color: var(--danger); }
.transfer { background: var(--transfer); color: #fff; border-radius: 6px; padding: 12px 14px; width: 240px; display: flex; flex-direction: column; gap: 4px; }
.transfer.done { background: var(--transfer-done); }
.transfer.failed { background: #C9C9C9; color: #333; }
.transfer-head { font-size: 13px; opacity: .9; }
.transfer-amount { font-size: 22px; font-weight: 600; }
.transfer-memo { font-size: 14px; }
.transfer-foot { border-top: 1px solid rgba(255, 255, 255, .4); margin-top: 6px; padding-top: 6px; font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.transfer-error { font-size: 12px; }
.typing { font-size: 12px; color: var(--muted); padding: 0 16px 4px; }
.composer {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    background: var(--secondary);
    border-top: 1px solid var(--divider);
}
.composer .round { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 22px; background: none; border: 1.5px solid var(--text); flex-shrink: 0; }
.actions { display: flex; gap: 24px; padding: 16px 20px; background: var(--secondary); }
.action { flex-direction: column; background: none; font-size: 13px; color: var(--muted); padding: 0; }
.action .glyph { width: 56px; height: 56px; border-radius: 12px; background: var(--surface); color: var(--text); font-size: 24px; display: flex; align-items: center; justify-content: center; }

/* Blazor's error bar */
#blazor-error-ui {
    background: #FFF4D6;
    color: #7A5B00;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
