/**
 * WellSky Common Styles
 *
 * Shared CSS for consistent styling across all WellSky Data Uploader pages.
 * This file standardizes colors, typography, buttons, modals, badges, and other
 * common UI components.
 */

/* ============================================
   CSS Variables - WellSky Brand Colors
   ============================================ */
:root {
    /* WellSky Brand Colors */
    --wellsky-indigo: #253746;
    --wellsky-deeper-blue: #28939D;
    --wellsky-blue: #71B0B4;
    --wellsky-ocher: #D38235;
    --wellsky-saffron: #93272C;
    --wellsky-sand: #D6D2C4;

    /* Application Color Mapping */
    --primary-color: #28939D;
    --primary-hover: #253746;
    --success-color: #059669;
    --error-color: #93272C;
    --warning-color: #D38235;
    --bg-color: #F5F4F2;
    --card-bg: #ffffff;
    --border-color: #D6D2C4;
    --text-color: #253746;
    --text-muted: #5A6B7A;
}

/* ============================================
   Base Styles
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', Arial, -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    font-weight: 300;
}

/* ============================================
   Container - Standardized to 1400px
   ============================================ */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* ============================================
   Header Styles
   ============================================ */
header {
    background: var(--wellsky-indigo);
    color: white;
    padding: 1.5rem 0;
    margin-bottom: 2rem;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0;
    padding-bottom: 0;
}

header .header-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

header .logo {
    height: 40px;
    width: auto;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 300;
}

header h1 span {
    color: var(--wellsky-blue);
}

header p {
    opacity: 0.9;
    margin-top: 0.5rem;
    font-weight: 300;
}

/* ============================================
   Navigation
   ============================================ */
.header-nav {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 400;
    transition: all 0.2s;
}

.nav-link:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.nav-link.active {
    color: white;
    background: rgba(255, 255, 255, 0.2);
    font-weight: 500;
}

/* ============================================
   Context Indicator
   ============================================ */
.context-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
}

.context-indicator .context-text {
    color: rgba(255, 255, 255, 0.9);
}

.context-indicator .context-value {
    color: var(--wellsky-blue);
    font-weight: 500;
}

.context-indicator .btn-change {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.context-indicator .btn-change:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   User Info in Header
   ============================================ */
.header-user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.header-user-info:hover {
    background: rgba(255, 255, 255, 0.2);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--wellsky-deeper-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 0.875rem;
    color: white;
    text-transform: uppercase;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.user-name-header {
    font-weight: 500;
    font-size: 0.875rem;
    color: white;
    line-height: 1.2;
}

.user-role-header {
    font-size: 0.75rem;
    color: var(--wellsky-blue);
    text-transform: capitalize;
}

.user-dropdown-icon {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    transition: transform 0.2s;
}

.header-user-info.open .user-dropdown-icon {
    transform: rotate(180deg);
}

/* ============================================
   User Dropdown
   ============================================ */
.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    min-width: 220px;
    z-index: 100;
    overflow: hidden;
}

.user-dropdown.show {
    display: block;
}

.user-dropdown-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
}

.user-dropdown-email {
    font-size: 0.75rem;
    color: var(--text-muted);
    word-break: break-all;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-color);
    text-decoration: none;
    transition: background 0.2s;
    font-size: 0.875rem;
}

.user-dropdown-item:hover {
    background: var(--bg-color);
}

.user-dropdown-item .icon {
    font-size: 1rem;
    opacity: 0.7;
}

/* ============================================
   User Loading State
   ============================================ */
.user-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
}

.user-loading .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ============================================
   Spinner Animation - Standardized to 0.8s
   ============================================ */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* ============================================
   Modal Styles - Standardized backdrop
   ============================================ */
.context-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(37, 55, 70, 0.6);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.context-modal.active {
    display: flex;
}

.context-modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.context-modal-header {
    background: var(--wellsky-indigo);
    color: white;
    padding: 1.5rem;
    text-align: center;
}

.context-modal-header h2 {
    margin: 0 0 0.5rem 0;
    font-weight: 500;
}

.context-modal-header p {
    margin: 0;
    opacity: 0.9;
    font-size: 0.9rem;
}

.context-modal-body {
    padding: 1.5rem;
}

.context-modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ============================================
   Cards - Standardized shadow
   ============================================ */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 500;
    margin-bottom: 1rem;
    color: var(--wellsky-indigo);
}

