:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-light: #6366f1;
    --brand-gradient: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
    --brand-gradient-subtle: linear-gradient(135deg, rgba(79, 70, 229, 0.08) 0%, rgba(59, 130, 246, 0.04) 100%);
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.85);
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    
    --ok: #10b981;
    --ok-light: #d1fae5;
    --warn: #f59e0b;
    --warn-light: #fef3c7;
    --info: #3b82f6;
    --info-light: #dbeafe;
    --danger: #ef4444;
    --danger-light: #fee2e2;

    --nav-h: 68px;
    --top-h: 60px;

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;

    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 32px -4px rgba(79, 70, 229, 0.15), 0 4px 12px -2px rgba(15, 23, 42, 0.05);
    --shadow-glow: 0 8px 24px rgba(79, 70, 229, 0.3);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: "Prompt", "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

body.app-body {
    padding-bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px));
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseGlow {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.5); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(79, 70, 229, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}

@keyframes toastSlideDown {
    from { opacity: 0; transform: translateY(-20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes modalScaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

/* Typography & Form Controls */
.app-input, .form-control, .form-select, textarea.form-control {
    min-height: 48px;
    font-size: 0.95rem !important;
    border-radius: 14px !important;
    border: 1.5px solid var(--border) !important;
    background-color: #fff !important;
    color: var(--text) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    padding: 10px 14px !important;
}

.app-input:focus, .form-control:focus, .form-select:focus, textarea.form-control:focus {
    border-color: var(--brand) !important;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.14) !important;
    outline: none !important;
}

.form-label {
    font-weight: 600;
    font-size: 0.875rem;
    color: #334155;
    margin-bottom: 0.4rem;
}

/* Custom Buttons */
.btn {
    font-weight: 500;
    border-radius: 14px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary, .app-btn-primary {
    background: var(--brand-gradient) !important;
    border: none !important;
    color: #fff !important;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35) !important;
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.45) !important;
    transform: translateY(-1px);
}

.btn-outline-primary {
    color: var(--brand) !important;
    border: 1.5px solid var(--brand) !important;
    background: transparent !important;
}

.btn-outline-primary:hover {
    background: rgba(79, 70, 229, 0.08) !important;
}

.btn-outline-secondary {
    color: #475569 !important;
    border: 1.5px solid var(--border) !important;
    background: #fff !important;
}

.btn-outline-secondary:hover {
    background: #f1f5f9 !important;
    border-color: #cbd5e1 !important;
}

.app-btn {
    min-height: 48px;
    min-width: 48px;
}

/* Header Topbar */
.app-topbar {
    position: sticky; top: 0; z-index: 1020;
    min-height: var(--top-h);
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.03);
}

.app-logo-mark {
    width: 40px; height: 40px; border-radius: 12px;
    background: var(--brand-gradient); color: #fff;
    display: grid; place-items: center; font-size: 1.2rem;
    box-shadow: var(--shadow-glow);
}

.app-logo-mark.lg {
    width: 64px; height: 64px; border-radius: 20px;
    margin: 0 auto 16px; font-size: 2rem;
}

.app-title { font-weight: 700; font-size: 1.05rem; color: var(--text); letter-spacing: -0.01em; }
.app-subtitle { font-size: 0.78rem; color: var(--text-muted); font-weight: 400; }

.icon-btn {
    position: relative; display: grid; place-items: center;
    width: 42px; height: 42px; border-radius: 12px;
    color: #475569; background: rgba(241, 245, 249, 0.8);
    text-decoration: none; transition: all 0.2s ease;
    border: 1px solid var(--border);
}

.icon-btn:hover { background: #e2e8f0; color: var(--brand); }

.notif-badge {
    position: absolute; top: -3px; right: -3px;
    background: var(--danger); color: #fff; border-radius: 99px;
    font-size: 10px; font-weight: 700; padding: 2px 6px; min-width: 18px;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    animation: badgePulse 2s infinite;
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.user-chip-badge {
    background: rgba(241, 245, 249, 0.8);
    border: 1px solid var(--border);
    padding: 4px 12px 4px 6px;
    border-radius: 99px;
    font-size: 0.85rem;
}

.user-avatar-small {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--brand-gradient); color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: 0.75rem;
}

.online-dot-wrap { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; }
.online-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
.online-dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }

.offline-banner {
    background: #fffbebf5; color: #b45309; text-align: center; padding: 10px 16px;
    font-size: 0.85rem; font-weight: 500; border-bottom: 1px solid #fde68a;
    backdrop-filter: blur(8px);
}

/* Main Container */
.app-main {
    padding: 16px 16px 32px;
    max-width: 960px;
    margin: 0 auto;
    animation: fadeInUp 0.35s ease-out;
}

/* Floating Bottom Navigation */
.bottom-nav {
    position: fixed; left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 1030; height: var(--nav-h);
    max-width: 540px; margin: 0 auto;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 24px;
    box-shadow: 0 12px 40px -6px rgba(15, 23, 42, 0.12);
    display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 6px;
}

.bottom-nav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; text-decoration: none; color: var(--text-muted); font-size: 0.72rem; font-weight: 500;
    border-radius: 18px; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); position: relative;
}

