/* PDAM API Dashboard Styles */

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #059669;
    --warning-color: #d97706;
    --danger-color: #dc2626;
    --info-color: #0891b2;
    --light-bg: #f8fafc;
    --dark-bg: #1e293b;
    --sidebar-width: 280px;
    --sidebar-width-collapsed: 76px;
}

/* Global Styles */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-bg);
    padding-top: 56px;
}

/* Compact mode: jadikan tabel seperti kartu untuk mobile-first */
.compact-mode table.card-table,
.compact-mode table.table,
.compact-mode table.dataTable {
    width: 100%;
}
.compact-mode table.card-table thead,
.compact-mode table.table thead,
.compact-mode table.dataTable thead {
    display: none !important;
}
.compact-mode table.card-table tbody tr,
.compact-mode table.table tbody tr,
.compact-mode table.dataTable tbody tr {
    display: block !important;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 12px;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.06);
}
.compact-mode table.card-table tbody td,
.compact-mode table.table tbody td,
.compact-mode table.dataTable tbody td {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-start;
    border: none !important;
    padding: 6px 0;
    font-size: 0.95rem;
}
.compact-mode table.card-table tbody td::before,
.compact-mode table.table tbody td::before,
.compact-mode table.dataTable tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    margin-right: 8px;
    text-transform: none;
}
.compact-mode .card {
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}

/* Navigation */
.navbar {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 1030;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    line-height: 1.1;
    padding: 4px 0;
}

.navbar-brand .brand-logo {
    width: 160px;
    height: 44px;
    display: block;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    z-index: 1000;
    padding: 0;
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    min-height: calc(100vh - 56px);
    width: var(--sidebar-width) !important;
    transition: width 0.2s ease;
}

.sidebar .nav-link {
    color: #333;
    padding: 0.75rem 1rem;
    border-radius: 0;
    transition: all 0.3s ease;
}

/* Configuration Section Styling */
.sidebar .nav-item small {
    display: block;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    color: #6c757d;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

.sidebar .nav-link i.text-info,
.sidebar .nav-link i.text-warning,
.sidebar .nav-link i.text-secondary {
    margin-right: 0.5rem !important;
}

.sidebar hr {
    margin: 0.5rem 1rem;
    border-color: #dee2e6;
}

/* Configuration Menu Highlights */
.pulse-highlight {
    animation: pulseConfig 1.5s infinite;
    border: 2px solid var(--warning-color) !important;
}

@keyframes pulseConfig {
    0% {
        box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(217, 119, 6, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(217, 119, 6, 0);
    }
}

/* Configuration section styling */
.sidebar .nav-item .bg-light.rounded {
    border-left: 4px solid var(--primary-color);
    transition: all 0.3s ease;
}

.sidebar .nav-item .bg-light.rounded:hover {
    background-color: #e3f2fd !important;
    border-left-color: var(--info-color);
}

/* Configuration Shortcut Cards */
.config-shortcut {
    cursor: pointer;
    transition: all 0.3s ease;
}

.config-shortcut:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15) !important;
}

.config-shortcut:hover .card-body {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.bg-gradient-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #1e40af 100%);
}

.sidebar .nav-link:hover {
    background-color: #e2e8f0;
    color: var(--primary-color);
}

.sidebar .nav-link.active {
    background-color: var(--primary-color);
    color: white;
}

.sidebar .nav-link i {
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    margin-left: 0;
    padding: 20px;
    min-height: calc(100vh - 56px);
    transition: margin-left 0.2s ease;
}

@media (min-width: 768px) {
    .main-content {
        margin-left: var(--sidebar-width);
    }
}

/* Sidebar collapsed (desktop) */
body.sidebar-collapsed {
    --sidebar-width: var(--sidebar-width-collapsed);
}
body.sidebar-collapsed .sidebar .nav-link {
    text-align: center;
    padding: 0.75rem 0.5rem;
    font-size: 0;
}
body.sidebar-collapsed .sidebar .nav-link i {
    margin-right: 0 !important;
    font-size: 1.1rem;
}
body.sidebar-collapsed .sidebar .nav-item small,
body.sidebar-collapsed .sidebar .nav-item .bg-light.rounded,
body.sidebar-collapsed .sidebar hr {
    display: none !important;
}

@media (max-width: 767.98px) {
    body.sidebar-collapsed .sidebar {
        width: 280px !important;
    }
}

/* Content Sections */
.content-section {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
    transition: all 0.3s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.25rem 2rem 0 rgba(58, 59, 69, 0.25);
}

.card-header {
    background-color: #f8f9fc;
    border-bottom: 1px solid #e3e6f0;
    border-radius: 10px 10px 0 0 !important;
}

