/* =========================================================
   RESET & BASE — Mobile First
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: #f8f9fa;
    color: #212529;
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
button { font-family: inherit; }
a { color: #1e3a5f; }

/* =========================================================
   LOGIN
   ========================================================= */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(180deg, #1e3a5f 0%, #152a45 100%);
}
.login-box {
    background: #fff;
    width: 100%;
    max-width: 400px;
    padding: 28px 22px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .logo {
    width: 56px; height: 56px; margin: 0 auto 12px;
    background: #1e3a5f; color: #fff; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px; letter-spacing: 1px;
}
.login-box h1 { font-size: 18px; color: #1e3a5f; margin-bottom: 4px; }
.login-box .subtitle { color: #6c757d; font-size: 13px; }

/* =========================================================
   FORM
   ========================================================= */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block; margin-bottom: 6px;
    font-weight: 500; font-size: 13.5px; color: #343a40;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    background: #fff;
    -webkit-appearance: none;
    appearance: none;
}
.form-group select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23343a40' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 34px;
}
.form-group textarea { min-height: 90px; resize: vertical; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #1e3a5f;
    box-shadow: 0 0 0 3px rgba(30,58,95,.12);
}

/* =========================================================
   TOMBOL — ukuran nyaman disentuh
   ========================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 42px;
    padding: 10px 16px;
    font-size: 14.5px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.3;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: #1e3a5f; color: #fff; }
.btn-primary:hover { background: #152a45; }
.btn-secondary { background: #fff; color: #343a40; border-color: #ced4da; }
.btn-secondary:hover { background: #f1f3f5; }
.btn-danger { background: #c0392b; color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-success { background: #1e7e34; color: #fff; }
.btn-success:hover { background: #155724; }
.btn-sm { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* =========================================================
   LAYOUT APP
   ========================================================= */
.app { min-height: 100vh; }

/* Topbar (mobile) */
.topbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 12px;
    background: #1e3a5f; color: #fff;
    padding: 12px 14px;
    box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.topbar .hamburger {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: 0; color: #fff;
    cursor: pointer; border-radius: 6px;
}
.topbar .hamburger:hover { background: rgba(255,255,255,.1); }
.topbar .hamburger span {
    display: block; width: 22px; height: 2px; background: #fff;
    position: relative;
}
.topbar .hamburger span::before,
.topbar .hamburger span::after {
    content: ""; position: absolute; left: 0; width: 22px; height: 2px;
    background: #fff;
}
.topbar .hamburger span::before { top: -7px; }
.topbar .hamburger span::after { top: 7px; }
.topbar .title { font-size: 15px; font-weight: 600; flex: 1; }
.topbar .title small { display: block; font-size: 11px; font-weight: 400; opacity: .75; }

/* Overlay saat drawer terbuka */
.overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 90; opacity: 0; visibility: hidden;
    transition: opacity .2s, visibility .2s;
}
.overlay.show { opacity: 1; visibility: visible; }

/* Sidebar / Drawer */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 260px; max-width: 82vw;
    background: #1e3a5f; color: #fff;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar .brand {
    padding: 18px 18px 14px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar .brand .name { font-size: 16px; font-weight: 600; }