.bottom-nav a i { font-size: 1.25rem; transition: transform 0.2s ease; }

.bottom-nav a.active {
    color: var(--brand); font-weight: 700;
    background: rgba(79, 70, 229, 0.08);
}

.bottom-nav a.active i { transform: translateY(-1px) scale(1.1); }

.bottom-nav .nav-plus {
    position: relative;
    top: -14px;
    color: var(--brand);
}

.bottom-nav .nav-plus-btn {
    width: 46px; height: 46px; border-radius: 50%;
    background: var(--brand-gradient); color: #fff;
    display: grid; place-items: center; font-size: 1.3rem;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
    transition: transform 0.2s ease;
}

.bottom-nav .nav-plus:active .nav-plus-btn { transform: scale(0.9); }

/* Panels & Cards */
.panel {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-top: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.panel h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0 0 14px;
    color: var(--text);
    display: flex; align-items: center; gap: 8px;
}

/* Stat Cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: 6px;
    position: relative; overflow: hidden;
    transition: all 0.2s ease;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card span { color: var(--text-muted); font-size: 0.825rem; font-weight: 500; }
.stat-card strong { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1; }

.stat-card::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: var(--brand); border-radius: 4px 0 0 4px;
}

.stat-card.wait::before { background: var(--warn); }
.stat-card.work::before { background: var(--info); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.ok::before { background: var(--ok); }

/* Modern Bar Chart */
.bar-chart {
    display: flex; align-items: flex-end; gap: 12px; height: 140px; padding-top: 20px;
}

.bar-chart .bar {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%;
}

.bar-chart .bar i {
    display: block; width: 100%; max-width: 36px;
    background: var(--brand-gradient);
    border-radius: 8px 8px 0 0; min-height: 6px;
    transition: height 0.4s ease;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.2);
}

.bar-chart .bar span {
    font-size: 0.75rem; color: var(--text-muted); margin-top: 8px; font-weight: 500;
}

/* Lists & Items */
.stack-list { display: flex; flex-direction: column; gap: 10px; }

.stack-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 14px; background: rgba(248, 250, 252, 0.8);
    border-radius: 12px; border: 1px solid var(--border);
    font-size: 0.9rem;
}

.stack-item strong {
    font-weight: 700; color: var(--brand);
    background: rgba(79, 70, 229, 0.08); padding: 2px 10px; border-radius: 99px;
}

/* Case Cards */
.card-list { display: flex; flex-direction: column; gap: 12px; }

.case-card {
    position: relative; text-decoration: none; color: inherit; display: block;
    background: var(--surface); border-radius: var(--radius-md); padding: 16px;
    border: 1px solid var(--border); box-shadow: var(--shadow-sm);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.case-card:hover {
    transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-hover);
    color: inherit;
}