/* Stats Cards */
.border-left-primary {
    border-left: 0.25rem solid var(--primary-color) !important;
}

.border-left-success {
    border-left: 0.25rem solid var(--success-color) !important;
}

.border-left-info {
    border-left: 0.25rem solid var(--info-color) !important;
}

.border-left-warning {
    border-left: 0.25rem solid var(--warning-color) !important;
}

.text-primary {
    color: var(--primary-color) !important;
}

.text-success {
    color: var(--success-color) !important;
}

.text-info {
    color: var(--info-color) !important;
}

.text-warning {
    color: var(--warning-color) !important;
}

.text-gray-800 {
    color: #5a5c69 !important;
}

.text-gray-300 {
    color: #dddfeb !important;
}

.font-weight-bold {
    font-weight: 600 !important;
}

.text-xs {
    font-size: 0.75rem;
}

/* Tables */
.table {
    border-collapse: separate;
    border-spacing: 0;
}

.table th {
    background-color: #f8f9fc;
    border-bottom: 2px solid #e3e6f0;
    font-weight: 600;
    font-size: 0.85rem;
    color: #858796;
    padding: 1rem 0.75rem;
}

.table td {
    padding: 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid #e3e6f0;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.02);
}

/* Status Badges */
.badge {
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

.badge.bg-success {
    background-color: var(--success-color) !important;
}

.badge.bg-warning {
    background-color: var(--warning-color) !important;
}

.badge.bg-danger {
    background-color: var(--danger-color) !important;
}

.badge.bg-secondary {
    background-color: var(--secondary-color) !important;
}

/* Buttons */
.btn {
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: #1d4ed8;
    border-color: #1d4ed8;
    transform: translateY(-1px);
}

.btn-outline-secondary {
    border-color: #e2e8f0;
    color: #64748b;
}

.btn-outline-secondary:hover {
    background-color: #64748b;
    border-color: #64748b;
}

/* Form Controls */
.form-control, .form-select {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.25);
}

/* Charts */
.chart-container {
    position: relative;
    height: 300px;
}

/* Status Indicators */
.status-indicator {
    padding: 1rem;
    text-align: center;
    border-radius: 8px;
    background-color: #f8f9fc;
    border: 1px solid #e3e6f0;
    margin-bottom: 0.5rem;
}

