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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

/* Login Page Styles */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1a365d 0%, #2d5a87 100%);
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

/* Login logo */
.login-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.login-logo svg {
    height: 36px;
    width: auto;
}

.login-box h1 {
    color: #1a365d;
    font-size: 24px;
    margin-bottom: 8px;
    text-align: center;
}

.login-box .subtitle {
    color: #666;
    text-align: center;
    margin-bottom: 30px;
    font-size: 14px;
}

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

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

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #2d5a87;
    box-shadow: 0 0 0 3px rgba(45, 90, 135, 0.1);
}

.btn {
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: #2d5a87;
    color: white;
}

.btn-primary:hover {
    background-color: #1a365d;
}

.btn-primary:disabled {
    background-color: #a0aec0;
    cursor: not-allowed;
}

.error-message {
    background-color: #fed7d7;
    color: #c53030;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
}

.login-footer {
    margin-top: 20px;
    text-align: center;
}

.login-footer a {
    color: #2d5a87;
    text-decoration: none;
    font-size: 13px;
}

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

/* App Page Styles */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    background: #1a365d;
    color: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
    font-size: 18px;
    font-weight: 500;
    color: #a0aec0;
    border-left: 1px solid #4a5568;
    padding-left: 16px;
    margin-left: 8px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.noble-logo {
    display: flex;
    align-items: center;
}

.noble-logo svg {
    height: 28px;
    width: auto;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-actions .user-email {
    font-size: 13px;
    opacity: 0.9;
}

.btn-secondary {
    background-color: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    font-size: 13px;
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-admin {
    background-color: rgba(255, 255, 255, 0.15);
    margin-right: 8px;
}

.app-main {
    flex: 1;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* Search Filters */
.search-filters {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.search-filters h2 {
    font-size: 16px;
    margin-bottom: 16px;
    color: #1a365d;
}

.filter-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filter-group {
    flex: 1;
    min-width: 200px;
}

.filter-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #555;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background-color: white;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #2d5a87;
    box-shadow: 0 0 0 3px rgba(45, 90, 135, 0.1);
}

.filter-actions {
    display: flex;
    gap: 10px;
}

.btn-search {
    background-color: #2d5a87;
    color: white;
    padding: 10px 24px;
    min-width: 120px;
}

.btn-search:hover {
    background-color: #1a365d;
}

.btn-clear {
    background-color: #e2e8f0;
    color: #4a5568;
    padding: 10px 20px;
}

.btn-clear:hover {
    background-color: #cbd5e0;
}

/* Data Grid Container */
.grid-container {
    flex: 1;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    min-height: 500px;
}

.grid-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 16px;
}

.grid-header h2 {
    font-size: 16px;
    color: #1a365d;
}

.result-count {
    font-size: 13px;
    color: #666;
}

#data-grid {
    height: calc(100vh - 340px);
    min-height: 400px;
}

/* Loading State */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #2d5a87;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Admin Page Styles */
.admin-container {
    max-width: 1000px;
    margin: 0 auto;
}

.admin-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 24px;
}

.admin-section-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-section-header h2 {
    font-size: 16px;
    color: #1a365d;
}

.admin-section-body {
    padding: 20px;
}

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

.user-table th,
.user-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.user-table th {
    background: #f7fafc;
    font-weight: 600;
    font-size: 13px;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-table td {
    font-size: 14px;
}

.user-table tr:hover {
    background: #f7fafc;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-admin {
    background: #e9d8fd;
    color: #6b46c1;
}

.badge-user {
    background: #bee3f8;
    color: #2b6cb0;
}

.badge-pending {
    background: #feebc8;
    color: #c05621;
}

.badge-approved {
    background: #c6f6d5;
    color: #276749;
}

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

.btn-danger {
    background-color: #e53e3e;
    color: white;
}

.btn-danger:hover {
    background-color: #c53030;
}

.btn-success {
    background-color: #38a169;
    color: white;
}

.btn-success:hover {
    background-color: #2f855a;
}

/* Add User Form */
.add-user-form {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

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

.add-user-form .form-group input,
.add-user-form .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    .filter-row {
        flex-direction: column;
    }
    
    .filter-group {
        min-width: 100%;
    }
    
    .app-header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* DataTables Theme Customizations */
#data-grid-wrapper {
    position: relative;
    overflow: hidden;
    padding: 0 20px 20px 20px;
}

/* Ensure DataTables fills container */
.dataTables_wrapper {
    width: 100% !important;
}

.dataTables_scroll {
    width: 100% !important;
}

.dataTables_scrollHead,
.dataTables_scrollBody {
    width: 100% !important;
}

#data-grid {
    font-size: 12px;
}