.sidebar .brand small { display: block; font-size: 11.5px; opacity: .7; margin-top: 2px; }
.sidebar nav { flex: 1; padding: 10px 0; }
.sidebar nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 18px;
    color: #cfd8e3; text-decoration: none; font-size: 14.5px;
    border-left: 3px solid transparent;
}
.sidebar nav a:hover,
.sidebar nav a.active {
    background: rgba(255,255,255,.08);
    color: #fff;
    border-left-color: #ffc107;
}
.sidebar nav a .ico {
    width: 18px; text-align: center; opacity: .9; font-size: 15px;
}
.sidebar .user-info {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,.12);
    background: rgba(0,0,0,.15);
}
.sidebar .user-info .nama { font-weight: 600; font-size: 13.5px; }
.sidebar .user-info .role { color: #9fb3c8; font-size: 12px; margin-top: 2px; }
.sidebar .user-info a {
    display: inline-block; margin-top: 8px;
    color: #ffc107; font-size: 13px; text-decoration: none;
}

/* Main content */
.main {
    padding: 16px 14px 40px;
    max-width: 1400px;
    margin: 0 auto;
}

/* =========================================================
   HALAMAN HEADER
   ========================================================= */
.page-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #dee2e6;
}
.page-header h2 { font-size: 18px; color: #1e3a5f; }
.page-header .breadcrumb { font-size: 12.5px; color: #6c757d; margin-top: 2px; }

/* =========================================================
   STAT CARDS
   ========================================================= */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
}
.stat-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 14px;
}
.stat-card .label {
    font-size: 12px; color: #6c757d; margin-bottom: 4px;
    display: flex; align-items: center; gap: 6px;
}
.stat-card .value {
    font-size: 20px; font-weight: 700; color: #1e3a5f; line-height: 1.2;
}
.stat-card .value.merah { color: #c0392b; }
.stat-card .value.hijau { color: #1e7e34; }
.stat-card .value.kuning { color: #b8860b; }

/* =========================================================
   TABEL — Mobile: jadi kartu bertumpuk
   ========================================================= */
.table-wrap {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }

/* Mode mobile: sembunyikan thead, tampilkan tiap baris sebagai kartu */
@media (max-width: 767px) {
    table.data thead { display: none; }
    table.data,
    table.data tbody,
    table.data tr,
    table.data td { display: block; width: 100%; }
    table.data tr {
        border-bottom: 1px solid #e9ecef;
        padding: 12px 14px;
    }
    table.data tr:last-child { border-bottom: none; }
    table.data td {
        padding: 4px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        text-align: right;
    }
    table.data td::before {
        content: attr(data-label);
        font-weight: 500;
        color: #6c757d;
        text-align: left;
        flex-shrink: 0;
        font-size: 12.5px;
    }
    table.data td.td-aksi {
        padding-top: 8px;
        justify-content: flex-end;
    }
    table.data td.td-aksi::before { content: none; }
    table.data td.td-check {
        justify-content: flex-start;
    }
    table.data td.td-check::before { content: none; }
}

/* Mode tablet & desktop: tabel normal */
@media (min-width: 768px) {
    table.data thead { display: table-header-group; }
    table.data tr { display: table-row; border-bottom: 1px solid #dee2e6; }
    table.data tr:hover td { background: #f1f3f5; }
    table.data th {
        background: #343a40; color: #fff; text-align: left;
        padding: 11px 12px; font-weight: 500; font-size: 13px;
        white-space: nowrap;
    }
    table.data td {
        padding: 10px 12px; vertical-align: middle;
    }
    table.data td[data-label]::before { content: none; }
}

/* =========================================================
   BADGE STATUS
   ========================================================= */
.badge {
    display: inline-block; padding: 3px 9px;
    font-size: 11.5px; border-radius: 20px;
    font-weight: 600; white-space: nowrap;
    letter-spacing: .2px;
}
.badge.belum { background: #f8d7da; color: #721c24; }
.badge.lunas { background: #d4edda; color: #155724; }
.badge.pending { background: #fff3cd; color: #856404; }
.badge.diterima { background: #d1ecf1; color: #0c5460; }
.badge.ditolak { background: #f8d7da; color: #721c24; }
.badge.role-admin { background: #1e3a5f; color: #fff; }
.badge.role-petugas { background: #6c757d; color: #fff; }

/* =========================================================
   ALERT
   ========================================================= */
.alert-error, .alert-success, .alert-info {
    padding: 12px 14px; border-radius: 6px;
    margin-bottom: 14px; font-size: 13.5px;
    border-left: 4px solid;
}
.alert-error { background: #f8d7da; color: #721c24; border-color: #c0392b; }
.alert-success { background: #d4edda; color: #155724; border-color: #1e7e34; }
.alert-info { background: #d1ecf1; color: #0c5460; border-color: #17a2b8; }

/* =========================================================
   FILTER BAR
   ========================================================= */
.filter-bar {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-bar .actions .btn { flex: 1 1 auto; }

/* =========================================================
   CHAT
   ========================================================= */
.chat-box {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    min-height: 380px;
    max-height: 620px;
    overflow: hidden;
}
.chat-messages {
    flex: 1; overflow-y: auto; padding: 14px;
    background: #f8f9fa;
    -webkit-overflow-scrolling: touch;
}
.chat-item { margin-bottom: 12px; display: flex; flex-direction: column; }
.chat-item.mine { align-items: flex-end; }
.chat-item .meta {
    font-size: 11.5px; color: #6c757d; margin-bottom: 3px;
    display: flex; align-items: center; gap: 6px;
}
.chat-item .meta .nama { font-weight: 600; color: #1e3a5f; }
.chat-item .bubble {
    background: #fff; border: 1px solid #dee2e6;
    padding: 9px 12px; border-radius: 10px;
    max-width: 85%; word-wrap: break-word;
    font-size: 14px;
}
.chat-item.mine .bubble {
    background: #1e3a5f; color: #fff; border-color: #1e3a5f;
}
.chat-form {
    display: flex; gap: 8px; padding: 10px;
    border-top: 1px solid #dee2e6; background: #fff;
}
.chat-form input {
    flex: 1; padding: 11px 12px;
    border: 1px solid #ced4da; border-radius: 6px;
    font-size: 16px; font-family: inherit;
}
.chat-form input:focus { outline: none; border-color: #1e3a5f; }

/* =========================================================
   MODAL
   ========================================================= */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.55);
    z-index: 200; display: none;
    align-items: flex-end; justify-content: center;
    padding: 0;
}
.modal-backdrop.show { display: flex; }
.modal {
    background: #fff; width: 100%;
    max-height: 92vh; overflow-y: auto;
    border-radius: 14px 14px 0 0;
    padding: 20px 18px 24px;
    animation: slideUp .25s ease;
}
@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal h3 { font-size: 16px; color: #1e3a5f; margin-bottom: 14px; }
.modal-actions {
    display: flex; gap: 8px; margin-top: 16px;
}
.modal-actions .btn { flex: 1; }
.modal .form-group input[readonly] {
    background: #f1f3f5; color: #495057; cursor: not-allowed;
}

/* =========================================================
   UTIL
   ========================================================= */
.text-muted { color: #6c757d; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mt-3 { margin-top: 16px; }
.empty-state {
    padding: 36px 16px; text-align: center;
    color: #6c757d; font-size: 13.5px;
}
.empty-state .ico {
    font-size: 34px; opacity: .35; margin-bottom: 8px;
    display: block;
}

/* Aksi atas halaman */
.row-actions {
    display: flex; gap: 8px; flex-wrap: wrap;
}
.row-actions .btn { flex: 1 1 auto; }

/* =========================================================
   TABLET (>= 768px)
   ========================================================= */
@media (min-width: 768px) {
    body { font-size: 14px; }

    .main { padding: 22px 24px 40px; }
    .page-header h2 { font-size: 20px; }

    .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
    .stat-card .value { font-size: 22px; }

    .filter-bar {
        flex-direction: row; align-items: flex-end;
        flex-wrap: wrap; gap: 10px; padding: 14px;
    }
    .filter-bar .form-group { flex: 1 1 160px; }
    .filter-bar .actions { flex: 0 0 auto; }
    .filter-bar .actions .btn { flex: 0 0 auto; }

    .row-actions .btn { flex: 0 0 auto; }

    .modal-backdrop { align-items: center; padding: 20px; }
    .modal { max-width: 520px; border-radius: 10px; padding: 24px; }

    .chat-item .bubble { max-width: 70%; }
}

/* =========================================================
   DESKTOP (>= 1024px)
   ========================================================= */
@media (min-width: 1024px) {
    .topbar { display: none; }

    .sidebar {
        transform: none;
        width: 240px;
        box-shadow: none;
    }
    .overlay { display: none !important; }

    .main {
        margin-left: 240px;
        padding: 26px 32px 56px;
        max-width: 1280px;
    }

    .stat-grid { gap: 16px; }
    .stat-card { padding: 18px; }
    .stat-card .value { font-size: 24px; }

    .page-header { margin-bottom: 20px; padding-bottom: 14px; }
    .page-header h2 { font-size: 22px; }
    .page-header .breadcrumb { font-size: 13px; }

    table.data { font-size: 14px; }
    table.data th { padding: 12px 14px; font-size: 13.5px; }
    table.data td { padding: 12px 14px; }

    .filter-bar { padding: 16px; gap: 12px; }
    .filter-bar .form-group { flex: 1 1 180px; }

    .chat-box { height: calc(100vh - 180px); }
}

/* =========================================================
   DESKTOP LEBAR (>= 1280px)
   ========================================================= */
@media (min-width: 1280px) {
    .sidebar { width: 260px; }
    .main {
        margin-left: 260px;
        padding: 30px 40px 60px;
        max-width: 1400px;
    }

    .stat-card { padding: 20px; }
    .stat-card .value { font-size: 26px; }
}

/* =========================================================
   DESKTOP SANGAT LEBAR (>= 1600px)
   ========================================================= */
@media (min-width: 1600px) {
    .main {
        max-width: 1560px;
        padding: 34px 48px 70px;
    }
    table.data { font-size: 14.5px; }
    table.data th { padding: 13px 16px; }
    table.data td { padding: 13px 16px; }
}

@media print {
    .sidebar, .topbar, .filter-bar, .row-actions, .bulk-bar { display: none !important; }
    .main { margin: 0 !important; padding: 0 !important; }
    .table-wrap { border: none; }
    table.data th { background: #e0e0e0 !important; color: #000 !important; }
    .badge { border: 1px solid #333; }
}
