/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 40px 30px;
    text-align: center;
}

header h1 {
    font-size: 32px;
    margin-bottom: 10px;
    font-weight: 700;
}

header p {
    font-size: 16px;
    opacity: 0.9;
}

/* Main content */
main {
    padding: 40px 30px;
}

/* Form sections */
.form-section {
    margin-bottom: 30px;
    padding-bottom: 30px;
    border-bottom: 2px solid #f0f0f0;
}

.form-section:last-child {
    border-bottom: none;
}

.form-section h2 {
    font-size: 20px;
    margin-bottom: 20px;
    color: #667eea;
    font-weight: 600;
}

/* Form groups */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
}

.form-group strong {
    font-weight: 600;
}

.help-text {
    display: block;
    font-size: 13px;
    color: #666;
    margin-top: 4px;
    font-weight: normal;
}

/* Radio buttons */
.radio-group {
    display: flex;
    gap: 20px;
    margin-top: 10px;
}

.radio-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 12px 20px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: #f9f9f9;
    transition: all 0.3s;
    flex: 1;
}

.radio-label:hover {
    border-color: #667eea;
    background: #f0f4ff;
}

.radio-label input[type="radio"] {
    margin-right: 10px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.radio-label input[type="radio"]:checked+span {
    font-weight: 600;
    color: #667eea;
}

.radio-label:has(input[type="radio"]:checked) {
    border-color: #667eea;
    background: #f0f4ff;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

/* File inputs */
input[type="file"] {
    display: block;
    width: 100%;
    padding: 12px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    background: #f9f9f9;
    cursor: pointer;
    transition: all 0.3s;
}

input[type="file"]:hover {
    border-color: #667eea;
    background: #f0f0ff;
}

.file-info {
    margin-top: 8px;
    font-size: 13px;
    color: #28a745;
}

/* Select and number inputs */
select,
input[type="number"] {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
}

select:focus,
input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

/* Multi-select specific styles */
select[multiple] {
    padding: 8px;
    min-height: 200px;
}

select[multiple] option {
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
}

select[multiple] option:hover {
    background: #f0f4ff;
}

select[multiple] option:checked {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
}

/* Checkboxes */
.checkbox-group label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    padding: 12px;
    border-radius: 8px;
    transition: background 0.3s;
}

.checkbox-group label:hover {
    background: #f9f9f9;
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-group strong {
    display: block;
}

/* Buttons */
.btn {
    padding: 14px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-block;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

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

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.form-actions {
    margin-top: 30px;
    text-align: center;
}

/* Progress section */
.progress-section {
    text-align: center;
    padding: 40px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% {
        width: 0%;
    }

    50% {
        width: 70%;
    }

    100% {
        width: 100%;
    }
}

#progressText {
    color: #667eea;
    font-weight: 600;
}

/* Results section */
.results-section {
    padding: 40px;
    text-align: center;
}

.results-section h2 {
    color: #28a745;
    margin-bottom: 15px;
}

#resultsMessage {
    margin-bottom: 30px;
    color: #666;
}

.download-links {
    margin: 30px 0;
}

.download-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    margin-bottom: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.download-item-info {
    flex: 1;
    text-align: left;
}

.download-item-info strong {
    display: block;
    margin-bottom: 4px;
    color: #333;
}

.download-item-info small {
    color: #666;
}

.download-btn {
    padding: 8px 20px;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.3s;
}

.download-btn:hover {
    background: #764ba2;
    transform: translateY(-2px);
}

/* Error section */
.error-section {
    padding: 40px;
    text-align: center;
}

.error-section h2 {
    color: #dc3545;
    margin-bottom: 15px;
}

#errorMessage {
    color: #666;
    margin-bottom: 20px;
}

#errorDetails {
    margin: 20px 0;
    text-align: left;
}

#errorDetails summary {
    cursor: pointer;
    color: #667eea;
    font-weight: 600;
    margin-bottom: 10px;
}

#errorTrace {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    color: #dc3545;
}

/* Footer */
footer {
    background: #f8f9fa;
    padding: 20px 30px;
    text-align: center;
    color: #666;
    font-size: 14px;
    border-top: 1px solid #e0e0e0;
}

footer a {
    color: #667eea;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Spinner */
.spinner {
    display: inline-block;
}

/* Tabs Navigation */
.tabs {
    display: flex;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 30px;
    gap: 5px;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background: #f5f5f5;
    color: #666;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
    transition: all 0.3s;
    border: 2px solid transparent;
    border-bottom: none;
    position: relative;
    top: 2px;
}

.tab-btn:hover {
    background: #e8e8e8;
    color: #333;
}

.tab-btn.active {
    background: white;
    color: #667eea;
    border-color: #e0e0e0;
    border-bottom-color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Data Tables */
.data-table-container {
    overflow-x: auto;
    margin: 20px 0;
}

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

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.data-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    position: sticky;
    top: 0;
}

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

.data-table tbody tr:nth-child(even) {
    background: #fafafa;
}

.data-table tbody tr:nth-child(even):hover {
    background: #f0f4ff;
}

/* Action buttons in table */
.action-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-right: 5px;
    transition: all 0.2s;
}