.case-card.unread {
    border-left: 4px solid var(--brand);
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.03) 0%, rgba(255, 255, 255, 1) 100%);
}

.status-badge {
    display: inline-flex; align-items: center; gap: 5px;
    border-radius: 999px; padding: 4px 12px; font-size: 0.78rem; font-weight: 600;
    line-height: 1.2;
}

.tone-secondary { background: #f1f5f9; color: #475569; }
.tone-warning { background: var(--warn-light); color: #b45309; }
.tone-info { background: var(--info-light); color: #1d4ed8; }
.tone-success { background: var(--ok-light); color: #047857; }
.tone-danger { background: var(--danger-light); color: #b91c1c; }

/* Filter Card */
.filter-card {
    background: var(--surface); border-radius: var(--radius-md); padding: 16px;
    border: 1px solid var(--border); box-shadow: var(--shadow-sm);
    display: grid; gap: 10px;
}

/* Wizard Form */
.wizard-progress { display: flex; gap: 8px; margin-bottom: 12px; }
.wizard-progress span {
    flex: 1; height: 6px; background: #e2e8f0; border-radius: 99px;
    transition: background-color 0.3s ease;
}
.wizard-progress span.on { background: var(--brand-gradient); }

.step-label {
    color: var(--brand); font-weight: 600; font-size: 0.875rem; margin-bottom: 16px;
    display: flex; align-items: center; gap: 6px;
}

.choice-row { display: grid; gap: 10px; }
.choice-row label {
    min-height: 52px; display: flex; align-items: center; gap: 12px;
    background: #fff; border-radius: 14px; padding: 0 16px; border: 1.5px solid var(--border);
    cursor: pointer; font-weight: 500; transition: all 0.2s ease;
}
.choice-row label:has(input:checked) {
    border-color: var(--brand); background: rgba(79, 70, 229, 0.04);
    color: var(--brand); font-weight: 600;
}

.input-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }

.emp-card {
    background: rgba(248, 250, 252, 0.9); border: 1.5px dashed var(--brand-light);
    border-radius: 14px; padding: 14px; margin-top: 10px; font-size: 0.875rem;
}

.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.preview-grid figure {
    margin: 0; position: relative; background: #fff; border-radius: 14px; overflow: hidden;
    border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.preview-grid img { width: 100%; height: 130px; object-fit: cover; }
.preview-grid button {
    position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border: 0; border-radius: 50%;
    background: rgba(15, 23, 42, 0.75); color: #fff; font-size: 1.1rem;
    display: grid; place-items: center; backdrop-filter: blur(4px);
}

/* Form Page Layout & Footer Fix */
body[data-active="form"] .bottom-nav {
    display: none !important;
}

body[data-active="form"] .app-main,
body[data-active="form"] #incidentForm {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important;
}

.form-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: none;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.08);
    display: flex;
    gap: 12px;
    padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    max-width: 520px;
    margin: 0 auto;
}

.form-footer .btn {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 14px;
    transition: all 0.2s ease;
}

.form-footer #btnBack {
    flex: 1;
}

.form-footer #btnNext,
.form-footer #btnSubmit {
    flex: 1.8;
}

.field-error { color: var(--danger); font-size: 0.85rem; font-weight: 500; margin-top: 6px; }
.help { color: var(--text-muted); font-size: 0.85rem; }

.success-box {
    text-align: center; background: #fff; border-radius: 24px; padding: 36px 20px;
    border: 1px solid var(--border); box-shadow: var(--shadow-md);
}
.success-box i { font-size: 3.5rem; color: var(--ok); }
.success-box strong { font-size: 1.5rem; display: block; color: var(--text); margin-top: 6px; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0 0 0 8px; border-left: 2px dashed #cbd5e1; }
.timeline li { padding: 0 0 20px 20px; position: relative; }
.timeline li::before {
    content: ""; width: 12px; height: 12px; border-radius: 50%;
    background: var(--brand); position: absolute; left: -7px; top: 4px;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.2);
}

