/* CSS Variables for Theming */
:root {
    --primary: #4338ca;
    --primary-light: #6366f1;
    --primary-dark: #3730a3;
    
    --bg-main: #f3f4f6;
    --bg-surface: #ffffff;
    --sidebar-bg: #1e1b4b;
    
    --text-main: #111827;
    --text-muted: #6b7280;
    --text-light: #f9fafb;
    
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    --radius: 16px;
    --transition: 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow-x: hidden;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.05);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px 32px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 24px;
}

.logo-icon {
    background: linear-gradient(135deg, #818cf8, #4f46e5);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.4);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 16px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    transition: var(--transition);
}

.nav-item i {
    width: 20px;
    font-size: 1.1rem;
}

.nav-item:hover {
    background-color: rgba(255,255,255,0.05);
    color: #fff;
    transform: translateX(4px);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(99,102,241,0.2) 0%, transparent 100%);
    color: #818cf8;
    border-left: 4px solid #818cf8;
}

.sidebar-footer {
    padding: 20px 24px;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.5);
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logout-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 6px;
    font-size: 1.1rem;
    transition: 0.2s;
}

.logout-btn:hover {
    color: #f87171;
    transform: scale(1.1);
}

.status.online {
    color: #10b981;
    font-weight: 600;
}

/* Main Content */
.content {
    flex: 1;
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.header-title h2 {
    font-size: 2rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.5px;
}

.header-title .subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    margin-top: 4px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    padding: 8px 16px 8px 8px;
    border-radius: 30px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.02);
    font-weight: 600;
    font-size: 0.95rem;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

/* Glass Panels */
.glass-panel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 10px 40px rgba(0,0,0,0.03);
    border-radius: var(--radius);
    padding: 24px;
}

/* KPI */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px 24px;
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 4px 15px rgba(0,0,0,0.02);
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
}

