/* ============================================
   CEPAT — Custom Styles
   Premium design system for the letter app
   ============================================ */

/* --- Base & Typography --- */
:root {
    --cepat-primary: #206bc4;
    --cepat-primary-light: #4299e1;
    --cepat-accent: #0ca678;
    --cepat-gradient: linear-gradient(135deg, #206bc4 0%, #4dabf7 50%, #0ca678 100%);
    --cepat-glass: rgba(255, 255, 255, 0.08);
    --cepat-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --cepat-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.12);
    --cepat-radius: 12px;
    --cepat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* --- Sidebar Branding --- */
.brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    color: #fff !important;
}

.brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--cepat-gradient);
    font-size: 20px;
    color: #fff;
    box-shadow: 0 4px 12px rgba(32, 107, 196, 0.4);
}

.brand-text {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: var(--cepat-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* --- Nav Items --- */
.navbar-vertical .nav-link.active,
.navbar-vertical .nav-item.active > .nav-link {
    background: rgba(32, 107, 196, 0.15) !important;
    border-left: 3px solid var(--cepat-primary-light);
    color: var(--cepat-primary-light) !important;
}

.nav-item-header .nav-link-title {
    font-size: 0.7rem;
    letter-spacing: 1.5px;
    padding-left: 0.75rem;
}

/* --- Stats Cards --- */
.stat-card {
    border: none;
    border-radius: var(--cepat-radius);
    box-shadow: var(--cepat-shadow);
    transition: var(--cepat-transition);
    overflow: hidden;
    position: relative;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--cepat-gradient);
}

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

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    color: #1e293b;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- Premium Cards --- */
.card-premium {
    border: none;
    border-radius: var(--cepat-radius);
    box-shadow: var(--cepat-shadow);
    transition: var(--cepat-transition);
}

.card-premium:hover {
    box-shadow: var(--cepat-shadow-hover);
}

.card-premium .card-header {
    background: transparent;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding: 1rem 1.25rem;
}

/* --- Form Wizard/Stepper --- */
.wizard-steps {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-bottom: 2rem;
    padding: 0;
    list-style: none;
    position: relative;
}

.wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    flex: 1;
    max-width: 200px;
}

.wizard-step::before {
    content: '';
    position: absolute;
    top: 20px;
    left: -50%;
    right: 50%;
    height: 3px;
    background: #e2e8f0;
    z-index: 0;
}

.wizard-step:first-child::before {
    display: none;
}

.wizard-step.active::before,
.wizard-step.completed::before {
    background: var(--cepat-primary);
}

.wizard-step .step-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    position: relative;
    z-index: 1;
    transition: var(--cepat-transition);
}

.wizard-step.active .step-circle {
    background: var(--cepat-primary);
    color: #fff;
    box-shadow: 0 4px 16px rgba(32, 107, 196, 0.4);
    transform: scale(1.1);
}

.wizard-step.completed .step-circle {
    background: var(--cepat-accent);
    color: #fff;
}

.wizard-step .step-label {
    margin-top: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #94a3b8;
    text-align: center;
}

.wizard-step.active .step-label {
    color: var(--cepat-primary);
}

.wizard-step.completed .step-label {
    color: var(--cepat-accent);
}

/* --- Wizard Content Panels --- */
.wizard-panel {
    display: none;
    animation: fadeSlideIn 0.4s ease;
}

.wizard-panel.active {
    display: block;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Table Premium --- */
.table-premium {
    border-radius: var(--cepat-radius);
    overflow: hidden;
}

.table-premium thead th {
    background: #f8fafc;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    color: #64748b;
    border-bottom: 2px solid #e2e8f0;
    padding: 0.875rem 1rem;
}

.table-premium tbody tr {
    transition: var(--cepat-transition);
}

.table-premium tbody tr:hover {
    background: rgba(32, 107, 196, 0.03);
}

.table-premium tbody td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
}

/* --- Action Buttons --- */
.btn-action {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: var(--cepat-transition);
    font-size: 1rem;
}

.btn-action:hover {
    transform: scale(1.1);
}

/* --- Empty State --- */
.empty-state {
    padding: 4rem 2rem;
    text-align: center;
}

