/* =====================================================================
   Kifaru Logistique Portal — Shared Stylesheet
   Phase 0.4 — Base Layout & UI Components
   Brand palette: blue #1A6CB7 / black / grey / white
   ===================================================================== */

:root {
    --kifaru-blue:        #1A6CB7;
    --kifaru-blue-dark:   #145087;
    --kifaru-blue-light:  #e8f1f9;
    --kifaru-black:       #0c1014;
    --kifaru-grey:        #B8BCC0;
    --kifaru-grey-light:  #f3f4f6;
    --kifaru-grey-mid:    #6b7280;
    --kifaru-white:       #ffffff;
    --shadow-card:        0 4px 20px rgba(0, 0, 0, 0.06);
    --shadow-elevate:     0 6px 28px rgba(0, 0, 0, 0.10);
    --radius:             10px;
    --topbar-h:           64px;
    --sidebar-w:          240px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;   /* defensive: never allow horizontal page scroll */
    width: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--kifaru-grey-light);
    color: var(--kifaru-black);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Allow flex children to shrink below their intrinsic content width */
.topbar > *,
.topbar-user > * {
    min-width: 0;
}

a { color: var(--kifaru-blue); }

/* =====================================================================
   AUTH SHELL — login.php, setup.php, lockout pages
   ===================================================================== */
.auth-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}
.auth-card {
    background: var(--kifaru-white);
    width: 100%;
    max-width: 420px;
    padding: 40px 36px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    border-top: 4px solid var(--kifaru-blue);
}
.auth-logo {
    display: block;
    max-width: 180px;
    height: auto;
    margin: 0 auto 24px;
}
.auth-card h1 {
    text-align: center;
    color: var(--kifaru-blue);
    margin: 0 0 8px;
    font-size: 22px;
    letter-spacing: 0.3px;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--kifaru-grey-mid);
    font-size: 13px;
    margin: 0 0 28px;
}
.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 11px;
    color: var(--kifaru-grey-mid);
    letter-spacing: 1px;
    text-transform: uppercase;
}

@media (max-width: 480px) {
    .auth-card { padding: 32px 22px; }
}

/* =====================================================================
   PORTAL LAYOUT — sidebar + topbar + content
   ===================================================================== */
.portal-layout {
    display: grid;
    grid-template-areas:
        "topbar  topbar"
        "sidebar content";
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    min-height: 100vh;
}

