/* FM Checks - Main Stylesheet */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 200px;
    --topbar-height: 48px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
}

/* Dark Mode Variables — inverts all gray scale.
   NOTE: in dark mode, var(--gray-50..300) become dark values, var(--gray-600..900) become light.
   Always use hardcoded hex or high-numbered vars in .dark-mode { } rule overrides. */
.dark-mode {
    --gray-50: #111827;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--gray-900);
    background-color: var(--gray-50);
}

/* ===============================================
   SIDEBAR
   =============================================== */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: white;
    overflow-y: auto;
    transition: transform 0.25s ease;
    z-index: 1000;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
}

.dark-mode .sidebar {
    background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
}

.sidebar-header {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 6px;
    flex-shrink: 0;
}

.logo-text {
    font-size: 1rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.01em;
}

.sidebar-nav {
    padding: 0.5rem;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.625rem;
    margin-bottom: 0.125rem;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    font-size: 0.8125rem;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255,255,255,0.09);
    color: white;
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.9;
}

.nav-icon svg {
    display: block;
}

.nav-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.08);
    border: none;
    margin: 0.375rem 0.625rem;
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.sidebar-footer .btn-block {
    flex: 1;
}

/* ===============================================
   TOPBAR
   =============================================== */

.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.dark-mode .topbar {
    background: #1e293b;
    border-bottom-color: #334155;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--gray-700);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 6px;
    flex-shrink: 0;
}

.dark-mode .sidebar-toggle {
    color: #94a3b8;
}

.sidebar-toggle:hover {
    background: var(--gray-100);
}

.dark-mode .sidebar-toggle:hover {
    background: rgba(255,255,255,0.08);
}

.topbar-left {
    flex: 1;
    min-width: 0;
}

.page-heading {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.user-badge {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.0625rem;
}

.user-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-900);
    line-height: 1.2;
}

.user-role {
    font-size: 0.6875rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

/* ===============================================
   CONTENT
   =============================================== */

.content {
    flex: 1;
    padding: 1.25rem;
}

/* ===============================================
   FOOTER
   =============================================== */

.footer {
    padding: 0.75rem 1.25rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--gray-500);
    border-top: 1px solid var(--gray-200);
    background: white;
}

.dark-mode .footer {
    background: #1e293b;
    border-top-color: #334155;
}

/* ===============================================
   CARDS
   =============================================== */

.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1.25rem;
}

.dark-mode .card {
    background: #1e293b;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

.dark-mode .card-header {
    background: #0f172a;
    border-bottom-color: #334155;
}

.card-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0;
    color: var(--gray-900);
}

.card-body {
    padding: 1rem;
}

.card-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===============================================
   BUTTONS
   =============================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.4375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s, opacity 0.15s;
    line-height: 1.4;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-800);
    border: 1px solid var(--gray-200);
}