/* ============================================
   Buttons - Standardized to 0.75rem 1.5rem padding
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    font-family: 'Roboto', sans-serif;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #047857;
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #7f1d22;
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #b86b2a;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--bg-color);
}

/* ============================================
   Badges - Unified styles
   ============================================ */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* Status badges */
.badge-draft { background: #E5E7EB; color: #4B5563; }
.badge-pending_review { background: rgba(211, 130, 53, 0.15); color: var(--warning-color); }
.badge-approved { background: rgba(5, 150, 105, 0.12); color: var(--success-color); }
.badge-rejected { background: rgba(147, 39, 44, 0.1); color: var(--error-color); }
.badge-deprecated { background: #D1D5DB; color: #6B7280; }

/* Role badges */
.badge-viewer { background: #E5E7EB; color: #4B5563; }
.badge-sme { background: rgba(113, 176, 180, 0.2); color: var(--wellsky-deeper-blue); }
.badge-approver { background: rgba(5, 150, 105, 0.12); color: var(--success-color); }
.badge-admin { background: rgba(147, 39, 44, 0.1); color: var(--error-color); }

/* Severity/Type badges */
.badge-error { background: rgba(147, 39, 44, 0.1); color: var(--error-color); }
.badge-warning { background: rgba(211, 130, 53, 0.15); color: var(--warning-color); }
.badge-info { background: rgba(113, 176, 180, 0.2); color: var(--wellsky-deeper-blue); }
.badge-success { background: rgba(5, 150, 105, 0.12); color: var(--success-color); }

/* ============================================
   Tables - Standardized header background to Indigo
   ============================================ */
table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    background: var(--wellsky-indigo);
    color: white;
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 500;
    font-size: 0.875rem;
}

table th:first-child {
    border-radius: 8px 0 0 0;
}

table th:last-child {
    border-radius: 0 8px 0 0;
}

table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

table tbody tr:hover {
    background: rgba(113, 176, 180, 0.05);
}

/* ============================================
   Form Elements
   ============================================ */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    font-family: 'Roboto', sans-serif;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(40, 147, 157, 0.1);
}

.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled {
    background: var(--bg-color);
    cursor: not-allowed;
}

/* ============================================
   Tabs
   ============================================ */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
    color: var(--text-muted);
    border-radius: 6px 6px 0 0;
    transition: all 0.2s;
    font-weight: 400;
}

.tab-btn:hover {
    color: var(--text-color);
    background: rgba(113, 176, 180, 0.1);
}

.tab-btn.active {
    background: var(--wellsky-deeper-blue);
    color: white;
    font-weight: 500;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================
   Alerts / Messages
   ============================================ */
.alert {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.alert-success {
    background: rgba(5, 150, 105, 0.1);
    border: 1px solid rgba(5, 150, 105, 0.3);
    color: var(--success-color);
}

.alert-error {
    background: rgba(147, 39, 44, 0.1);
    border: 1px solid rgba(147, 39, 44, 0.3);
    color: var(--error-color);
}

.alert-warning {
    background: rgba(211, 130, 53, 0.1);
    border: 1px solid rgba(211, 130, 53, 0.3);
    color: var(--warning-color);
}

.alert-info {
    background: rgba(113, 176, 180, 0.1);
    border: 1px solid rgba(113, 176, 180, 0.3);
    color: var(--wellsky-deeper-blue);
}

/* ============================================
   Multi-select Styles
   ============================================ */
.multi-select-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-height: 44px;
    background: white;
}

.multi-select-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: rgba(40, 147, 157, 0.15);
    color: var(--wellsky-deeper-blue);
    border-radius: 4px;
    font-size: 0.8125rem;
}

.multi-select-chip .remove {
    cursor: pointer;
    font-weight: bold;
    margin-left: 0.25rem;
}

.multi-select-chip .remove:hover {
    color: var(--error-color);
}

/* ============================================
   Utility Classes
   ============================================ */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-muted { color: var(--text-muted); }
.text-success { color: var(--success-color); }
.text-error { color: var(--error-color); }
.text-warning { color: var(--warning-color); }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.hidden { display: none !important; }
.visible { display: block; }

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 400px;
}

.toast {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: slideIn 0.3s ease-out;
    border-left: 4px solid var(--primary-color);
}

.toast.toast-success {
    border-left-color: var(--success-color);
}

.toast.toast-error {
    border-left-color: var(--error-color);
}

