:root {
    --primary: #03173d;
    --primary-light: #0a2a5e;
    --accent: #1b6ec2;
    --accent-light: #e8f1fa;
    --bg: #f2f4f8;
    --text: #1f2937;
    --text-muted: #6b7280;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --header-h: calc(56px + env(safe-area-inset-top, 0px));
    --nav-h: calc(60px + env(safe-area-inset-bottom, 0px));
}

html, body {
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    margin: 0;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

input, textarea, select, [contenteditable] {
    -webkit-user-select: text;
    user-select: text;
}

h1:focus {
    outline: none;
}

a, .btn-link {
    color: var(--accent);
}

#app {
    height: 100%;
}

/* ============ APP SHELL ============ */

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 520px;
    margin: 0 auto;
    background: var(--bg);
    position: relative;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.08);
}

/* Top app bar */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: #fff;
    padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 12px;
    min-height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.app-header .header-title {
    font-size: 1.15rem;
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header .header-subtitle {
    font-size: 0.75rem;
    opacity: 0.8;
    display: block;
    font-weight: 400;
}

.header-btn {
    background: none;
    border: none;
    color: #fff;
    padding: 6px;
    display: flex;
    align-items: center;
    border-radius: 50%;
    cursor: pointer;
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

.header-btn svg {
    width: 24px;
    height: 24px;
}

/* Scrollable content */
.app-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px 24px;
}

.app-content.no-nav {
    padding-bottom: 16px;
}

/* Bottom navigation */
.bottom-nav {
    display: flex;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: var(--nav-h);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.68rem;
    padding: 6px 0;
    cursor: pointer;
}

.bottom-nav .nav-item svg {
    width: 24px;
    height: 24px;
}

.bottom-nav .nav-item.active {
    color: var(--accent);
    font-weight: 600;
}

.bottom-nav .nav-item:active {
    background: var(--accent-light);
}

/* ============ COMPONENTS ============ */

/* Cards */
.app-card {
    background: #fff;
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border: none;
}

.app-card .card-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
}

/* Menu grid (home) */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px 8px;
}

.menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--text);
    cursor: pointer;
}

.menu-item .menu-icon {
    width: 54px;
    height: 54px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.menu-item .menu-icon svg {
    width: 26px;
    height: 26px;
}

.menu-item .menu-label {
    font-size: 0.7rem;
    text-align: center;
    line-height: 1.2;
    color: var(--text);
}

.menu-item:active .menu-icon {
    transform: scale(0.93);
}

/* List items */
.app-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.list-item {
    background: #fff;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text);
    cursor: pointer;
}

.list-item:active {
    background: #f8fafc;
}

.list-item .item-body {
    flex: 1;
    min-width: 0;
}

.list-item .item-title {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item .item-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Status badges */
.status-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    white-space: nowrap;
}

.status-badge.success { background: #dcfce7; color: var(--success); }
.status-badge.danger  { background: #fee2e2; color: var(--danger); }
.status-badge.warning { background: #fef3c7; color: var(--warning); }
.status-badge.info    { background: var(--accent-light); color: var(--accent); }
.status-badge.muted   { background: #f3f4f6; color: var(--text-muted); }

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: calc(var(--nav-h) + 20px);
    right: max(20px, calc(50% - 240px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(27, 110, 194, 0.4);
    z-index: 20;
    cursor: pointer;
}

.fab svg {
    width: 26px;
    height: 26px;
}

.fab:active {
    transform: scale(0.93);
}

/* Buttons */
.btn-app {
    border-radius: 12px;
    padding: 12px;
    font-weight: 600;
    width: 100%;
    border: none;
    min-height: 48px;
}

.btn-app-primary {
    background: var(--accent);
    color: #fff;
}

.btn-app-primary:disabled {
    background: #9ca3af;
}

.btn-app-outline {
    background: #fff;
    color: var(--accent);
    border: 1.5px solid var(--accent);
}

/* Forms */
.form-label-app {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.form-control, .form-select {
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 1rem;
    border: 1.5px solid #e5e7eb;
    min-height: 48px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem rgba(27, 110, 194, 0.15);
}

/* Login page */
.login-page {
    min-height: 100dvh;
    background: linear-gradient(160deg, var(--primary) 0%, var(--primary-light) 55%, #0d3b80 100%);
    display: flex;
    flex-direction: column;
    padding: calc(env(safe-area-inset-top, 0px) + 48px) 28px calc(env(safe-area-inset-bottom, 0px) + 24px);
}

.login-page .login-logo {
    text-align: center;
    color: #fff;
    margin-bottom: 36px;
}

.login-page .login-logo .app-name {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.login-page .login-logo .app-tagline {
    font-size: 0.85rem;
    opacity: 0.75;
    margin-top: 4px;
}

.login-card {
    background: #fff;
    border-radius: 20px;
    padding: 28px 22px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

/* Section header */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 18px 2px 10px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    opacity: 0.35;
    margin-bottom: 12px;
}

/* Loading spinner overlay */
.loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-muted);
    gap: 12px;
}

.spinner-app {
    width: 36px;
    height: 36px;
    border: 3.5px solid #e5e7eb;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Tab bar */
.tab-bar {
    display: flex;
    background: #fff;
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 14px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.tab-bar .tab-item {
    flex: 1;
    text-align: center;
    padding: 9px 4px;
    border-radius: 9px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
}

.tab-bar .tab-item.active {
    background: var(--accent);
    color: #fff;
}

/* Search bar */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.search-bar .form-control {
    flex: 1;
}

/* Detail rows */
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.9rem;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-row .label {
    color: var(--text-muted);
}

.detail-row .value {
    font-weight: 600;
    text-align: right;
}

/* Validation */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
    font-size: 0.8rem;
}

/* Blazor default UI bits */
#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.loading-progress {
    position: relative;
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 30vh auto 1rem auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(30vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}