.dark-mode .btn-secondary {
    background: rgba(255,255,255,0.08);
    color: #cbd5e1;
    border-color: rgba(255,255,255,0.12);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.dark-mode .btn-secondary:hover {
    background: rgba(255,255,255,0.14);
}

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

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

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

.btn-success:hover {
    background: #15803d;
}

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

.btn-sm {
    font-size: 0.75rem;
    padding: 0.3125rem 0.625rem;
}

.btn-block {
    display: flex;
    width: 100%;
    justify-content: center;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

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

/* Button with icon + label inline */
.btn-icon-label {
    display: inline-flex;
    align-items: center;
    gap: 0.3125rem;
}

.btn-icon-label svg {
    flex-shrink: 0;
}

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

/* ===============================================
   FORMS
   =============================================== */

.form-group {
    margin-bottom: 0.875rem;
}

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

.dark-mode .form-group label {
    color: #94a3b8;
}

.form-control {
    width: 100%;
    padding: 0.4375rem 0.625rem;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.8125rem;
    background: white;
    color: var(--gray-900);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.dark-mode .form-control {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

.dark-mode .form-control::placeholder {
    color: #64748b;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.dark-mode .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.25);
}

.form-text {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
    display: block;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.25rem;
}

.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

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

/* Select dark mode */
.dark-mode select.form-control option {
    background: #1e293b;
    color: #e2e8f0;
}

/* ===============================================
   TABLES
   =============================================== */

.table-responsive {
    overflow-x: auto;
}

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

.table thead {
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
}

.dark-mode .table thead {
    background: #0f172a;
    border-bottom-color: #334155;
}

.table th {
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--gray-500);
}

.table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    color: var(--gray-900);
    border-bottom: 1px solid var(--gray-200);
}

.dark-mode .table td {
    border-bottom-color: #334155;
}

.table tbody tr:hover {
    background: var(--gray-50);
}

.dark-mode .table tbody tr:hover {
    background: rgba(255,255,255,0.03);
}

/* ===============================================
   BADGES
   =============================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1875rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    line-height: 1.4;
}

.badge-success, .badge-pass, .badge-ok {
    background: #dcfce7;
    color: #15803d;
}

.badge-danger, .badge-fail, .badge-overdue {
    background: #fee2e2;
    color: #991b1b;
}

.badge-warning, .badge-due-soon, .badge-due_soon {
    background: #fef3c7;
    color: #92400e;
}

.badge-low {
    background: var(--gray-100);
    color: var(--gray-600);
}

.badge-medium {
    background: #fef3c7;
    color: #92400e;
}

.badge-high {
    background: #fecaca;
    color: #991b1b;
}

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

.badge-status-open {
    background: #dbeafe;
    color: #1e40af;
}

.badge-status-in_progress {
    background: #fef3c7;
    color: #92400e;
}

.badge-status-resolved {
    background: #dcfce7;
    color: #15803d;
}

.badge-status-closed {
    background: var(--gray-100);
    color: var(--gray-600);
}

.badge-never {
    background: var(--gray-100);
    color: var(--gray-600);
}

/* ===============================================
   ALERTS
   =============================================== */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.8125rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.alert-success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #86efac;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-danger {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    flex-direction: column;
    align-items: flex-start;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
    flex-direction: column;
    align-items: flex-start;
}

.dark-mode .alert-success {
    background: rgba(22,163,74,0.15);
    color: #4ade80;
    border-color: rgba(22,163,74,0.3);
}

.dark-mode .alert-error {
    background: rgba(220,38,38,0.15);
    color: #f87171;
    border-color: rgba(220,38,38,0.3);
}

.dark-mode .alert-danger {
    background: rgba(220,38,38,0.12);
    color: #fca5a5;
    border-color: rgba(220,38,38,0.3);
}

.dark-mode .alert-warning {
    background: rgba(217,119,6,0.12);
    color: #fcd34d;
    border-color: rgba(217,119,6,0.3);
}

/* ===============================================
   PAGE HEADER
   =============================================== */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.25rem;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.25;
}

.breadcrumb-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.8125rem;
    margin-bottom: 0.375rem;
}

.breadcrumb-link:hover {
    text-decoration: underline;
}

/* ===============================================
   GRID / STATS
   =============================================== */

.grid-layout {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: white;
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.dark-mode .stat-card {
    background: #1e293b;
}

.stat-critical {
    border-left: 3px solid var(--danger);
}

.stat-icon {
    font-size: 2rem;
    line-height: 1;
}

.stat-info h3 {
    font-size: 1.625rem;
    font-weight: 700;
    margin-bottom: 0.125rem;
    line-height: 1;
}

.stat-info p {
    color: var(--gray-500);
    font-size: 0.75rem;
}

/* ===============================================
   AUTH PAGES
   =============================================== */

.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 1.5rem;
}

.auth-header {
    text-align: center;
    color: white;
    margin-bottom: 1.5rem;
}

.auth-header h1 {
    font-size: 2rem;
    margin-bottom: 0.375rem;
    font-weight: 700;
}

.auth-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.auth-card h2 {
    margin-bottom: 1.25rem;
    text-align: center;
    font-size: 1.125rem;
}