.toast.toast-warning {
    border-left-color: var(--warning-color);
}

.toast.toast-info {
    border-left-color: var(--primary-color);
}

.toast-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-color);
}

.toast-message {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.toast-action {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 0.875rem;
    cursor: pointer;
    padding: 0.25rem 0;
    margin-top: 0.5rem;
    font-weight: 500;
}

.toast-action:hover {
    text-decoration: underline;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    line-height: 1;
}

.toast-close:hover {
    color: var(--text-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast.removing {
    animation: slideOut 0.3s ease-out forwards;
}

/* ============================================
   Workflow Indicator
   ============================================ */
.workflow-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.workflow-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.workflow-step-badge {
    padding: 0.375rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    background: #E5E7EB;
    color: #6B7280;
}

.workflow-step.active .workflow-step-badge {
    background: var(--primary-color);
    color: white;
}

.workflow-step.completed .workflow-step-badge {
    background: var(--success-color);
    color: white;
}

.workflow-step.rejected .workflow-step-badge {
    background: var(--error-color);
    color: white;
}

.workflow-arrow {
    color: var(--text-muted);
    font-size: 1rem;
}

.workflow-guidance {
    text-align: center;
    padding: 0.75rem;
    background: rgba(40, 147, 157, 0.1);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--wellsky-deeper-blue);
    margin-bottom: 1rem;
}

.workflow-guidance.warning {
    background: rgba(211, 130, 53, 0.1);
    color: var(--warning-color);
}

.workflow-guidance.error {
    background: rgba(147, 39, 44, 0.1);
    color: var(--error-color);
}

/* ============================================
   Rejection Modal
   ============================================ */
.rejection-modal .modal-content {
    max-width: 500px;
}

.rejection-textarea {
    min-height: 100px;
    resize: vertical;
}

/* ============================================
   Quick Action Buttons
   ============================================ */
.quick-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Roboto', sans-serif;
    font-size: 0.9375rem;
    color: var(--text-color);
}

.quick-action-btn:hover {
    border-color: var(--primary-color);
    background: rgba(40, 147, 157, 0.05);
}

.quick-action-btn .icon {
    font-size: 1.125rem;
}

/* ============================================
   Dashboard Breakdown Tables
   ============================================ */
.breakdown-section {
    margin-bottom: 1.5rem;
}

.breakdown-section h3 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--wellsky-indigo);
    margin-bottom: 0.75rem;
}

.breakdown-table {
    width: 100%;
    border-collapse: collapse;
}

.breakdown-table th,
.breakdown-table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.breakdown-table th {
    background: var(--bg-color);
    font-weight: 500;
    color: var(--text-muted);
}

.breakdown-table .count-cell {
    text-align: center;
    font-weight: 500;
}

.breakdown-table .clickable-row {
    cursor: pointer;
}

.breakdown-table .clickable-row:hover {
    background: rgba(40, 147, 157, 0.05);
}

/* Needs Attention Section */
.needs-attention {
    background: rgba(211, 130, 53, 0.08);
    border: 1px solid rgba(211, 130, 53, 0.2);
    border-radius: 8px;
    padding: 1rem;
}

.needs-attention-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: var(--warning-color);
    margin-bottom: 0.75rem;
}

.attention-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(211, 130, 53, 0.1);
}

.attention-item:last-child {
    border-bottom: none;
}

/* ============================================
   Create Rule Dropdown
   ============================================ */
.create-rule-dropdown {
    position: relative;
    display: inline-block;
}

.create-rule-dropdown .dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    z-index: 100;
    margin-top: 0.25rem;
}

.create-rule-dropdown .dropdown-menu.show {
    display: block;
}

.create-rule-dropdown .dropdown-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 0.9375rem;
    font-family: 'Roboto', sans-serif;
    color: var(--text-color);
}

.create-rule-dropdown .dropdown-item:hover {
    background: var(--bg-color);
}

.create-rule-dropdown .dropdown-item:first-child {
    border-radius: 8px 8px 0 0;
}

.create-rule-dropdown .dropdown-item:last-child {
    border-radius: 0 0 8px 8px;
}

.dropdown-caret {
    margin-left: 0.5rem;
    font-size: 0.75rem;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header .container {
        flex-direction: column;
        gap: 1rem;
    }

    .header-nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.9375rem;
    }

    table {
        font-size: 0.8125rem;
    }

    table th,
    table td {
        padding: 0.5rem 0.75rem;
    }
}
