/* ============================================================
   QSA Portal — Base Styles & CSS Variables
   Shared across all pages
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
    /* Brand colours — QSA navy + gold */
    --color-primary:        #082A3E;
    --color-primary-dark:   #051e2c;
    --color-primary-light:  #134074;
    --color-accent:         #ca0000;
    --color-accent-dark:    #a50000;
    --color-accent-light:   #e53333;

    /* Neutrals */
    --color-white:          #ffffff;
    --color-bg:             #f4f6f8;
    --color-bg-card:        #ffffff;
    --color-border:         #dde1e7;
    --color-border-light:   #eef0f3;

    /* Text */
    --color-text:           #1a2332;
    --color-text-muted:     #5a6478;
    --color-text-light:     #8a95a3;

    /* Status colours */
    --color-success:        #1a7a4a;
    --color-success-bg:     #e8f5ee;
    --color-warning:        #a05c00;
    --color-warning-bg:     #fef3e2;
    --color-danger:         #b91c1c;
    --color-danger-bg:      #fef2f2;
    --color-info:           #1d5fa6;
    --color-info-bg:        #eff6ff;

    /* Layout */
    --menu-height:          64px;
    --sidebar-width:        240px;
    --content-max-width:    1200px;
    --border-radius:        8px;
    --border-radius-sm:     4px;
    --border-radius-lg:     12px;

    /* Shadows */
    --shadow-sm:            0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:            0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg:            0 8px 24px rgba(0,0,0,0.12);

    /* Transitions */
    --transition:           all 0.2s ease;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--color-primary-light);
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--color-text);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

p { margin-bottom: 0.75rem; }
p:last-child { margin-bottom: 0; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.5;
}

.btn:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

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

.btn-primary:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary-light);
    color: var(--color-white);
    text-decoration: none;
}

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

.btn-secondary:hover {
    background: var(--color-bg);
    border-color: var(--color-primary);
    text-decoration: none;
}

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

.btn-accent:hover {
    background: var(--color-accent-dark);
    border-color: var(--color-accent-dark);
    color: var(--color-white);
    text-decoration: none;
}

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

.btn-danger:hover {
    background: #991b1b;
    color: var(--color-white);
    text-decoration: none;
}

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

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

.btn:disabled,
.btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-bg);
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1.25rem;
}

/* ── Forms ──────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1.125rem;
}

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

.form-control {
    width: 100%;
    padding: 0.5625rem 0.875rem;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(8, 42, 62, 0.12);
}

.form-control::placeholder {
    color: var(--color-text-light);
}

select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235a6478' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
    cursor: pointer;
}

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

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
    padding: 0.875rem 1.125rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.alert-success {
    background: var(--color-success-bg);
    border-color: #a3d9bc;
    color: var(--color-success);
}

.alert-warning {
    background: var(--color-warning-bg);
    border-color: #fcd38a;
    color: var(--color-warning);
}

.alert-danger {
    background: var(--color-danger-bg);
    border-color: #fca5a5;
    color: var(--color-danger);
}

.alert-info {
    background: var(--color-info-bg);
    border-color: #93c5fd;
    color: var(--color-info);
}

/* ── Status Badges ──────────────────────────────────────────── */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.status-work-order,
.status-pending {
    background: var(--color-info-bg);
    color: var(--color-info);
}

.status-in-progress {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.status-completed {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.status-cancelled,
.status-unsuccessful {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    background: var(--color-bg);
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--color-border-light);
    color: var(--color-text);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: var(--color-bg);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--color-white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
}

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

.modal-header h2 {
    color: var(--color-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
    border-radius: var(--border-radius-sm);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
    flex-wrap: wrap;
}

.modal-section {
    margin-bottom: 1.5rem;
}

.modal-section h3 {
    font-size: 0.9375rem;
    color: var(--color-primary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border-light);
}

.modal-section ul {
    list-style: none;
    display: grid;
    gap: 0.5rem;
}

.modal-section ul li {
    font-size: 0.875rem;
    color: var(--color-text);
}

.modal-section ul li strong {
    color: var(--color-text-muted);
    font-weight: 500;
    min-width: 120px;
    display: inline-block;
}

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.empty-state p {
    font-size: 0.9375rem;
}

/* ── Loading spinner ────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ── Utility ────────────────────────────────────────────────── */
.text-muted  { color: var(--color-text-muted); }
.text-small  { font-size: 0.8125rem; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.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; }
.d-flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    h1 { font-size: 1.375rem; }
    h2 { font-size: 1.125rem; }
    .modal-content { padding: 1.25rem; }
    .modal-footer { flex-direction: column; }
    .modal-footer .btn { width: 100%; justify-content: center; }
}