/* ===============================================
   AREA VIEWER & CANVAS
   =============================================== */

.area-viewer {
    background: white;
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.dark-mode .area-viewer {
    background: #1e293b;
}

.area-controls {
    display: flex;
    gap: 0.375rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.canvas-container {
    position: relative;
    overflow: auto;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    background: var(--gray-100);
    min-height: 300px;
    /* Allow canvas to fill container and not overflow */
    max-width: 100%;
}

.dark-mode .canvas-container {
    border-color: #334155;
    background: #0f172a;
}

#pdfCanvas {
    display: block;
    /* Canvas renders at its own pixel dimensions; keep it block so no extra spacing */
}

.checkpoint-legend {
    margin-top: 0.75rem;
    padding: 0.625rem 0.875rem;
    background: var(--gray-50);
    border-radius: 6px;
    border: 1px solid var(--gray-200);
}

.dark-mode .checkpoint-legend {
    background: #0f172a;
    border-color: #334155;
}

.checkpoint-legend h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--gray-500);
    margin-bottom: 0.375rem;
}

.legend-items {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--gray-600);
}

.dark-mode .legend-item {
    color: var(--gray-500);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-ok { background: var(--success); }
.status-due-soon { background: var(--warning); }
.status-overdue { background: var(--danger); }
.status-never { background: var(--gray-400); }

/* ===============================================
   MODAL
   =============================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    max-width: 480px;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.dark-mode .modal-content {
    background: #1e293b;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

.modal-header {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: inherit;
    z-index: 1;
}

.dark-mode .modal-header {
    border-bottom-color: #334155;
}

.modal-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0;
}

.modal-body {
    padding: 1rem;
}

.modal-body p {
    font-size: 0.8125rem;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.dark-mode .modal-body p {
    color: #94a3b8;
}

.btn-close {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: var(--gray-400);
    padding: 0.25rem;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.btn-close:hover {
    color: var(--gray-700);
    background: var(--gray-100);
}

.dark-mode .btn-close:hover {
    color: var(--gray-300);
    background: rgba(255,255,255,0.08);
}

/* ===============================================
   UTILITIES
   =============================================== */

.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }

/* Dark mode: ensure muted text is still visible */
.dark-mode .text-muted { color: #64748b; }

.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.875rem; }
.mt-4 { margin-top: 1.25rem; }
.mb-3 { margin-bottom: 0.875rem; }
.mb-4 { margin-bottom: 1.25rem; }

.mobile-only { display: none; }

/* ===============================================
   FOCUS / ACCESSIBILITY
   =============================================== */

.btn:focus-visible,
.nav-item:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ===============================================
   SIDEBAR BACKDROP (mobile)
   =============================================== */

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 999;
}

.sidebar-backdrop.active {
    display: block;
}

/* ===============================================
   RESPONSIVE — Mobile ≤768px
   =============================================== */

@media (max-width: 768px) {
    .sidebar {
        width: 260px;
        transform: translateX(-260px);
        z-index: 1100;
        box-shadow: none;
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.35);
    }

    .sidebar-backdrop {
        z-index: 1099;
    }

    .sidebar-toggle {
        display: flex;
    }

    .mobile-only {
        display: block;
    }

    .main-wrapper {
        margin-left: 0;
    }

    .topbar {
        padding: 0 0.875rem;
    }

    .content {
        padding: 0.875rem;
    }

    .page-header {
        flex-wrap: wrap;
    }

    .user-badge {
        display: none;
    }

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

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .nav-item {
        min-height: 40px;
    }

    .btn, .action-card {
        min-height: 40px;
    }

    .area-controls {
        gap: 0.25rem;
    }

    .area-controls .btn {
        min-height: 36px;
    }
}

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

/* ===============================================
   PRINT
   =============================================== */

@media print {
    .sidebar,
    .topbar,
    .sidebar-footer,
    .quick-actions-grid {
        display: none !important;
    }

    .main-wrapper {
        margin-left: 0;
    }

    .content {
        padding: 0;
    }
}