.empty-state .empty-icon {
    font-size: 4rem;
    color: #cbd5e1;
    margin-bottom: 1rem;
}

.empty-state .empty-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #334155;
    margin-bottom: 0.5rem;
}

.empty-state .empty-subtitle {
    color: #94a3b8;
    margin-bottom: 1.5rem;
}

/* --- Surat Preview (A4 Paper) --- */
.paper-preview {
    background: #fff;
    max-width: 210mm;
    margin: 0 auto;
    padding: var(--paper-margin, 10mm);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    font-family: 'Times New Roman', serif;
    font-size: 12pt;
    line-height: 1.8;
    color: #000;
    position: relative;
    transition: padding 0.3s ease;
}

.paper-preview p {
    margin-top: 0;
    margin-bottom: 12pt;
    padding: 0;
    min-height: 1.2em;
}

.paper-preview .surat-title {
    text-align: center;
    font-weight: bold;
    font-size: 14pt;
    text-decoration: underline;
    margin-bottom: 24pt;
    letter-spacing: 1px;
}

.paper-preview .data-table td {
    padding: 2pt 8pt;
    vertical-align: top;
    border: none;
}

.paper-preview .data-table td:first-child {
    width: 180px;
    white-space: nowrap;
}

.paper-preview .data-table td:nth-child(2) {
    width: 15px;
    text-align: center;
}

.paper-preview .ttd-area {
    margin-top: 48pt;
    text-align: right;
    padding-right: 40px;
}

.paper-preview .ttd-area .ttd-space {
    height: 80px;
}

/* --- Animations --- */
.animate-fade-in {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-count {
    animation: countPulse 0.6s ease;
}

@keyframes countPulse {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Quick Action Card --- */
.quick-action {
    background: var(--cepat-gradient);
    border-radius: var(--cepat-radius);
    padding: 2rem;
    color: #fff;
    position: relative;
    overflow: hidden;
    transition: var(--cepat-transition);
}

.quick-action:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(32, 107, 196, 0.3);
}

.quick-action::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    pointer-events: none;
}

/* --- Badge Premium --- */
.badge-nomor {
    font-family: 'Inter', monospace;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
}

/* --- Search Bar --- */
.search-premium {
    position: relative;
}

.search-premium .form-control {
    border-radius: 10px;
    padding-left: 2.5rem;
    border: 2px solid #e2e8f0;
    transition: var(--cepat-transition);
}

.search-premium .form-control:focus {
    border-color: var(--cepat-primary);
    box-shadow: 0 0 0 4px rgba(32, 107, 196, 0.1);
}

.search-premium .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

/* ==============================================
   MOBILE-FIRST RESPONSIVE ENHANCEMENTS
   ============================================== */

/* --- Utility Classes --- */
.mobile-full { /* applied via CSS below */ }
.mobile-stack { /* applied via CSS below */ }

/* --- Bottom Sticky Action Bar --- */
.mobile-action-bar {
    display: none;
}

/* --- Skeleton Loading --- */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
    border-radius: 8px;
}

@keyframes skeletonShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* --- Mobile Card Row (Table Alternative) --- */
.mobile-card-list {
    display: none;
}

