:root {
    --primary: #091F62;
    --accent: #05A2C7;
    --bg: #f8f9fa;
    --surface: #ffffff;
    --text: #333333;
    --text-light: #666666;
    --text-muted: #999999;
    --border: #e0e0e0;
    --border-light: #f0f0f0;
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #17a2b8;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    overflow-x: hidden;
    overflow-y: scroll;
}

body {
    height: 100%;
    font-family: Calibri, 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 100vw;
    overflow-x: hidden;
}

/* NAVBAR */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0 32px;
    display: flex;
    align-items: center;
    height: 64px;
    min-height: 64px;
    max-height: 64px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: none;
    border-bottom: 2px solid #061847;
    flex-wrap: nowrap;
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: white;
    font-size: 20px;
    font-weight: 600;
    flex-shrink: 0;
}

.navbar-brand img {
    height: 36px;
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 32px;
    flex: 1;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.navbar-menu a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: all 0.2s;
}

.navbar-menu a:hover,
.navbar-menu a.active {
    color: white;
    background: rgba(255,255,255,0.15);
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 16px;
    color: rgba(255,255,255,0.8);
    font-size: 14px;
    flex-shrink: 0;
    white-space: nowrap;
}

.navbar-user a {
    color: var(--accent);
    text-decoration: none;
}

.navbar-user a:hover {
    text-decoration: underline;
}

/* CONTAINER */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
    width: 100%;
}

.container-wide {
    max-width: 1400px;
}

/* CARDS */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

.card-header h2,
.card-header h3 {
    color: var(--primary);
    margin: 0;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
}

/* METRIC CARDS */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    text-align: center;
    border-top: 3px solid var(--accent);
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.metric-label {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* TABLES */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Extend to card edges so the table gets maximum width */
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    padding-left: 0;
    padding-right: 0;
}

table {
    width: 100%;
    min-width: 700px;   /* Force horizontal scroll rather than squeezing columns */
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead th {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
}

tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-light);
}

/* Action cells — allow wrapping so buttons don't overflow the table */
td:last-child {
    min-width: 150px;
}

tbody tr:hover {
    background: #f5f8ff;
}

tbody tr:nth-child(even) {
    background: #fafbfc;
}

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

/* BADGES */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-success {
    background: #e6f9ed;
    color: #1a7a3a;
}

.badge-warning {
    background: #fff8e1;
    color: #9a6700;
}

.badge-danger {
    background: #fde8e8;
    color: #c0392b;
}

.badge-info {
    background: #e3f2fd;
    color: #1565c0;
}

.badge-primary {
    background: #e8eaf6;
    color: var(--primary);
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    line-height: 1.5;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: #0a2878;
}

.btn-accent {
    background: var(--accent);
    color: white;
}

.btn-accent:hover {
    background: #048bab;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-warning {
    background: var(--warning);
    color: #333;
}

.btn-warning:hover {
    background: #e0a800;
}

.btn-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.75rem 2rem;
    font-size: 1rem;
}

/* FORMS */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(5,162,199,0.15);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

/* FORM GRID */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ALERTS */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success {
    background: #e6f9ed;
    color: #1a7a3a;
    border-left: 4px solid var(--success);
}

.alert-danger {
    background: #fde8e8;
    color: #c0392b;
    border-left: 4px solid var(--danger);
}

.alert-warning {
    background: #fff8e1;
    color: #9a6700;
    border-left: 4px solid var(--warning);
}

.alert-info {
    background: #e3f2fd;
    color: #1565c0;
    border-left: 4px solid var(--info);
}

/* PAGE HEADER */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    color: var(--primary);
    font-weight: 700;
}

/* FOOTER */
.footer {
    background: var(--primary);
    color: rgba(255,255,255,0.7);
    text-align: center;
    padding: 1rem;
    font-size: 0.85rem;
    margin-top: auto;
}

/* LOGIN PAGE */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, #0d2d7a 100%);
}

.login-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-card img {
    height: 50px;
    margin-bottom: 1.5rem;
}

.login-card h1 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.login-card p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-card .form-group {
    text-align: left;
}

.login-card .btn {
    width: 100%;
    justify-content: center;
    margin-top: 0.5rem;
}

/* MODAL */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    line-height: 1;
}

.modal-close:hover {
    color: var(--primary);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* BACKUP PAGE */
.backup-upload-row {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.backup-upload-row .form-control {
    max-width: 400px;
}

.backup-actions,
.actions-cell {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}

.backup-filename {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* FILTERS ROW */
.filters-row {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filters-row .form-group {
    margin-bottom: 0;
    min-width: 150px;
}

.filter-count {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 0.75rem;
}

/* PROGRESS BAR */
.progress-bar-container {
    background: var(--border-light);
    border-radius: 99px;
    height: 8px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.3s ease;
}

.progress-bar-fill.good {
    background: var(--success);
}

.progress-bar-fill.ok {
    background: var(--warning);
}

.progress-bar-fill.poor {
    background: var(--danger);
}

.progress-bar-fill.accent {
    background: var(--accent);
}

/* ASSESSMENT CHAT */
.assessment-container {
    max-width: 800px;
    margin: 0 auto;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.chat-message {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    max-width: 85%;
    line-height: 1.6;
}

.chat-message.ai {
    background: white;
    border: 1px solid var(--border-light);
    align-self: flex-start;
    box-shadow: var(--shadow);
}

.chat-message.user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
}

.chat-input-area {
    display: flex;
    gap: 0.75rem;
}

.chat-input-area textarea {
    flex: 1;
    min-height: 60px;
    resize: none;
}

/* PILLAR SCORE BAR */
.pillar-score-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.pillar-score-row .pillar-name {
    width: 200px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary);
    flex-shrink: 0;
}

.pillar-score-row .progress-bar-container {
    flex: 1;
}

.pillar-score-row .score-value {
    width: 50px;
    text-align: right;
    font-weight: 700;
    font-size: 0.9rem;
}

/* TABS */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border-light);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 0.9rem;
    color: var(--text-light);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--primary);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

/* EMPTY STATE */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}

.empty-state h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    margin-bottom: 1rem;
}

/* LOADING / HTMX */
.htmx-indicator {
    display: none;
    color: var(--accent);
    font-size: 0.85rem;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request .htmx-hide {
    display: none;
}

/* UTILITY CLASSES */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-muted);
}

.text-small {
    font-size: 0.85rem;
}

.text-accent {
    color: var(--accent);
}

.text-primary {
    color: var(--primary);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.mb-0 {
    margin-bottom: 0;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.d-flex {
    display: flex;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 1rem;
}

.align-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

/* RESPONSIVE DESIGN */
@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
    }

    .navbar-menu {
        display: none;
    }

    .container {
        padding: 1rem;
    }

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

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .card {
        padding: 1rem;
    }

    .table-container {
        margin-left: -1rem;
        margin-right: -1rem;
    }

    table {
        font-size: 0.82rem;
    }

    thead th, tbody td {
        padding: 0.5rem 0.6rem;
    }

    .backup-actions,
    .actions-cell {
        gap: 0.25rem;
    }

    .backup-actions .btn-sm,
    .actions-cell .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .backup-upload-row {
        flex-direction: column;
        align-items: stretch;
    }

    .backup-upload-row .form-control {
        max-width: 100%;
    }

    .metrics-grid {
        grid-template-columns: 1fr 1fr;
    }

    .pillar-score-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .pillar-score-row .pillar-name {
        width: auto;
    }
}

@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .chat-message {
        max-width: 100%;
    }

    .filters-row {
        flex-direction: column;
    }

    .filters-row .form-group {
        width: 100%;
        min-width: unset;
    }
}
