/* SILManager — IEC 61511 Safety Management System */

:root {
    /* Brand */
    --primary-color: #0d6efd;
    --secondary-color: #6c757d;
    --success-color: #198754;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #0dcaf0;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --border-radius: 0.375rem;
    --box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --box-shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.175);

    /* Sidebar */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 0px;
    --topbar-height: 52px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-muted: #64748b;
    --sidebar-active-bg: rgba(59, 130, 246, 0.15);
    --sidebar-active-text: #60a5fa;
    --sidebar-hover-bg: rgba(255,255,255,0.06);
    --sidebar-border: rgba(255,255,255,0.07);
    --sidebar-section-text: #475569;
}

/* =============================================
   LAYOUT — Sidebar + Topbar Application Shell
   ============================================= */

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f1f5f9;
    font-size: 0.875rem;
    overflow-x: hidden;
}

/* ---- Sidebar ---- */
#app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.25s ease;
}

#app-sidebar::-webkit-scrollbar { width: 4px; }
#app-sidebar::-webkit-scrollbar-track { background: transparent; }
#app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* Sidebar brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 0 1rem;
    height: var(--topbar-height);
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    text-decoration: none;
}
.sidebar-brand-text {
    color: #f1f5f9;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.02em;
    margin-left: 0.6rem;
}
.sidebar-brand-icon {
    color: #60a5fa;
    font-size: 1.25rem;
}

/* Current project pill in sidebar */
.sidebar-project {
    margin: 0.75rem 0.75rem 0.25rem;
    background: rgba(59,130,246,0.12);
    border: 1px solid rgba(59,130,246,0.25);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
}
.sidebar-project-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text-muted);
}
.sidebar-project-name {
    color: #93c5fd;
    font-weight: 600;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-project-code {
    color: var(--sidebar-text-muted);
    font-size: 0.68rem;
}

/* Section headings */
.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--sidebar-section-text);
    padding: 0.9rem 1rem 0.3rem;
}

/* Nav items */
.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}
.sidebar-nav-item {}
.sidebar-nav-link {
    display: flex;
    align-items: center;
    padding: 0.42rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0;
    transition: background 0.15s, color 0.15s;
    font-size: 0.82rem;
    white-space: nowrap;
}
.sidebar-nav-link i {
    width: 1.2rem;
    font-size: 0.9rem;
    margin-right: 0.6rem;
    flex-shrink: 0;
    text-align: center;
    color: var(--sidebar-text-muted);
    transition: color 0.15s;
}
.sidebar-nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #e2e8f0;
}
.sidebar-nav-link:hover i { color: #94a3b8; }
.sidebar-nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}
.sidebar-nav-link.active i { color: var(--sidebar-active-text); }

/* Sub-level items (indented) */
.sidebar-nav-link.sub {
    padding-left: 2.4rem;
    font-size: 0.8rem;
}

/* Divider */
.sidebar-divider {
    border: none;
    border-top: 1px solid var(--sidebar-border);
    margin: 0.5rem 0;
}

/* ---- Topbar ---- */
#app-topbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    z-index: 999;
    gap: 1rem;
}

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    color: #475569;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem;
}

.topbar-breadcrumb {
    flex: 1;
    min-width: 0;
}
.topbar-breadcrumb .breadcrumb {
    margin: 0;
    padding: 0;
    background: none;
    font-size: 0.8rem;
}
.topbar-breadcrumb .breadcrumb-item.active { color: #1e293b; font-weight: 600; }
.topbar-breadcrumb .breadcrumb-item a { color: var(--primary-color); text-decoration: none; }
.topbar-breadcrumb .breadcrumb-item a:hover { text-decoration: underline; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}
.topbar-user .dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: #334155;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.35rem 0.6rem;
    border-radius: var(--border-radius);
    transition: background 0.15s;
}
.topbar-user .dropdown-toggle:hover { background: #f1f5f9; }
.topbar-user .dropdown-toggle::after { display: none; }
.topbar-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ---- Main content ---- */
#app-main {
    margin-left: var(--sidebar-width);
    padding-top: var(--topbar-height);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-content {
    flex: 1;
    padding: 1.25rem 1.5rem;
}

/* Page header inside content */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.page-header-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.page-header-title i { color: var(--primary-color); }
.page-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Footer */
#app-footer {
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    color: #94a3b8;
    display: flex;
    justify-content: space-between;
}