.kpi-icon {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.kpi-icon.blue { background: #e0e7ff; color: #4f46e5; }
.kpi-icon.green { background: #d1fae5; color: #059669; }

.kpi-info h3 {
    font-size: 2rem;
    font-weight: 800;
    color: #111827;
}

.kpi-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Table */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.card-header h3 {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
}

.search-box input {
    padding: 10px 16px 10px 40px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
    width: 250px;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.table-responsive {
    overflow-x: auto;
}

.styled-table {
    width: 100%;
    border-collapse: collapse;
}

.styled-table thead tr {
    background-color: #f9fafb;
    border-bottom: 2px solid #e5e7eb;
}

.styled-table th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    color: #4b5563;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.styled-table td {
    padding: 16px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    font-weight: 500;
}

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

.styled-table tbody tr:hover {
    background-color: #f9fafb;
}

.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

.status-safe { background: #d1fae5; color: #065f46; }
.status-low { background: #fef3c7; color: #92400e; }
.status-empty { background: #fee2e2; color: #991b1b; }

/* Forms */
.form-card {
    max-width: 700px;
    margin: 0 auto;
}

.form-desc {
    color: var(--text-muted);
    margin: 8px 0 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group.row {
    display: flex;
    gap: 20px;
}

.row .col { flex: 2; }
.row .col-small { flex: 1; }

label {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: #374151;
}

input[type="text"], input[type="number"], select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    font-size: 1rem;
    transition: var(--transition);
    background: #f9fafb;
}

select {
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg fill='none' stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M6 9l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px;
    padding-right: 40px;
}

input[type="text"]:focus, input[type="number"]:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(99,102,241,0.1);
}

/* Custom JS Autocomplete Dropdown */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    z-index: 1000;
    max-height: 250px;
    overflow-y: auto;
    display: none;
    margin-top: 8px;
}

.autocomplete-dropdown.show {
    display: block;
    animation: fadeIn 0.2s ease;
}

.autocomplete-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: 0.2s;
    font-size: 0.95rem;
    color: #1f2937;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #eef2ff;
    color: #4338ca;
}

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

.radio-group {
    display: flex;
    gap: 16px;
}

.radio-btn {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.radio-btn input {
    position: absolute;
    opacity: 0;
}

.radio-btn span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-weight: 600;
    color: #6b7280;
    transition: var(--transition);
}

.radio-btn input:checked + span {
    border-color: var(--primary);
    background: #eef2ff;
    color: var(--primary-dark);
}

.radio-btn.in-btn input:checked + span {
    border-color: #10b981;
    background: #ecfdf5;
    color: #065f46;
}

.radio-btn.out-btn input:checked + span {
    border-color: #ef4444;
    background: #fef2f2;
    color: #991b1b;
}

.form-actions {
    margin-top: 32px;
    display: flex;
    justify-content: flex-end;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 28px;
    font-size: 1.05rem;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

/* Timeline / History */
.history-card {
    max-width: 800px;
    margin: 0 auto;
}

.timeline {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.timeline-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    background: #fff;
    border: 1px solid #f3f4f6;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.015);
    transition: var(--transition);
}

.timeline-item:hover {
    border-color: #e5e7eb;
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
}

.timeline-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.timeline-icon.in { background: #d1fae5; color: #059669; }
.timeline-icon.out { background: #fee2e2; color: #dc2626; }

.timeline-content {
    flex: 1;
}

.timeline-content h4 {
    font-size: 1.1rem;
    margin-bottom: 4px;
    color: #111827;
}

.timeline-content h4 span {
    font-weight: 800;
}
.text-in { color: #059669; }
.text-out { color: #dc2626; }

.timeline-content p {
    color: #6b7280;
    font-size: 0.9rem;
}

.timeline-meta {
    text-align: right;
    color: #9ca3af;
    font-size: 0.85rem;
    font-weight: 500;
}

/* Utils */
.hidden { display: none !important; }

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #111827;
    color: white;
    padding: 16px 24px;
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success { background: #10b981; }
.toast.error { background: #ef4444; }

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
}
@media print {
    body * { visibility: hidden; }
    #qr-modal, #qr-modal * { visibility: visible; }
    #qr-modal { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: white; }
    .modal-content { box-shadow: none; border: none; }
    button { display: none !important; }
}

/* Responsiveness / Mobile View HP */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        padding: 16px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    }
    
    .sidebar nav {
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 8px;
    }
    
    .nav-item {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
    
    .content {
        padding: 24px 16px;
    }
    
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    
    .header-title h2 {
        font-size: 1.5rem;
    }
    
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    
    .form-group.row {
        flex-direction: column;
        gap: 16px;
    }
    
    .styled-table th, .styled-table td {
        padding: 12px 10px;
        font-size: 0.85rem;
    }
    
    .search-box input {
        width: 100%;
    }
    
    .timeline-item {
        flex-direction: column;
        gap: 8px;
    }
    
    .timeline-meta {
        text-align: left;
    }
}

/* ============================================================
   POPUP ALERT MODAL
   ============================================================ */
.alert-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 30, 0.55);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.alert-modal-box {
    background: #fff;
    border-radius: 24px;
    padding: 40px 36px 32px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: 0 25px 60px rgba(0,0,0,0.18);
    position: relative;
    border-top: 5px solid #e5e7eb;
}

/* Animasi masuk */
@keyframes popupEnter {
    0%   { transform: scale(0.7) translateY(30px); opacity: 0; }
    70%  { transform: scale(1.04) translateY(-4px); opacity: 1; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes popupExit {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.8) translateY(20px); opacity: 0; }
}
.alert-modal-box.popup-enter { animation: popupEnter 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.alert-modal-box.popup-exit  { animation: popupExit 0.28s ease-in forwards; }

/* Icon besar di atas */
.alert-modal-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    line-height: 1;
}

/* Tema warna */
.alert-modal-box.popup-success { border-top-color: #10b981; }
.alert-modal-box.popup-success .alert-modal-icon { color: #10b981; }
.alert-modal-box.popup-success .alert-modal-btn  { background: #10b981; box-shadow: 0 4px 14px rgba(16,185,129,0.35); }
.alert-modal-box.popup-success .alert-modal-btn:hover { background: #059669; }

.alert-modal-box.popup-error { border-top-color: #ef4444; }
.alert-modal-box.popup-error .alert-modal-icon { color: #ef4444; }
.alert-modal-box.popup-error .alert-modal-btn  { background: #ef4444; box-shadow: 0 4px 14px rgba(239,68,68,0.35); }
.alert-modal-box.popup-error .alert-modal-btn:hover { background: #dc2626; }

.alert-modal-box.popup-warning { border-top-color: #f59e0b; }
.alert-modal-box.popup-warning .alert-modal-icon { color: #f59e0b; }
.alert-modal-box.popup-warning .alert-modal-btn  { background: #f59e0b; box-shadow: 0 4px 14px rgba(245,158,11,0.35); }
.alert-modal-box.popup-warning .alert-modal-btn:hover { background: #d97706; }

.alert-modal-title {
    font-size: 1.45rem;
    font-weight: 800;
    color: #111827;
    margin-bottom: 10px;
}

.alert-modal-message {
    color: #4b5563;
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 28px;
}

.alert-modal-btn {
    color: #fff;
    border: none;
    padding: 14px 40px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.3px;
    width: 100%;
    max-width: 220px;
}

/* ===========================================
   RESPONSIVE / MOBILE STYLES
   =========================================== */

/* Tablet */
@media (max-width: 1024px) {
    .sidebar {
        width: 220px;
    }
    .content {
        padding: 24px;
    }
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile: Sidebar jadi Bottom Nav */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    /* Sidebar jadi bottom navigation */
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
        flex-shrink: 0;
    }

    /* Sembunyikan logo dan footer di mobile */
    .sidebar .logo,
    .sidebar-footer {
        display: none !important;
    }

    /* Nav bar horizontal */
    .sidebar nav {
        flex-direction: row;
        justify-content: space-around;
        padding: 0;
        width: 100%;
        gap: 0;
    }

    .nav-item {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 10px 6px 14px;
        font-size: 0.62rem;
        border-radius: 0;
        border-left: none !important;
        border-top: 3px solid transparent;
        flex: 1;
        text-align: center;
        transform: none !important;
    }

    .nav-item i {
        width: auto;
        font-size: 1.2rem;
    }

    .nav-item.active {
        background: rgba(99,102,241,0.15);
        color: #818cf8;
        border-left: none;
        border-top: 3px solid #818cf8;
    }

    /* Content area */
    .content {
        padding: 16px 16px 90px; /* padding bawah untuk bottom nav */
        gap: 16px;
    }

    /* Header */
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .header-title h2 {
        font-size: 1.4rem;
    }

    .user-profile {
        width: 100%;
        justify-content: space-between;
    }

    /* KPI grid 1 kolom di HP kecil */
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .kpi-card {
        padding: 16px;
        gap: 12px;
    }

    .kpi-icon {
        width: 48px;
        height: 48px;
        font-size: 1.4rem;
        border-radius: 12px;
        flex-shrink: 0;
    }

    .kpi-info h3 {
        font-size: 1.5rem;
    }

    /* Card header wrap */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .search-box input {
        width: 100%;
    }

    .search-box {
        width: 100%;
    }

    /* Form row jadi vertikal */
    .form-group.row {
        flex-direction: column;
        gap: 12px;
    }

    .row .col,
    .row .col-small {
        flex: unset;
        width: 100%;
    }

    .form-card {
        max-width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }

    .btn-primary {
        width: 100%;
        justify-content: center;
    }

    /* Tombol Tambah Barang */
    button[onclick*="addItemRow"] {
        font-size: 0.9rem;
    }

    /* Responsif tabel */
    .styled-table th,
    .styled-table td {
        padding: 10px 10px;
        font-size: 0.88rem;
    }

    /* Laporan per divisi */
    .report-grid {
        grid-template-columns: 1fr !important;
    }

    /* History cards */
    .log-entry {
        padding: 14px !important;
    }

    /* Serial number inputs stapel vertikal */
    .serial-inputs {
        flex-direction: column !important;
        gap: 8px !important;
    }

    /* Login overlay form */
    #global-login-overlay > div {
        padding: 28px 20px !important;
    }

    /* Alert modal */
    .alert-modal-box {
        padding: 28px 20px !important;
        margin: 16px !important;
    }
}

/* Layar sangat kecil (< 400px) */
@media (max-width: 400px) {
    .nav-item {
        font-size: 0.58rem;
        padding: 8px 4px 12px;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .kpi-info h3 {
        font-size: 1.3rem;
    }

    .header-title h2 {
        font-size: 1.2rem;
    }
}