/* ===================== MOBILE < 768px ===================== */
@media (max-width: 767.98px) {

    /* --- Global Mobile Resets --- */
    .container-xl,
    .container-fluid {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    .page-header {
        padding-top: 0.75rem;
        padding-bottom: 0.5rem;
    }

    .page-title {
        font-size: 1.25rem !important;
    }

    .page-pretitle {
        font-size: 0.7rem;
    }

    /* --- Stat Cards --- */
    .stat-card .stat-value {
        font-size: 1.4rem;
    }

    .stat-card .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .stat-card .card-body {
        padding: 0.875rem;
    }

    /* --- Card Premium Compact --- */
    .card-premium .card-header {
        padding: 0.625rem 0.875rem;
    }

    .card-premium .card-body {
        padding: 0.875rem;
    }

    /* --- Paper Preview (Surat) --- */
    .paper-preview {
        padding: 8px !important;
        margin-left: -8px;
        margin-right: -8px;
        border-radius: 0;
        box-shadow: none;
    }

    .paper-preview iframe,
    #suratFrame {
        height: 80vh !important;
        border-radius: 0 !important;
    }

    /* --- Form Controls (Touch-friendly) --- */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }

    .form-label {
        font-size: 0.85rem;
        font-weight: 600;
        margin-bottom: 0.375rem;
    }

    /* --- Buttons (Touch-friendly) --- */
    .btn {
        min-height: 42px;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .btn-lg {
        min-height: 48px;
        font-size: 1rem;
    }

    .btn-sm {
        min-height: 36px;
    }

    /* --- Mobile Full-Width Buttons --- */
    .mobile-full .btn,
    .d-flex.gap-2 .btn {
        flex: 1;
    }

    /* --- Wizard Steps (Horizontal Scroll) --- */
    .wizard-steps {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        padding-bottom: 8px;
    }

    .wizard-steps::-webkit-scrollbar {
        display: none;
    }

    .wizard-step {
        min-width: 64px;
        flex-shrink: 0;
    }

    .wizard-step .step-circle {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    .wizard-step .step-label {
        font-size: 0.6rem;
        max-width: 64px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* --- Wizard Navigation Footer (Sticky) --- */
    .wizard-panel .card-footer {
        position: sticky;
        bottom: 0;
        background: #fff;
        z-index: 10;
        padding: 0.75rem;
        border-top: 1px solid #e2e8f0;
        gap: 0.5rem;
    }

    .wizard-panel .card-footer .btn {
        flex: 1;
        min-height: 46px;
        font-weight: 600;
    }

    /* --- Dynamic Show: Sticky Action Bar --- */
    .mobile-action-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        z-index: 1050;
        gap: 8px;
        align-items: center;
    }

    .mobile-action-bar .btn {
        flex: 1;
        border-radius: 10px !important;
        font-weight: 600;
        min-height: 44px;
    }

    .mobile-action-bar .btn-primary {
        flex: 2; /* Download button takes more space */
    }

    /* Add bottom padding to body so content isn't hidden behind sticky bar */
    .has-mobile-action-bar {
        padding-bottom: 80px !important;
    }

    /* --- Hide Desktop-Only Elements --- */
    .d-flex.flex-wrap.justify-content-between .btn-outline-warning,
    .show-desktop-actions {
        /* Keep visible but let mobile-action-bar handle primary actions */
    }

    /* --- Hero Section Mobile --- */
    .hero-section {
        padding: 2rem 0 2.5rem !important;
    }

    .hero-title {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
    }

    .hero-subtitle {
        font-size: 0.9rem !important;
    }

    .hero-badge {
        font-size: 0.7rem;
        padding: 4px 10px;
    }

    .hero-section .input-group {
        box-shadow: 0 4px 12px rgba(0,0,0,0.08) !important;
    }

    .hero-section .input-group .form-control {
        height: 46px !important;
    }

    /* --- Template Cards (Full Width) --- */
    .template-card .card-body {
        padding: 1.125rem;
    }

    .template-card .card-icon {
        width: 44px;
        height: 44px;
        border-radius: 12px;
        font-size: 22px;
        margin-bottom: 0.75rem;
    }

    .template-card .card-title {
        font-size: 0.95rem;
    }

    .template-card .card-text {
        font-size: 0.8rem;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .template-card .btn {
        width: 100%;
    }

    /* --- Search Results Mobile --- */
    .card-stacked .card-body {
        padding: 1rem;
    }

    /* --- Table → Mobile Card View --- */
    .mobile-card-list {
        display: block;
    }

    .desktop-table {
        display: none !important;
    }

    .mobile-card-item {
        background: #fff;
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 0.75rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.04);
        border: 1px solid #f1f5f9;
    }

    .mobile-card-item .card-item-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 0.625rem;
    }

    .mobile-card-item .card-item-body {
        font-size: 0.85rem;
        color: #64748b;
    }

    .mobile-card-item .card-item-body .label {
        font-weight: 600;
        color: #334155;
        display: inline-block;
        min-width: 80px;
    }

    .mobile-card-item .card-item-footer {
        display: flex;
        gap: 0.5rem;
        margin-top: 0.75rem;
        padding-top: 0.625rem;
        border-top: 1px solid #f1f5f9;
    }

    .mobile-card-item .card-item-footer .btn {
        flex: 1;
        min-height: 38px;
    }

    /* --- Empty State Compact --- */
    .empty-state {
        padding: 2.5rem 1.5rem;
    }

    .empty-state .empty-icon {
        font-size: 3rem;
    }

    .empty-state .empty-title {
        font-size: 1.1rem;
    }

    /* --- Quick Action Mobile --- */
    .quick-action {
        padding: 1.25rem;
    }

    .quick-action .row {
        flex-direction: column;
        gap: 1rem;
    }

    .quick-action .col-auto {
        width: 100%;
    }

    .quick-action .btn {
        width: 100%;
    }

    /* --- Riwayat / Admin Search Mobile --- */
    .search-premium .form-control {
        min-height: 44px;
    }

    /* --- Admin Template Form: Field Builder Mobile --- */
    .col-md-3, .col-md-2, .col-md-1 {
        /* Bootstrap already handles this — these become col-12 on mobile */
    }

    /* Ace Editor Mobile */
    #ace-editor {
        height: 300px !important;
    }

    /* --- Footer Compact --- */
    .public-footer {
        padding: 1.25rem 0 !important;
        margin-top: 2rem !important;
        font-size: 0.75rem !important;
    }

    footer.footer {
        padding: 0.75rem 0;
    }

    /* --- Alerts Compact --- */
    .alert {
        padding: 0.625rem 0.875rem;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    /* --- Badge --- */
    .badge-nomor {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    /* --- Card Footer Actions --- */
    .card-footer .d-flex {
        flex-wrap: wrap;
    }

    /* --- Safe Area for Modern Phones --- */
    body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* ===================== TABLET 768-991px ===================== */
@media (min-width: 768px) and (max-width: 991.98px) {
    .hero-title {
        font-size: 1.8rem !important;
    }

    .paper-preview {
        padding: 16px !important;
    }

    .stat-card .stat-value {
        font-size: 1.5rem;
    }

    .template-card .btn {
        width: 100%;
    }

    /* Keep desktop table visible on tablet */
    .mobile-card-list {
        display: none;
    }
}

/* ===================== KEEP DESKTOP INTACT ===================== */
@media (min-width: 992px) {
    :root {
        margin-left: 0 !important;
    }

    .mobile-action-bar {
        display: none !important;
    }

    .mobile-card-list {
        display: none !important;
    }

    .desktop-table {
        display: block !important;
    }
}



/* --- Base styles --- */
@media print {
    /* Hide ALL UI elements */
    .public-navbar,
    .public-footer,
    .navbar,
    .navbar-vertical,
    .page-header,
    .footer,
    .btn,
    .alert,
    .badge-nomor,
    .no-print,
    .mobile-action-bar,
    nav,
    footer,
    .d-flex.flex-wrap.justify-content-between,
    .mb-4 > .badge,
    .mb-4 > .text-muted {
        display: none !important;
    }

    /* Hide the info bar (nomor surat & tanggal) */
    .container-xl > .mb-4.no-print {
        display: none !important;
    }

    /* Reset page */
    html, body {
        background: #fff !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Reset admin sidebar layout — make page-wrapper full width */
    .page {
        display: block !important;
    }

    .page-wrapper {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .page-body {
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Remove container padding */
    .container-xl,
    .container-xl.py-4 {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Paper becomes the page — margin diserahkan ke browser */
    .paper-preview {
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        font-family: 'Times New Roman', serif !important;
        font-size: 12pt !important;
        line-height: 1.8 !important;
        color: #000 !important;
    }

    /* Table styling for print */
    .paper-preview .data-table td {
        padding: 1pt 4pt !important;
        border: none !important;
    }

    /* Prevent page breaks inside elements */
    .paper-preview table,
    .paper-preview ol,
    .paper-preview ul,
    .paper-preview .ttd-area {
        page-break-inside: avoid;
    }

    .paper-preview .ttd-area {
        page-break-before: avoid;
    }

    /* Links should not show URL */
    a[href]::after {
        content: none !important;
    }
}