/* =============================================
   TABLES — Compact tabular lists
   ============================================= */

.table {
    font-size: 0.82rem;
    background: #fff;
}
.table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    color: #64748b;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    background: #f8fafc;
    padding: 0.6rem 0.75rem;
}
.table td {
    vertical-align: middle;
    padding: 0.5rem 0.75rem;
    color: #334155;
    border-color: #f1f5f9;
}
.table-hover tbody tr:hover { background: rgba(59,130,246,0.04); }
.table > :not(caption) > * > * { padding: 0.5rem 0.75rem; }

/* Action buttons in table rows */
.table-actions { white-space: nowrap; }
.table-actions .btn { padding: 0.2rem 0.5rem; font-size: 0.75rem; }

/* =============================================
   CARDS — Used only for detail pages
   ============================================= */

.card {
    border: 1px solid #e2e8f0;
    box-shadow: var(--box-shadow);
    border-radius: 0.5rem;
    background: #fff;
}
.card-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.65rem 1rem;
    color: #334155;
}
.card-body { padding: 1rem; }

/* Section card for detail pages */
.detail-section {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}
.detail-section-header {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.82rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #f8fafc;
    border-radius: 0.5rem 0.5rem 0 0;
}
.detail-section-body { padding: 0.75rem 1rem; }

/* =============================================
   BADGES
   ============================================= */

.badge {
    font-weight: 500;
    font-size: 0.7em;
    padding: 0.35em 0.65em;
    border-radius: 0.3em;
}