/* ----- Topbar ----- */
.topbar {
    grid-area: topbar;
    background: var(--kifaru-white);
    border-bottom: 1px solid #e5e7eb;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: var(--topbar-h);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-toggle {
    display: none;
    background: transparent;
    border: 0;
    width: 40px;
    height: 40px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 0;
    border-radius: 8px;
}
.topbar-toggle:hover { background: var(--kifaru-grey-light); }
.topbar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--kifaru-black);
    border-radius: 2px;
}
.topbar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
}
.topbar-brand img {
    height: 36px;
    width: auto;
    display: block;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.topbar-user .user-name {
    color: var(--kifaru-black);
    font-weight: 500;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ----- Sidebar ----- */
.sidebar {
    grid-area: sidebar;
    background: var(--kifaru-white);
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.sidebar-nav {
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--kifaru-black);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover {
    background: var(--kifaru-grey-light);
}
.sidebar-link.is-active {
    background: var(--kifaru-blue-light);
    color: var(--kifaru-blue-dark);
    font-weight: 600;
}
.sidebar-bullet {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--kifaru-grey);
    flex-shrink: 0;
    transition: background 0.15s;
}
.sidebar-link:hover .sidebar-bullet,
.sidebar-link.is-active .sidebar-bullet {
    background: var(--kifaru-blue);
}
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid #e5e7eb;
    text-align: center;
}
.sidebar-tagline {
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.2px;
    color: var(--kifaru-blue);
}
.sidebar-credit {
    margin: 4px 0 0;
    font-size: 10px;
    color: var(--kifaru-grey-mid);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.2s;
}
.sidebar-backdrop.is-open {
    display: block;
    opacity: 1;
}

/* ----- Content area ----- */
.content {
    grid-area: content;
    padding: 28px;
    overflow-x: hidden;
}

/* =====================================================================
   COMMON COMPONENTS
   ===================================================================== */

/* ----- Page header ----- */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.page-header h1 {
    margin: 0;
    font-size: 22px;
    color: var(--kifaru-black);
}
.breadcrumb {
    margin: 0 0 4px;
    font-size: 11px;
    color: var(--kifaru-grey-mid);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

/* ----- Cards / panels ----- */
.page-card {
    background: var(--kifaru-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 28px;
}
.page-card + .page-card { margin-top: 20px; }
.page-card h2 {
    margin: 0 0 16px;
    font-size: 17px;
    color: var(--kifaru-black);
}
.page-card h3 {
    margin: 24px 0 8px;
    font-size: 14px;
    color: var(--kifaru-black);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ----- Forms ----- */
.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--kifaru-black);
    margin-bottom: 6px;
}
.field input[type="email"],
.field input[type="password"],
.field input[type="text"],
.field input[type="tel"],
.field input[type="number"],
.field input[type="date"],
.field input[type="search"],
.field textarea,
.field select {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fafbfc;
    color: var(--kifaru-black);
    transition: border-color 0.15s, background 0.15s;
}
.field textarea { min-height: 100px; resize: vertical; }
.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--kifaru-blue);
    background: var(--kifaru-white);
}
.field .hint {
    font-size: 12px;
    color: var(--kifaru-grey-mid);
    margin-top: 4px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
.form-grid .field { margin: 0; }
.form-grid .field.full-width { grid-column: 1 / -1; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 16px;
    flex-wrap: wrap;
}

/* Checkbox rows and rights grid (admin forms) */
.rights-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--kifaru-grey-light);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s;
}
.checkbox-row:hover {
    background: var(--kifaru-blue-light);
}
.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--kifaru-blue);
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}
.checkbox-row input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}
.checkbox-row input[type="checkbox"]:disabled ~ span,
.checkbox-row input[type="checkbox"]:disabled ~ label {
    color: var(--kifaru-grey-mid);
}
@media (max-width: 600px) {
    .rights-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-actions { justify-content: stretch; }
    .form-actions .btn { flex: 1; }
}

/* ----- Buttons ----- */
.btn {
    display: inline-block;
    padding: 11px 22px;
    background: var(--kifaru-blue);
    color: var(--kifaru-white);
    border: 0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
    line-height: 1.2;
    text-align: center;
}
.btn:hover { background: var(--kifaru-blue-dark); }

.btn-block { display: block; width: 100%; }
.btn-sm    { padding: 7px 16px; font-size: 12px; }

