:root {
    --app-bg: #0f172a;
    --app-surface: #111827;
    --app-surface-2: #1f2937;
    --app-card: rgba(255,255,255,0.08);
    --app-border: rgba(255,255,255,0.08);
    --app-text: #f8fafc;
    --app-text-muted: #94a3b8;
    --app-accent: #22c55e;
    --app-accent-soft: rgba(34,197,94,0.18);
    --app-danger: #ef4444;
    --app-shadow: 0 10px 30px rgba(0,0,0,0.28);
    --topbar-height: 74px;
    --bottomnav-height: 82px;
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
}

html, body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at top left, rgba(34,197,94,0.10), transparent 28%), radial-gradient(circle at top right, rgba(59,130,246,0.10), transparent 32%), linear-gradient(180deg, #0f172a 0%, #111827 100%);
    color: var(--app-text);
    min-height: 100%;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.miniapp-body {
    min-height: 100vh;
    color: var(--app-text);
    background: transparent;
}

.miniapp-shell {
    min-height: 100vh;
    padding-top: calc(env(safe-area-inset-top) + 10px);
    padding-bottom: calc(var(--bottomnav-height) + env(safe-area-inset-bottom) + 10px);
}

.miniapp-topbar {
    position: sticky;
    top: 0;
    z-index: 1050;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    min-height: var(--topbar-height);
    padding: 12px 14px;
    backdrop-filter: blur(20px);
    background: rgba(15, 23, 42, 0.72);
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.miniapp-topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.miniapp-brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 8px 18px rgba(34,197,94,0.30);
}

.miniapp-brand-title {
    font-size: 15px;
    font-weight: 800;
    line-height: 1.1;
}

.miniapp-brand-subtitle {
    font-size: 12px;
    color: var(--app-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.db-chip {
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.06);
    color: var(--app-text);
    border-radius: 999px;
    height: 42px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    max-width: 190px;
    box-shadow: var(--app-shadow);
}

    .db-chip span {
        display: inline-block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.db-chip-arrow {
    font-size: 11px;
    opacity: 0.8;
}

.miniapp-content {
    padding: 14px 14px 8px;
}

.miniapp-bottomnav {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom) + 10px);
    z-index: 1100;
    height: var(--bottomnav-height);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    gap: 6px;
    padding: 8px;
    border-radius: 26px;
    background: rgba(17,24,39,0.92);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}

.miniapp-nav-item {
    color: var(--app-text-muted);
    text-decoration: none;
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 700;
    transition: all .18s ease;
}

    .miniapp-nav-item i {
        font-size: 20px;
        line-height: 1;
    }

    .miniapp-nav-item.active {
        background: linear-gradient(180deg, rgba(34,197,94,0.22), rgba(34,197,94,0.10));
        color: #dcfce7;
        box-shadow: inset 0 0 0 1px rgba(34,197,94,0.20);
    }

    .miniapp-nav-item:active {
        transform: scale(0.97);
    }

.database-modal .modal-dialog {
    margin: 0;
    min-height: 100%;
    display: flex;
    align-items: flex-end;
}

.database-modal-content {
    border: 0;
    border-radius: 28px 28px 0 0;
    background: #0f172a;
    color: var(--app-text);
    height: min(88vh, 720px);
    width: 100%;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.database-modal-handle {
    width: 52px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255,255,255,0.18);
    margin: 10px auto 6px;
    flex-shrink: 0;
}

.database-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 16px 12px;
    flex-shrink: 0;
}

.database-modal-title {
    font-size: 19px;
    font-weight: 800;
}

.database-modal-subtitle {
    font-size: 13px;
    color: var(--app-text-muted);
    margin-top: 2px;
}

.database-list {
    padding: 0 14px 20px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.database-form + .database-form {
    margin-top: 10px;
}

.database-item {
    width: 100%;
    min-height: 72px;
    border: 1px solid rgba(255,255,255,0.07);
    background: rgba(255,255,255,0.05);
    color: var(--app-text);
    border-radius: 18px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    transition: all .18s ease;
}

    .database-item.active {
        background: linear-gradient(180deg, rgba(34,197,94,0.16), rgba(34,197,94,0.08));
        border-color: rgba(34,197,94,0.24);
    }

.database-list {
    padding: 0 14px 16px;
}

.database-form + .database-form {
    margin-top: 10px;
}

.database-item {
    width: 100%;
    border: 1px solid rgba(255,255,255,0.07);
    background: rgba(255,255,255,0.05);
    color: var(--app-text);
    border-radius: 18px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    transition: all .18s ease;
}

    .database-item.active {
        background: linear-gradient(180deg, rgba(34,197,94,0.16), rgba(34,197,94,0.08));
        border-color: rgba(34,197,94,0.24);
    }

.database-item-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(34,197,94,0.14);
    color: #86efac;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.database-item-body {
    min-width: 0;
    flex: 1;
}

.database-item-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.database-item-subtitle {
    font-size: 12px;
    color: var(--app-text-muted);
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.database-item-side {
    flex-shrink: 0;
    color: var(--app-text-muted);
}

.database-current-badge {
    color: #86efac;
    font-size: 18px;
}

.empty-block {
    min-height: 160px;
    border-radius: 18px;
    border: 1px dashed rgba(255,255,255,0.12);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--app-text-muted);
    gap: 10px;
}

    .empty-block i {
        font-size: 26px;
    }

.card-glass {
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.05);
    border-radius: 22px;
    box-shadow: var(--app-shadow);
    color: var(--app-text);
}

.btn-accent {
    border: 0;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 700;
}

.btn-soft {
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.06);
    color: var(--app-text);
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 700;
}

.form-control,
.form-select {
    min-height: 48px;
    border-radius: 14px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--app-text);
}

    .form-control:focus,
    .form-select:focus {
        background: rgba(255,255,255,0.08);
        color: var(--app-text);
        border-color: rgba(34,197,94,0.34);
        box-shadow: 0 0 0 .2rem rgba(34,197,94,.12);
    }

    .form-control::placeholder {
        color: #94a3b8;
    }

.btn-close {
    filter: invert(1);
    opacity: 0.9;
}

@media (min-width: 768px) {
    .miniapp-shell {
        max-width: 560px;
        margin: 0 auto;
        position: relative;
    }

    .miniapp-topbar {
        border-radius: 0 0 22px 22px;
    }

    .miniapp-bottomnav {
        max-width: 540px;
        margin: 0 auto;
    }
}