/* Status badges */
.badge-status-draft       { background: #dbeafe; color: #1d4ed8; }
.badge-status-review      { background: #fef3c7; color: #92400e; }
.badge-status-approved    { background: #d1fae5; color: #065f46; }
.badge-status-implemented { background: #ede9fe; color: #5b21b6; }
.badge-status-active      { background: #d1fae5; color: #065f46; }
.badge-status-completed   { background: #dbeafe; color: #1e40af; }
.badge-status-on_hold     { background: #fef3c7; color: #92400e; }
.badge-status-cancelled   { background: #f1f5f9; color: #64748b; }
.badge-status-design      { background: #dbeafe; color: #1d4ed8; }
.badge-status-verification{ background: #fef3c7; color: #92400e; }
.badge-status-validation  { background: #ede9fe; color: #5b21b6; }
.badge-status-operational { background: #d1fae5; color: #065f46; }

/* SIL badges */
.badge-sil-0 { background: #f1f5f9; color: #475569; }
.badge-sil-1 { background: #d1fae5; color: #065f46; }
.badge-sil-2 { background: #fef3c7; color: #92400e; }
.badge-sil-3 { background: #fed7aa; color: #9a3412; }
.badge-sil-4 { background: #fee2e2; color: #991b1b; }

/* Risk badges */
.badge-risk-low       { background: #d1fae5; color: #065f46; }
.badge-risk-medium    { background: #fef3c7; color: #92400e; }
.badge-risk-high      { background: #fed7aa; color: #9a3412; }
.badge-risk-very_high { background: #fee2e2; color: #991b1b; }
.badge-risk-very-high { background: #fee2e2; color: #991b1b; }

/* =============================================
   FORMS
   ============================================= */

.form-label { font-weight: 500; font-size: 0.82rem; margin-bottom: 0.3rem; color: #374151; }
.form-control, .form-select {
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.85rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
    outline: none;
}

/* =============================================
   BUTTONS
   ============================================= */

.btn { font-size: 0.82rem; font-weight: 500; border-radius: 0.375rem; }
.btn-sm { font-size: 0.75rem; }
.btn-icon { padding: 0.3rem 0.5rem; }

/* =============================================
   ALERTS
   ============================================= */

.alert {
    border: 1px solid transparent;
    border-left-width: 4px;
    border-radius: 0.375rem;
    font-size: 0.85rem;
    padding: 0.65rem 1rem;
}
.alert-success  { border-left-color: var(--success-color); background: rgba(25,135,84,0.07); color: #0f5132; }
.alert-danger   { border-left-color: var(--danger-color);  background: rgba(220,53,69,0.07);  color: #842029; }
.alert-warning  { border-left-color: var(--warning-color); background: rgba(255,193,7,0.1);   color: #664d03; }
.alert-info     { border-left-color: var(--info-color);    background: rgba(13,202,240,0.07); color: #055160; }

/* =============================================
   LOGIN PAGE
   ============================================= */

.login-container {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: #fff;
    border-radius: 0.75rem;
    box-shadow: var(--box-shadow-lg);
    width: 100%;
    max-width: 380px;
}

/* =============================================
   PAGINATION
   ============================================= */

.pagination .page-link { color: var(--primary-color); font-size: 0.8rem; }
.pagination .page-link:hover { background: rgba(13,110,253,0.08); }
.pagination .page-item.active .page-link { background: var(--primary-color); border-color: var(--primary-color); }

/* =============================================
   OLD STATS CARD COLORS (kept for compat)
   ============================================= */

.border-left-primary { border-left: 0.25rem solid var(--primary-color) !important; }
.border-left-success { border-left: 0.25rem solid var(--success-color) !important; }
.border-left-info    { border-left: 0.25rem solid var(--info-color) !important; }
.border-left-warning { border-left: 0.25rem solid var(--warning-color) !important; }
.border-left-danger  { border-left: 0.25rem solid var(--danger-color) !important; }

/* =============================================
   SIL / RISK COLORS (legacy)
   ============================================= */

.risk-low      { color: var(--success-color); background-color: rgba(25,135,84,0.1); }
.risk-medium   { color: var(--warning-color); background-color: rgba(255,193,7,0.1); }
.risk-high     { color: #fd7e14;             background-color: rgba(253,126,20,0.1);}
.risk-very-high{ color: var(--danger-color); background-color: rgba(220,53,69,0.1); }
.sil-0 { color: var(--secondary-color); background-color: rgba(108,117,125,0.1); }
.sil-1 { color: var(--success-color);   background-color: rgba(25,135,84,0.1); }
.sil-2 { color: #fd7e14;                background-color: rgba(253,126,20,0.1); }
.sil-3 { color: var(--warning-color);   background-color: rgba(255,193,7,0.1); }
.sil-4 { color: var(--danger-color);    background-color: rgba(220,53,69,0.1); }

/* =============================================
   RESPONSIVE
   ============================================= */

@media (max-width: 992px) {
    #app-sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }
    #app-sidebar.open {
        transform: translateX(0);
    }
    #app-sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }
    #app-topbar { left: 0; }
    #app-main   { margin-left: 0; }
    .topbar-toggle { display: block; }
}

/* =============================================
   MISC UTILITIES
   ============================================= */

.text-xs  { font-size: 0.7rem; }
.text-sm  { font-size: 0.8rem; }
.fw-600   { font-weight: 600; }
.mono     { font-family: 'Consolas', monospace; font-size: 0.82rem; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Inline key-value pairs in detail pages */
.kv-row { display: flex; gap: 0.5rem; margin-bottom: 0.4rem; font-size: 0.82rem; }
.kv-label { color: #6b7280; font-weight: 500; min-width: 140px; flex-shrink: 0; }
.kv-value { color: #1e293b; }

/* IEC pill */
.iec-pill {
    display: inline-flex; align-items: center; gap: 0.3rem;
    background: #eff6ff; color: #1e40af;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem; font-weight: 600;
}