/* Use same font-size and padding for ALL th and td (including cloned header) */
#data-grid-wrapper th,
#data-grid-wrapper td,
.dataTables_scrollHead th,
.dataTables_scrollBody td {
    font-size: 12px !important;
    padding: 8px 10px !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
}

/* Header styling - applies to both original and cloned */
#data-grid-wrapper thead th,
.dataTables_scrollHead th {
    background-color: #f7fafc;
    color: #1a365d;
    font-weight: 600;
    border-bottom: 2px solid #e2e8f0;
    vertical-align: middle;
}

/* Body cell styling */
#data-grid-wrapper tbody td,
.dataTables_scrollBody td {
    border-bottom: 1px solid #e2e8f0;
}

.dataTables_scrollBody tbody tr:hover {
    background-color: #edf2f7 !important;
}

.dataTables_scrollBody tbody tr.selected {
    background-color: #e2e8f0 !important;
}

/* Row Group Styling */
.dataTables_scrollBody tbody tr.group-header {
    background-color: #edf2f7 !important;
    cursor: pointer;
}

.dataTables_scrollBody tbody tr.group-header:hover {
    background-color: #e2e8f0 !important;
}

.dataTables_scrollBody tbody tr.group-header td {
    padding: 10px 12px !important;
    border-bottom: 2px solid #2d5a87;
    font-size: 14px !important;
}

.dataTables_scrollBody tbody tr.group-header strong {
    color: #1a365d;
}

.group-toggle {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    margin-right: 10px;
    font-size: 14px;
    color: #2d5a87;
    vertical-align: middle;
    cursor: pointer;
}

.group-count {
    color: #666;
    font-weight: normal;
    margin-left: 8px;
}

/* Collapsed group header style */
.dataTables_scrollBody tbody tr.group-header.collapsed {
    background-color: #e2e8f0 !important;
}

/* Description column specific styling */
td.description-column {
    min-width: 400px !important;
    max-width: 700px !important;
    width: 500px !important;
}

.description-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Additional Mkt Research column specific styling */
td.mkt-research-column {
    min-width: 300px !important;
    max-width: 500px !important;
    width: 400px !important;
}

.mkt-research-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.dataTables_scrollHead {
    border-bottom: none !important;
}

.dataTables_scrollBody {
    border-top: none !important;
}

/* Loading overlay for table */
#table-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 100;
    font-size: 14px;
    color: #1a365d;
}

#table-loading .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #2d5a87;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Hide DataTables default elements we don't need */
.dataTables_length,
.dataTables_filter,
.dataTables_info,
.dataTables_paginate {
    display: none !important;
}

/* Selected cell/row styling */
#data-grid tbody td.selected,
#data-grid tbody tr.selected td {
    background-color: #bee3f8 !important;
    box-shadow: inset 0 0 0 1px #2d5a87;
}

#data-grid tbody td:focus {
    outline: 2px solid #2d5a87;
    outline-offset: -2px;
}

/* Make cells selectable */
#data-grid tbody td {
    user-select: text;
    cursor: cell;
}


/* DataTables buttons styling */
.dt-buttons {
    margin-bottom: 10px;
}

.dt-button {
    background-color: #2d5a87 !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    border-radius: 4px !important;
    margin-right: 8px !important;
}

.dt-button:hover {
    background-color: #1a365d !important;
}

/* Refresh button - pushed to far right */
.btn-refresh {
    background-color: transparent;
    color: #2d5a87;
    border: 1px solid #2d5a87;
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    margin-left: auto;
    width: auto !important;
}

.btn-refresh:hover {
    background-color: #2d5a87;
    color: white;
}


/* Server-Side Pagination Controls */
.server-pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 20px;
}

.pagination-btn {
    background: #2d5a87;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
    min-width: 36px;
}

.pagination-btn:hover:not(:disabled) {
    background: #1a365d;
}

.pagination-btn:disabled {
    background: #a0aec0;
    cursor: not-allowed;
}

#page-info {
    font-size: 13px;
    color: #4a5568;
    padding: 0 8px;
    min-width: 120px;
    text-align: center;
}

.page-size-select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: white;
    color: #4a5568;
    cursor: pointer;
    margin-left: 12px;
}

.page-size-select:focus {
    outline: none;
    border-color: #2d5a87;
}

/* Adjust grid header for pagination */
.grid-header {
    flex-wrap: wrap;
    gap: 12px;
}