.action-btn.edit {
    background: #17a2b8;
    color: white;
}

.action-btn.edit:hover {
    background: #138496;
}

.action-btn.delete {
    background: #dc3545;
    color: white;
}

.action-btn.delete:hover {
    background: #c82333;
}

/* Add Item Form */
.add-item-form {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.add-item-form h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 18px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row select {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.form-row input:focus,
.form-row select:focus {
    outline: none;
    border-color: #667eea;
}

.form-row label {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    display: block;
}

.btn-add {
    background: #28a745;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-add:hover {
    background: #218838;
    transform: translateY(-1px);
}

.btn-cancel {
    background: #6c757d;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 10px;
}

.btn-cancel:hover {
    background: #5a6268;
}

/* Toggle Add Form Button */
.btn-toggle-form {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 20px;
    transition: all 0.3s;
}

.btn-toggle-form:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.3);
}

/* Export Button */
.btn-export {
    background: linear-gradient(135deg, #17a2b8 0%, #20c997 100%);
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.3s;
}

.btn-export:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(23, 162, 184, 0.3);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px;
    color: #666;
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 10px;
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: #dc3545;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
}

.toast {
    padding: 15px 25px;
    border-radius: 8px;
    margin-bottom: 10px;
    color: white;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}

.toast.success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

.toast.error {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.toast.info {
    background: linear-gradient(135deg, #17a2b8 0%, #138496 100%);
}

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

/* Count Badge */
.count-badge {
    background: #667eea;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    margin-left: 8px;
}

/* Wider container for data management */
.container.wide {
    max-width: 1200px;
}

/* Responsive */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .container {
        border-radius: 12px;
    }

    header {
        padding: 30px 20px;
    }

    header h1 {
        font-size: 24px;
    }

    main {
        padding: 30px 20px;
    }

    .download-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .download-btn {
        margin-top: 10px;
        width: 100%;
        text-align: center;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab-btn {
        flex: 1;
        min-width: 100px;
        text-align: center;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

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

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

/* ============================================================================
   LOGIN PAGE
   ============================================================================ */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-wrapper {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.login-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 36px 32px 28px;
    text-align: center;
}

.login-logo {
    font-size: 48px;
    margin-bottom: 10px;
}

.login-header h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-header p {
    font-size: 14px;
    opacity: 0.85;
}

.login-form-section {
    padding: 32px;
}

.login-form-section h2 {
    font-size: 20px;
    color: #667eea;
    font-weight: 600;
    margin-bottom: 24px;
}

.login-field {
    margin-bottom: 20px;
}

.login-field label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: #444;
    margin-bottom: 8px;
}

.login-field input[type="text"],
.login-field input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: #fafafa;
}

.login-field input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.password-wrapper {
    position: relative;
}

.password-wrapper input[type="password"],
.password-wrapper input[type="text"] {
    padding-right: 48px;
}

.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 4px;
    color: #666;
}

.toggle-password:hover {
    color: #333;
}

.login-btn {
    width: 100%;
    margin-top: 8px;
    font-size: 16px;
    padding: 14px;
}

.login-error {
    background: #fff5f5;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    color: #721c24;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.login-error::before {
    content: '⚠️';
    flex-shrink: 0;
}

.login-footer {
    padding: 16px 32px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    font-size: 13px;
}

.login-footer a {
    color: #667eea;
    text-decoration: none;
}

.login-footer a:hover {
    text-decoration: underline;
}

/* ============================================================================
   HEADER USER BAR
   ============================================================================ */

.header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.header-brand {
    flex: 1;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 4px;
    flex-shrink: 0;
}

.user-info {
    font-size: 14px;
    font-weight: 500;
    opacity: 0.9;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* ============================================================================
   ADMIN TAB & USER MANAGEMENT
   ============================================================================ */

.tab-btn-admin {
    margin-left: auto;
}

.role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    background: #e9ecef;
    color: #495057;
}

.role-badge.admin {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.admin-checkbox-group {
    display: flex;
    align-items: flex-end;
    padding-bottom: 2px;
}

.admin-checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #444;
    cursor: pointer;
}

.admin-checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* ============================================================================
   FORM VALIDATION STYLES
   ============================================================================ */

/* Form Validation Styles */
.error-message {
    color: #dc3545;
    font-size: 13px;
    margin-top: 5px;
    display: none;
    font-weight: 500;
}

.error-message.show {
    display: block;
}

.form-group.has-error input,
.form-group.has-error select {
    border-color: #dc3545;
    background-color: #fff5f5;
}

.form-group.has-error input:focus,
.form-group.has-error select:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

.form-group.has-success input,
.form-group.has-success select {
    border-color: #28a745;
}

.form-group.has-success input:focus,
.form-group.has-success select:focus {
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.1);
}