/*
 * PCEFlow – Main Stylesheet
 * ───────────────────────────
 * Design system:
 *   --primary : #1e3a5f  (dark navy sidebar/headers)
 *   --accent  : #e63946  (action red – buttons, highlights)
 *   --bg      : #f4f6f9  (page background)
 *
 * Injected as CSS custom properties per-org from header.php.
 * Do not hard-code these hex values elsewhere; always use var().
 */

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

:root {
    /* Fallback values – overridden by header.php inline <style> */
    --primary:        #1e3a5f;
    --accent:         #e63946;
    --bg:             #f4f6f9;
    --sidebar-width:  240px;
    --topbar-height:  56px;
    --card-shadow:    0 2px 8px rgba(0,0,0,.08);
    --radius:         8px;
    --font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
                      Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    --text:           #1a1a2e;
    --text-muted:     #6c757d;
    --border:         #dee2e6;
    --success:        #198754;
    --danger:         #dc3545;
    --warning:        #ffc107;
    --info:           #0dcaf0;
    --sidebar-text:   rgba(255,255,255,.85);
    --sidebar-hover:  rgba(255,255,255,.12);
    --sidebar-active: var(--accent);
}

html { font-size: 16px; }

body {
    font-family:      var(--font);
    background-color: var(--bg);
    color:            var(--text);
    line-height:      1.6;
    min-height:       100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
ul { list-style: none; }
button { cursor: pointer; font-family: inherit; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
        "topbar  topbar"
        "sidebar main";
    min-height: 100vh;
}

/* ── Top bar ───────────────────────────────────────────────────────────────── */
.topbar {
    grid-area: topbar;
    position:  fixed;
    top: 0; left: 0; right: 0;
    z-index:   200;
    height:    var(--topbar-height);
    background: var(--primary);
    color:      #fff;
    display:    flex;
    align-items: center;
    padding:    0 1rem;
    gap:        .75rem;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.topbar-brand {
    display:    flex;
    align-items: center;
    gap:        .5rem;
    flex:       1;
}

.topbar-logo {
    height:    32px;
    width:     auto;
    border-radius: 4px;
}

.topbar-title {
    font-size:   1rem;
    font-weight: 600;
    letter-spacing: .3px;
    white-space: nowrap;
    overflow:    hidden;
    text-overflow: ellipsis;
}

.topbar-right { margin-left: auto; }

.topbar-user {
    display:    flex;
    align-items: center;
    gap:        .5rem;
    color:      rgba(255,255,255,.9);
    font-size:  .875rem;
}

.topbar-username { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Hamburger button */
.sidebar-toggle {
    display:    none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width:      38px;
    height:     38px;
    gap:        5px;
    background: transparent;
    border:     none;
    color:      #fff;
    border-radius: var(--radius);
    padding:    6px;
    flex-shrink: 0;
    transition: background .15s;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.15); }
.hamburger-line {
    width:  22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    display: block;
    transition: all .25s;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    grid-area:  sidebar;
    position:   fixed;
    top:        var(--topbar-height);
    left:       0;
    width:      var(--sidebar-width);
    height:     calc(100vh - var(--topbar-height));
    background: var(--primary);
    overflow-y: auto;
    overflow-x: hidden;
    z-index:    150;
    transition: transform .25s ease;
    display:    flex;
    flex-direction: column;
}

.sidebar-inner {
    display:   flex;
    flex-direction: column;
    min-height: 100%;
    padding:   1rem 0 1.5rem;
}

.sidebar-brand {
    display:    flex;
    align-items: center;
    justify-content: center;
    padding:    .5rem 1rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
    margin-bottom: .5rem;
}

.sidebar-logo    { height: 36px; border-radius: 4px; }
.sidebar-logo-text {
    font-size:   1.4rem;
    font-weight: 700;
    color:       #fff;
    letter-spacing: .5px;
}

/* Nav lists */
.nav-list { padding: .25rem 0; }
.nav-list + .nav-list { margin-top: .25rem; }

.nav-link {
    display:        flex;
    align-items:    center;
    gap:            .6rem;
    padding:        .55rem 1rem .55rem 1.25rem;
    color:          var(--sidebar-text);
    font-size:      .875rem;
    font-weight:    500;
    border-left:    3px solid transparent;
    transition:     background .15s, color .15s, border-color .15s;
    border-radius:  0 var(--radius) var(--radius) 0;
    margin-right:   .5rem;
    text-decoration: none;
    position:       relative;
}

.nav-link:hover {
    background:  var(--sidebar-hover);
    color:       #fff;
    text-decoration: none;
}

.nav-link.active {
    background:  rgba(255,255,255,.12);
    color:       #fff;
    border-left-color: var(--accent);
    font-weight: 600;
}

.nav-link-disabled {
    opacity: .55;
    cursor:  default;
    pointer-events: none; /* still navigable for the lock pages */
    pointer-events: auto;
}
.nav-link-disabled:hover { background: transparent; color: var(--sidebar-text); }

.nav-link-logout:hover { background: rgba(230,57,70,.2); color: #ff8a93; }

.nav-icon  { font-size: 1rem; flex-shrink: 0; }
.nav-label { flex: 1; }
.nav-badge { font-size: .7rem; opacity: .6; }

.nav-divider {
    height:     1px;
    background: rgba(255,255,255,.1);
    margin:     .75rem 1rem;
}

.nav-section-label {
    font-size:    .7rem;
    font-weight:  700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color:        rgba(255,255,255,.45);
    padding:      .25rem 1.25rem .1rem;
}

.sidebar-spacer { flex: 1; }

/* Overlay for mobile */
.sidebar-overlay {
    display:    none;
    position:   fixed;
    inset:      0;
    z-index:    140;
    background: rgba(0,0,0,.5);
}

/* ── Main content area ─────────────────────────────────────────────────────── */
.main-content {
    grid-area:  main;
    margin-top: var(--topbar-height);
    /* No margin-left: the CSS grid column 1 (240px sidebar) already offsets main to x=240 */
    padding:    2rem;
    min-height: calc(100vh - var(--topbar-height));
}

.container {
    max-width: 1100px;
    margin:    0 auto;
}

.container-sm { max-width: 640px; margin: 0 auto; }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    flex-wrap:       wrap;
    gap:             .75rem;
    margin-bottom:   1.5rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: .9rem; margin-top: .1rem; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
    background:    #fff;
    border-radius: var(--radius);
    box-shadow:    var(--card-shadow);
    overflow:      hidden;
}

.card-header {
    padding:       1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight:   600;
    font-size:     .95rem;
    display:       flex;
    align-items:   center;
    gap:           .5rem;
}

.card-body { padding: 1.25rem; }

.card-footer {
    padding:       .75rem 1.25rem;
    border-top:    1px solid var(--border);
    background:    #fafafa;
    display:       flex;
    align-items:   center;
    gap:           .5rem;
    flex-wrap:     wrap;
}

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.25rem; }

/* Stat cards */
.stat-card {
    background:    #fff;
    border-radius: var(--radius);
    box-shadow:    var(--card-shadow);
    padding:       1.25rem;
    display:       flex;
    flex-direction: column;
    gap:           .25rem;
}
.stat-card .stat-icon  { font-size: 2rem; margin-bottom: .25rem; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display:       inline-flex;
    align-items:   center;
    gap:           .4rem;
    padding:       .5rem 1.1rem;
    border-radius: var(--radius);
    border:        1px solid transparent;
    font-size:     .875rem;
    font-weight:   600;
    line-height:   1.4;
    cursor:        pointer;
    transition:    all .15s;
    text-decoration: none;
    white-space:   nowrap;
    font-family:   inherit;
}
.btn:hover { text-decoration: none; opacity: .9; }
.btn:active { transform: translateY(1px); }

.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #c62f3b; border-color: #c62f3b; }

.btn-secondary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-secondary:hover { background: #162e4d; border-color: #162e4d; }

.btn-outline {
    background: transparent;
    color:      var(--primary);
    border-color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #fff; }

.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--border); color: var(--text); }

.btn-sm { padding: .3rem .75rem; font-size: .8rem; }
.btn-lg { padding: .7rem 1.5rem; font-size: 1rem; }

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

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

.form-control {
    display:       block;
    width:         100%;
    padding:       .5rem .75rem;
    font-size:     .9rem;
    font-family:   inherit;
    color:         var(--text);
    background:    #fff;
    border:        1px solid var(--border);
    border-radius: var(--radius);
    transition:    border-color .15s, box-shadow .15s;
    line-height:   1.5;
}
.form-control:focus {
    outline:      none;
    border-color: var(--primary);
    box-shadow:   0 0 0 3px rgba(30,58,95,.15);
}
.form-control::placeholder { color: #adb5bd; }
.form-control:disabled { background: #f8f9fa; cursor: not-allowed; opacity: .75; }

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

.form-hint  { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }
.form-error { font-size: .78rem; color: var(--danger); margin-top: .25rem; }

/* Input with button (password toggle) */
.input-group {
    display:  flex;
    position: relative;
}
.input-group .form-control { border-radius: var(--radius) 0 0 var(--radius); flex: 1; }
.input-group .input-group-btn {
    display:        flex;
    align-items:    center;
    padding:        0 .75rem;
    background:     #f8f9fa;
    border:         1px solid var(--border);
    border-left:    none;
    border-radius:  0 var(--radius) var(--radius) 0;
    cursor:         pointer;
    font-size:      .9rem;
    color:          var(--text-muted);
    transition:     background .15s;
}
.input-group .input-group-btn:hover { background: var(--border); }

/* Password strength bar */
.strength-bar-wrap {
    height:      6px;
    background:  var(--border);
    border-radius: 3px;
    margin-top:  .4rem;
    overflow:    hidden;
}
.strength-bar {
    height:     100%;
    width:      0;
    border-radius: 3px;
    transition: width .3s, background .3s;
}
.strength-label { font-size: .75rem; margin-top: .25rem; font-weight: 600; }
.strength-0 { width: 0%;   background: transparent; }
.strength-1 { width: 25%;  background: var(--danger); }
.strength-2 { width: 50%;  background: var(--warning); }
.strength-3 { width: 75%;  background: #fd7e14; }
.strength-4 { width: 100%; background: var(--success); }

/* Password generator widget */
.pwd-generator {
    background:    #f8f9fa;
    border:        1px solid var(--border);
    border-radius: var(--radius);
    padding:       .75rem 1rem;
    margin-top:    .5rem;
    display:       none;
    flex-direction: column;
    gap:           .5rem;
}
.pwd-generator.visible { display: flex; }
.pwd-generated-value {
    font-family: 'Courier New', monospace;
    font-size:   1rem;
    font-weight: 700;
    letter-spacing: .5px;
    color:       var(--primary);
    word-break:  break-all;
    padding:     .5rem;
    background:  #fff;
    border:      1px solid var(--border);
    border-radius: 4px;
}

/* Toggle switch */
.toggle-wrap  { display: flex; align-items: center; gap: .5rem; }
.toggle-input { display: none; }
.toggle-label {
    position:  relative;
    display:   inline-block;
    width:     44px;
    height:    24px;
    cursor:    pointer;
}
.toggle-label::before {
    content:     '';
    position:    absolute;
    inset:       0;
    background:  #ccc;
    border-radius: 12px;
    transition:  background .2s;
}
.toggle-label::after {
    content:     '';
    position:    absolute;
    top:         3px; left: 3px;
    width:       18px; height: 18px;
    background:  #fff;
    border-radius: 50%;
    transition:  left .2s;
    box-shadow:  0 1px 3px rgba(0,0,0,.2);
}
.toggle-input:checked + .toggle-label::before { background: var(--accent); }
.toggle-input:checked + .toggle-label::after  { left: 23px; }

/* Checkbox & radio */
.form-check { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.form-check-input {
    width: 16px; height: 16px; cursor: pointer;
    accent-color: var(--primary);
}
.form-check-label { font-size: .875rem; cursor: pointer; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
    padding:       .75rem 1rem;
    border-radius: var(--radius);
    border:        1px solid transparent;
    font-size:     .875rem;
    margin-bottom: 1rem;
    display:       flex;
    align-items:   flex-start;
    gap:           .5rem;
}
.alert-success { background: #d1e7dd; border-color: #a3cfbb; color: #0a3622; }
.alert-error   { background: #f8d7da; border-color: #f1aeb5; color: #58151c; }
.alert-warning { background: #fff3cd; border-color: #ffe69c; color: #664d03; }
.alert-info    { background: #cff4fc; border-color: #9eeaf9; color: #055160; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.table-wrap   { overflow-x: auto; }
.table {
    width:         100%;
    border-collapse: collapse;
    font-size:     .875rem;
}
.table th {
    padding:       .6rem .9rem;
    border-bottom: 2px solid var(--border);
    text-align:    left;
    font-weight:   600;
    color:         var(--text-muted);
    text-transform: uppercase;
    font-size:     .75rem;
    letter-spacing: .5px;
    white-space:   nowrap;
}
.table td {
    padding:       .7rem .9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8f9fa; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display:       inline-block;
    padding:       .2rem .55rem;
    font-size:     .72rem;
    font-weight:   700;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.badge-primary  { background: var(--primary); color: #fff; }
.badge-accent   { background: var(--accent);  color: #fff; }
.badge-success  { background: #d1e7dd; color: #0a3622; }
.badge-danger   { background: #f8d7da; color: #58151c; }
.badge-warning  { background: #fff3cd; color: #664d03; }
.badge-muted    { background: var(--border); color: var(--text-muted); }

/* ── Avatars ───────────────────────────────────────────────────────────────── */
.avatar-sm {
    width:         32px;
    height:        32px;
    border-radius: 50%;
    object-fit:    cover;
    flex-shrink:   0;
}

.avatar-md {
    width:         64px;
    height:        64px;
    border-radius: 50%;
    object-fit:    cover;
}

.avatar-lg {
    width:         96px;
    height:        96px;
    border-radius: 50%;
    object-fit:    cover;
}

.avatar-initials {
    display:        inline-flex;
    align-items:    center;
    justify-content: center;
    border-radius:  50%;
    background:     var(--accent);
    color:          #fff;
    font-weight:    700;
    font-size:      .85em;
    flex-shrink:    0;
}
.avatar-sm.avatar-initials { width: 32px; height: 32px; }
.avatar-md.avatar-initials { width: 64px; height: 64px; font-size: 1.4rem; }
.avatar-lg.avatar-initials { width: 96px; height: 96px; font-size: 2rem; }

/* ── Utility ───────────────────────────────────────────────────────────────── */
.text-muted    { color: var(--text-muted); }
.text-center   { text-align: center; }
.text-right    { text-align: right; }
.text-danger   { color: var(--danger); }
.text-success  { color: var(--success); }
.text-sm       { font-size: .8rem; }

.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }

.d-flex        { display: flex; }
.align-center  { align-items: center; }
.gap-1         { gap: .25rem; }
.gap-2         { gap: .5rem; }
.gap-3         { gap: 1rem; }
.flex-wrap     { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }

.w-100 { width: 100%; }
.py-5  { padding-top: 3rem; padding-bottom: 3rem; }

/* ── Login page ────────────────────────────────────────────────────────────── */
body.page-login {
    background:    var(--bg);
    display:       flex;
    align-items:   center;
    justify-content: center;
    min-height:    100vh;
    padding:       1rem;
}

.login-card {
    width:         100%;
    max-width:     420px;
    background:    #fff;
    border-radius: var(--radius);
    box-shadow:    0 4px 24px rgba(0,0,0,.12);
    padding:       2.5rem 2rem;
}

.login-brand {
    text-align:    center;
    margin-bottom: 2rem;
}
.login-brand img   { height: 56px; margin: 0 auto .75rem; }
.login-brand h1    { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.login-brand p     { color: var(--text-muted); font-size: .85rem; margin-top: .25rem; }

.login-divider     { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ── Module placeholder pages ──────────────────────────────────────────────── */
.module-placeholder {
    display:       flex;
    flex-direction: column;
    align-items:   center;
    justify-content: center;
    text-align:    center;
    padding:       5rem 2rem;
    gap:           1rem;
}
.module-placeholder .placeholder-icon { font-size: 4rem; }
.module-placeholder h2 { font-size: 1.4rem; color: var(--primary); }
.module-placeholder p  { color: var(--text-muted); max-width: 400px; }

/* ── Dashboard ─────────────────────────────────────────────────────────────── */
.welcome-banner {
    background:    linear-gradient(135deg, var(--primary) 0%, #2a4f7c 100%);
    color:         #fff;
    border-radius: var(--radius);
    padding:       1.5rem 2rem;
    margin-bottom: 1.5rem;
}
.welcome-banner h2 { font-size: 1.3rem; margin-bottom: .25rem; }
.welcome-banner p  { opacity: .8; font-size: .9rem; }

/* Recent activity list */
.activity-list { list-style: none; }
.activity-item {
    display:       flex;
    gap:           .75rem;
    padding:       .6rem 0;
    border-bottom: 1px solid var(--border);
    font-size:     .85rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-time { color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }

/* ── Admin page – Users table badges ───────────────────────────────────────── */
.status-active    { background: #d1e7dd; color: #0a3622; }
.status-inactive  { background: var(--border); color: var(--text-muted); }
.status-suspended { background: #f8d7da; color: #58151c; }

/* ── Profile page – avatar preview ─────────────────────────────────────────── */
.avatar-preview-wrap {
    display:       flex;
    align-items:   center;
    gap:           1.25rem;
    margin-bottom: 1rem;
}
.avatar-preview-wrap .avatar-lg { cursor: pointer; }
.avatar-change-hint { font-size: .8rem; color: var(--text-muted); }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
    .sidebar-toggle { display: flex; }
    .d-none-mobile  { display: none; }

    .sidebar {
        transform: translateX(-100%);
        z-index:   160;
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-overlay.visible { display: block; }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }

    .grid-2 { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: 1fr; }

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

@media (max-width: 480px) {
    .login-card { padding: 1.75rem 1.25rem; }
    .main-content { padding: .75rem; }
}