.status-indicator i {
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.status-indicator span {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: #5a5c69;
}

/* Loading States */
.loading {
    opacity: 0.7;
    pointer-events: none;
}

.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Alerts */
.alert {
    border: none;
    border-radius: 8px;
    font-weight: 500;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border-left: 4px solid var(--success-color);
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border-left: 4px solid var(--danger-color);
}

.alert-warning {
    background-color: #fef3c7;
    color: #92400e;
    border-left: 4px solid var(--warning-color);
}

.alert-info {
    background-color: #cffafe;
    color: #155e75;
    border-left: 4px solid var(--info-color);
}

/* Modals */
.modal-content {
    border: none;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.modal-header {
    background-color: #f8f9fc;
    border-bottom: 1px solid #e3e6f0;
    border-radius: 10px 10px 0 0;
}

.modal-footer {
    background-color: #f8f9fc;
    border-top: 1px solid #e3e6f0;
    border-radius: 0 0 10px 10px;
}

/* Dropdown Menus */
.dropdown-menu {
    border: none;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dropdown-item {
    padding: 0.5rem 1rem;
    transition: background-color 0.3s ease;
}

.dropdown-item:hover {
    background-color: #f8f9fc;
}

/* DataTables Customization */
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: white !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: #f8f9fc !important;
    border-color: #e2e8f0 !important;
    color: var(--primary-color) !important;
}

/* Responsive Adjustments */
@media (max-width: 767px) {
    /* Mobile sidebar behaves like an offcanvas */
    .sidebar {
        width: var(--sidebar-width);
        background-color: #ffffff !important;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    /* Overlay behind sidebar when open */
    #sidebarOverlay {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.35);
        z-index: 999;
        display: none;
        backdrop-filter: blur(1px);
    }
    #sidebarOverlay.active { display: block; }
    /* Main content uses full width */
    .main-content {
        margin-left: 0 !important;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .table-responsive {
        border: none;
    }

    /* Reduce padding for nav links for better fit */
    .sidebar .nav-link { padding: 0.65rem 0.85rem; }
}

/* Responsive table column visibility on small screens */
@media (max-width: 576px) {
    /* Transactions table: show ID, Customer, Amount, Status only */
    #transactionsTable th:nth-child(2),
    #transactionsTable td:nth-child(2), /* Client */
    #transactionsTable th:nth-child(5),
    #transactionsTable td:nth-child(5), /* Fee */
    #transactionsTable th:nth-child(7),
    #transactionsTable td:nth-child(7), /* Created At */
    #transactionsTable th:nth-child(8),
    #transactionsTable td:nth-child(8)  /* Actions */
    { display: none; }

    /* Reversals table: hide Client, Fee, Created, Actions */
    #reversalsTable th:nth-child(2),
    #reversalsTable td:nth-child(2),
    #reversalsTable th:nth-child(5),
    #reversalsTable td:nth-child(5),
    #reversalsTable th:nth-child(7),
    #reversalsTable td:nth-child(7),
    #reversalsTable th:nth-child(8),
    #reversalsTable td:nth-child(8)
    { display: none; }

    /* Clients table: show Code, Name, Status, Actions */
    #clientsTable th:nth-child(4),
    #clientsTable td:nth-child(4), /* Contact */
    #clientsTable th:nth-child(5),
    #clientsTable td:nth-child(5), /* Email */
    #clientsTable th:nth-child(6),
    #clientsTable td:nth-child(6), /* Rate Limit */
    #clientsTable th:nth-child(7),
    #clientsTable td:nth-child(7), /* Fee % */
    #clientsTable th:nth-child(8),
    #clientsTable td:nth-child(8), /* Active Keys */
    #clientsTable th:nth-child(10),
    #clientsTable td:nth-child(10) /* Created */
    { display: none; }

    /* API Keys table: show all columns for easier audit */

    /* Customers table: show ID, Name, Status, Actions */
    #customersTable th:nth-child(3),
    #customersTable td:nth-child(3), /* Address */
    #customersTable th:nth-child(4),
    #customersTable td:nth-child(4), /* Phone */
    #customersTable th:nth-child(6),
    #customersTable td:nth-child(6)  /* Last Transaction */
    { display: none; }

    /* Logs table: show Timestamp, Client, Response Code */
    #logsTable th:nth-child(2),
    #logsTable td:nth-child(2), /* Level */
    #logsTable th:nth-child(4),
    #logsTable td:nth-child(4), /* Endpoint */
    #logsTable th:nth-child(5),
    #logsTable td:nth-child(5), /* IP */
    #logsTable th:nth-child(7),
    #logsTable td:nth-child(7), /* Message */
    #logsTable th:nth-child(8),
    #logsTable td:nth-child(8)  /* Actions */
    { display: none; }

    /* Audit table: show Timestamp, User, Action, IP */
    #auditTable th:nth-child(4),
    #auditTable td:nth-child(4), /* Resource */
    #auditTable th:nth-child(5),
    #auditTable td:nth-child(5), /* Resource ID */
    #auditTable th:nth-child(7),
    #auditTable td:nth-child(7)  /* Details */
    { display: none; }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --light-bg: #0f172a;
        --dark-bg: #1e293b;
    }
    
    body {
        background-color: var(--dark-bg);
        color: #e2e8f0;
    }
    
    .sidebar {
        background-color: var(--dark-bg) !important;
        border-color: #334155;
    }
    
    .sidebar .nav-link {
        color: #e2e8f0;
    }
    
    .sidebar .nav-link:hover {
        background-color: #334155;
    }
    
    .card {
        background-color: var(--dark-bg);
        color: #e2e8f0;
    }
    
    .card-header {
        background-color: #334155;
        border-color: #475569;
    }
    
    .table th {
        background-color: #334155;
        color: #e2e8f0;
        border-color: #475569;
    }
    
    .table td {
        border-color: #475569;
        color: #e2e8f0;
    }
}

/* Print Styles */
@media print {
    .sidebar,
    .navbar,
    .btn-toolbar {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #dee2e6;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

.slide-in-left {
    animation: slideInLeft 0.5s ease-in-out;
}

.slide-in-right {
    animation: slideInRight 0.5s ease-in-out;
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Utility Classes */
.cursor-pointer {
    cursor: pointer;
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.border-radius-lg {
    border-radius: 10px;
}

.shadow-sm {
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.shadow-lg {
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175);
}

/* Admin Profile */
.profile-card .card-title {
    font-weight: 600;
}
.profile-card .form-label {
    font-weight: 600;
    color: #334155;
}
.password-rules {
    list-style: none;
    padding-left: 0;
    margin: 10px 0 12px;
    display: grid;
    gap: 6px;
}
.password-rules li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #6c757d;
}
.password-rules li.ok {
    color: #198754;
    font-weight: 600;
}
.password-rule-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    border: 1px solid #ced4da;
    background: #e9ecef;
    display: inline-block;
}
.password-rules li.ok .password-rule-dot {
    background: #22c55e;
    border-color: #16a34a;
}
