/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    color: #333;
    line-height: 1.6;
}

a {
    color: #4a90d9;
    text-decoration: none;
    cursor: pointer;
}

a:hover {
    text-decoration: underline;
}

.hidden { display: none !important; }

/* ===== TOASTS ===== */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 3.7s forwards;
    max-width: 400px;
}

.toast.success { background: #28a745; }
.toast.error   { background: #dc3545; }
.toast.warning { background: #ffc107; color: #333; }
.toast.info    { background: #17a2b8; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* ===== AUTH PAGES ===== */
.page {
    display: none;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
}
.page.active { display: flex; }

.auth-box {
    background: #fff;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 420px;
    margin: 20px;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h1 {
    font-size: 28px;
    color: #2c3e50;
    margin-bottom: 8px;
}

.auth-header p {
    color: #888;
    font-size: 14px;
}

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

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #555;
}

.form-group input,
.form-group select,
.form-control {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
    background: #fafafa;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #4a90d9;
    background: #fff;
}

.form-group .error {
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
    display: none;
}

.form-group .error.visible {
    display: block;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: #4a90d9;
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #357abd; }

.btn-success {
    background: #28a745;
    color: #fff;
}
.btn-success:hover:not(:disabled) { background: #218838; }

.btn-danger {
    background: #dc3545;
    color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #c82333; }

.btn-secondary {
    background: #6c757d;
    color: #fff;
}
.btn-secondary:hover:not(:disabled) { background: #5a6268; }

.btn-full { width: 100%; }

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

/* ===== ERROR / SUCCESS MESSAGES ===== */
.error-msg {
    color: #dc3545;
    background: #f8d7da;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
}

.success-msg {
    color: #155724;
    background: #d4edda;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
}

/* ===== DASHBOARD LAYOUT ===== */
#dashboard-page {
    display: none;
    flex-direction: row;
    min-height: 100vh;
}
#dashboard-page.active { display: flex; }

#sidebar {
    width: 260px;
    background: #1a1a2e;
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 20px;
    margin-bottom: 12px;
    color: #e0e0e0;
}

#user-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#user-name {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

#user-level-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    width: fit-content;
}

.badge-staff    { background: #6c757d; color: #fff; }
.badge-manager  { background: #ffc107; color: #333; }
.badge-admin    { background: #dc3545; color: #fff; }

.sidebar-menu {
    list-style: none;
    padding: 12px 0;
    flex: 1;
    overflow-y: auto;
}

.sidebar-menu li {
    padding: 0;
}

.sidebar-menu li a {
    display: block;
    padding: 12px 20px;
    color: #b0b0b0;
    font-size: 14px;
    transition: all 0.2s;
    text-decoration: none;
    cursor: pointer;
}

.sidebar-menu li a:hover,
.sidebar-menu li a.active {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.sidebar-menu li a::before {
    content: "›";
    margin-right: 10px;
    font-weight: bold;
    font-size: 18px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* ===== MAIN CONTENT ===== */
#main-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    background: #f0f2f5;
}

#page-content {
    max-width: 1000px;
}

.page-section {
    display: none;
}
.page-section.active { display: block; }

.page-section h2 {
    font-size: 22px;
    color: #2c3e50;
    margin-bottom: 8px;
}

.page-section .section-desc {
    color: #888;
    font-size: 14px;
    margin-bottom: 24px;
}

/* ===== CARDS ===== */
.card {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.card h3 {
    font-size: 16px;
    color: #2c3e50;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

/* ===== TABLES ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead th {
    background: #f8f9fa;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #e0e0e0;
}

.data-table tbody td {
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
    color: #444;
}

.data-table tbody tr:hover {
    background: #f8f9fa;
}

.data-table .actions {
    display: flex;
    gap: 8px;
}

/* ===== FORMS (inline) ===== */
.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

.form-row .btn {
    margin-bottom: 18px;
}

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-staff    { background: #e2e3e5; color: #383d41; }
.badge-manager  { background: #fff3cd; color: #856404; }
.badge-admin    { background: #f8d7da; color: #721c24; }

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 40px;
    color: #aaa;
}

.empty-state p {
    font-size: 14px;
}

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: modalIn 0.2s ease;
}

.modal h3 {
    margin-bottom: 20px;
    color: #2c3e50;
}

.modal .form-group {
    margin-bottom: 16px;
}

.modal .modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

@keyframes modalIn {
    from { transform: scale(0.9); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

/* ===== TAGS ===== */
.mapfield-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    background: #e3f2fd;
    color: #1565c0;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.tag:hover {
    background: #bbdefb;
}

.tag-remove {
    background: none;
    border: none;
    color: #1565c0;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.tag-remove:hover {
    opacity: 1;
    color: #c62828;
}

/* ===== LOADING ===== */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top-color: #4a90d9;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
    color: #888;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e0e0e0;
    border-top-color: #4a90d9;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ===== DASHBOARD CARDS ===== */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.stat-icon {
    font-size: 32px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f7ff;
    border-radius: 12px;
}

.stat-info h3 {
    font-size: 13px;
    color: #888;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    border: none;
    padding: 0;
}

.stat-value {
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
}

.quick-actions {
    margin-top: 20px;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.action-buttons .btn {
    text-decoration: none;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 22px;
    color: #2c3e50;
    margin: 0;
}

/* ===== SEARCH BOX ===== */
.search-box {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.search-box .form-control {
    width: 280px;
}

.input-group {
    display: flex;
    gap: 8px;
}

.input-group .form-control {
    flex: 1;
}

/* ===== TABLE WRAPPER ===== */
.table-wrapper {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow-x: auto;
}

.empty-table {
    text-align: center;
    padding: 30px;
    color: #aaa;
    font-style: italic;
}

.text-right { text-align: right; }
.text-muted { color: #888; }

.actions-cell {
    white-space: nowrap;
}

.no-mapfields {
    color: #aaa;
    font-style: italic;
    font-size: 13px;
}

.table-info {
    color: #888;
    font-size: 13px;
    margin-top: 12px;
}

/* ===== ERROR STATE ===== */
.error-state {
    text-align: center;
    padding: 40px 20px;
    background: #fff;
    border-radius: 10px;
    margin-top: 20px;
}

.error-state h2 {
    color: #dc3545;
    margin-bottom: 12px;
}

.error-state p {
    color: #666;
    margin-bottom: 20px;
}

/* ===== SUCCESS MESSAGE ===== */
.success-message {
    color: #155724;
    background: #d4edda;
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 12px;
    font-size: 14px;
}

/* ===== AUTH PAGES (full width variant) ===== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-title {
    text-align: center;
    font-size: 24px;
    color: #2c3e50;
    margin-bottom: 8px;
}

.auth-subtitle {
    text-align: center;
    color: #888;
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-btn {
    width: 100%;
    margin-top: 8px;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    color: #888;
    font-size: 13px;
}

/* ===== TOP BAR ===== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    margin-bottom: 10px;
}

.topbar h1 {
    font-size: 24px;
    color: #2c3e50;
}

.topbar-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #888;
    font-size: 14px;
}

/* ===== SIDEBAR BACKDROP (mobile) ===== */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
    cursor: pointer;
}

.sidebar-backdrop.active {
    display: block;
}

/* ===== SIDEBAR TOGGLE ===== */
.sidebar-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    padding: 8px 10px;
    background: none;
    border: none;
    cursor: pointer;
    margin: 10px 0 0 10px;
}

.sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: #333;
    border-radius: 2px;
}

/* ===== SEARCH INPUT ===== */
.search-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: #fafafa;
    margin-bottom: 16px;
}

.search-input:focus {
    outline: none;
    border-color: #4a90d9;
    background: #fff;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 200;
        transition: left 0.25s ease;
    }

    #sidebar.open {
        left: 0;
    }

    #sidebar-backdrop.active {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }

    #main-content {
        padding: 20px;
    }

    .auth-box {
        padding: 30px 20px;
    }

    .data-table {
        font-size: 13px;
    }

    .data-table thead th,
    .data-table tbody td {
        padding: 8px;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 16px 20px;
    }

    .topbar h1 {
        font-size: 20px;
    }
}