.btn-ghost {
    background: transparent;
    color: var(--kifaru-blue);
    border: 1px solid var(--kifaru-blue);
}
.btn-ghost:hover {
    background: var(--kifaru-blue-light);
    color: var(--kifaru-blue-dark);
}
.btn-secondary {
    background: var(--kifaru-grey-light);
    color: var(--kifaru-black);
}
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger  { background: #dc2626; }
.btn-danger:hover  { background: #b91c1c; }
.btn-success { background: #16a34a; }
.btn-success:hover { background: #15803d; }

/* ----- Alerts ----- */
.alert {
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    border-left: 3px solid;
    line-height: 1.45;
}
.alert-error    { background: #fef2f2; color: #991b1b; border-color: #dc2626; }
.alert-success  { background: #f0fdf4; color: #166534; border-color: #16a34a; }
.alert-info     { background: var(--kifaru-blue-light); color: var(--kifaru-blue-dark); border-color: var(--kifaru-blue); }
.alert-warning  { background: #fffbeb; color: #92400e; border-color: #f59e0b; }

/* ----- Tables ----- */
.data-table-wrap {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--kifaru-white);
    min-width: 480px;
}
.data-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--kifaru-grey-mid);
    padding: 12px 14px;
    border-bottom: 2px solid #e5e7eb;
    background: #fafbfc;
    white-space: nowrap;
}
.data-table td {
    padding: 14px;
    font-size: 14px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: #fafbfc; }
.data-table .actions {
    text-align: right;
    white-space: nowrap;
}

/* ----- Status / priority badges ----- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.4;
    white-space: nowrap;
}
.role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--kifaru-blue-light);
    color: var(--kifaru-blue-dark);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    white-space: nowrap;
}

.status-active     { background: #d1fae5; color: #065f46; }
.status-inactive   { background: #f3f4f6; color: #6b7280; }
.status-open       { background: #dbeafe; color: #1e40af; }
.status-progress   { background: #fef3c7; color: #92400e; }
.status-resolved   { background: #d1fae5; color: #065f46; }
.status-closed     { background: #f3f4f6; color: #6b7280; }
.status-reopened   { background: #fee2e2; color: #991b1b; }
.priority-low      { background: #f3f4f6; color: #6b7280; }
.priority-medium   { background: #fef3c7; color: #92400e; }
.priority-high     { background: #fee2e2; color: #991b1b; }

/* ----- Stats grid ----- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--kifaru-white);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}
.stat-card .stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--kifaru-grey-mid);
    margin: 0;
}
.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--kifaru-blue);
    margin: 4px 0 0;
}
.stat-card.stat-link {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    border: 1px solid transparent;
}
.stat-card.stat-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevate);
    border-color: var(--kifaru-blue-light);
}

/* Quick-actions row (admin dashboard) */
.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

/* ----- Toolbar (search/filter row) ----- */
.toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.toolbar input[type="search"],
.toolbar select {
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background: var(--kifaru-white);
    font-family: inherit;
}
.toolbar input[type="search"] {
    flex: 1;
    min-width: 180px;
}
.toolbar-spacer { flex: 1; }

/* ----- Pagination ----- */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 6px;
    color: var(--kifaru-blue);
    text-decoration: none;
    min-width: 36px;
    text-align: center;
}
.pagination a:hover { background: var(--kifaru-blue-light); }
.pagination .current {
    background: var(--kifaru-blue);
    color: var(--kifaru-white);
    font-weight: 600;
}
.pagination .disabled {
    color: var(--kifaru-grey);
    cursor: not-allowed;
}

/* ----- Empty state ----- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--kifaru-grey-mid);
}
.empty-state h3 {
    color: var(--kifaru-black);
    margin: 0 0 8px;
    font-size: 16px;
    text-transform: none;
    letter-spacing: 0;
}
.empty-state p { margin: 0 0 8px; font-size: 14px; }
.empty-state .muted { font-size: 12px; }

/* ----- Modal (basic) ----- */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-backdrop.is-open {
    display: flex;
}
.modal {
    background: var(--kifaru-white);
    border-radius: var(--radius);
    padding: 28px;
    max-width: 500px;
    width: 100%;
    box-shadow: var(--shadow-elevate);
}
.modal h2 {
    margin: 0 0 12px;
    color: var(--kifaru-blue);
    font-size: 18px;
}
.modal-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ----- Right-list (stub: dashboard rights display) ----- */
.right-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
    font-size: 13px;
}
.right-list li {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}
.right-list li:last-child { border-bottom: 0; }
.tag-yes { color: #166534; font-weight: 600; }
.tag-no  { color: var(--kifaru-grey-mid); }

/* ----- Utility ----- */
.muted     { color: var(--kifaru-grey-mid); font-size: 13px; }
.divider   { border: none; border-top: 1px solid #e5e7eb; margin: 24px 0; }
.text-center { text-align: center; }
.text-right  { text-align: right; }

/* =====================================================================
   RESPONSIVE — sidebar drawer below 1024px
   ===================================================================== */
@media (max-width: 1023px) {
    .portal-layout {
        grid-template-areas:
            "topbar"
            "content";
        grid-template-columns: 1fr;
    }
    .topbar-toggle { display: flex; }
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 80vw;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 60;
        box-shadow: var(--shadow-elevate);
    }
    .sidebar.is-open {
        transform: translateX(0);
    }
}

@media (max-width: 767px) {
    /* Below tablet: hide role badge to save horizontal space in topbar */
    .topbar-user .role-badge { display: none; }
    .topbar { gap: 12px; }
}

@media (max-width: 600px) {
    .content { padding: 18px; }
    .page-card { padding: 20px; }
    .topbar { padding: 0 14px; }
    .topbar-user .user-name { display: none; }
    .topbar-brand img { height: 30px; }
    .page-header h1 { font-size: 19px; }
}

@media (max-width: 400px) {
    /* Tightest: small phones */
    .topbar { padding: 0 10px; gap: 8px; }
    .topbar-brand img { height: 26px; }
    .topbar-user .btn { padding: 7px 12px; font-size: 11px; }
    .topbar-toggle { width: 36px; height: 36px; }
    .content { padding: 14px; }
    .page-card { padding: 16px; }
}