/* Menu Items */
.menu-list { display: flex; flex-direction: column; gap: 10px; }
.menu-item {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    min-height: 56px; display: flex; align-items: center; gap: 14px; padding: 0 18px;
    text-decoration: none; color: var(--text); width: 100%; text-align: left; font-size: 0.95rem;
    font-weight: 500; transition: all 0.2s ease; box-shadow: var(--shadow-sm);
}
.menu-item:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); background: #fff; }
.menu-item i { font-size: 1.3rem; color: var(--brand); }
.menu-item.text-danger i { color: var(--danger); }

.empty-state, .loading-block {
    text-align: center; padding: 36px 16px; color: var(--text-muted);
    background: var(--surface); border-radius: var(--radius-md); border: 1px dashed var(--border);
}

.pager { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 16px; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; background: #f1f5f9; border: 1px solid var(--border); }

/* Login Page */
.login-body {
    min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: radial-gradient(circle at 50% 0%, #312e81 0%, #0f172a 100%);
    position: relative; overflow: hidden;
}

.login-body::before {
    content: ""; position: absolute; width: 300px; height: 300px;
    background: var(--brand); filter: blur(120px); border-radius: 50%;
    top: -50px; left: 50%; transform: translateX(-50%); opacity: 0.6;
}

.login-card {
    width: min(440px, 100%); background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px); border-radius: 28px; padding: 32px 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35); border: 1px solid rgba(255, 255, 255, 0.3);
    position: relative; z-index: 2; animation: fadeInUp 0.4s ease-out;
}

.login-card h1 { font-size: 1.3rem; text-align: center; font-weight: 700; color: var(--text); }
.hint { font-size: 0.8rem; color: var(--text-muted); text-align: center; }

/* Custom Professional Toast System */
.toast-container-custom {
    position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
    z-index: 2000; display: flex; flex-direction: column; gap: 10px;
    width: min(420px, calc(100vw - 32px)); pointer-events: none;
}

.custom-toast {
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(16px);
    color: #fff;
    border-radius: 18px;
    padding: 12px 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    display: flex; align-items: center; gap: 12px;
    animation: toastSlideDown 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.9rem; font-weight: 500;
}

.custom-toast.toast-success { border-left: 4px solid var(--ok); }
.custom-toast.toast-danger { border-left: 4px solid var(--danger); }
.custom-toast.toast-warning { border-left: 4px solid var(--warn); }
.custom-toast.toast-info { border-left: 4px solid var(--info); }

.custom-toast .toast-icon { font-size: 1.3rem; display: flex; }
.custom-toast.toast-success .toast-icon { color: var(--ok); }
.custom-toast.toast-danger .toast-icon { color: var(--danger); }
.custom-toast.toast-warning .toast-icon { color: var(--warn); }
.custom-toast.toast-info .toast-icon { color: var(--info); }

.custom-toast .toast-message { flex: 1; line-height: 1.3; }

/* Custom Modal Dialog Styling */
.modal-backdrop.show {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    background-color: rgba(15, 23, 42, 0.6);
}

.custom-app-modal .modal-content, .modal-content {
    border-radius: 24px !important;
    border: 1px solid var(--border) !important;
    box-shadow: var(--shadow-lg) !important;
    animation: modalScaleIn 0.25s ease-out;
}

.modal-icon-badge {
    width: 38px; height: 38px; border-radius: 12px;
    background: rgba(79, 70, 229, 0.1); color: var(--brand);
    display: grid; place-items: center; font-size: 1.2rem;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .stat-grid { grid-template-columns: repeat(5, 1fr); }
    .filter-card { grid-template-columns: repeat(3, 1fr); }
    .bottom-nav { max-width: 500px; }
    .app-main { padding: 24px; }
}

@media print {
    .bottom-nav, .app-topbar, .form-footer, .filter-card button, .toast-container-custom { display: none !important; }
    body { background: #fff; }
}


/* Grid Column Span Helpers */
.grid-column-span-full { grid-column: 1 / -1; width: 100%; }
.grid-column-span-2 { grid-column: span 2; }
