/* Koguru - styles de l'application (par-dessus Bootstrap 5.3) */

:root {
    --bs-body-font-family: 'Noto Sans Variable', 'Noto Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --kg-header-h: 3.5rem;
    --kg-gap: 0.75rem;
    --kg-primary: #1b4f8a;
}

.btn-primary {
    --bs-btn-bg: var(--kg-primary);
    --bs-btn-border-color: var(--kg-primary);
    --bs-btn-hover-bg: #153e6e;
    --bs-btn-hover-border-color: #153e6e;
    --bs-btn-active-bg: #123560;
    --bs-btn-active-border-color: #123560;
    --bs-btn-disabled-bg: var(--kg-primary);
    --bs-btn-disabled-border-color: var(--kg-primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--kg-primary);
    --bs-btn-border-color: var(--kg-primary);
    --bs-btn-hover-bg: var(--kg-primary);
    --bs-btn-hover-border-color: var(--kg-primary);
    --bs-btn-active-bg: var(--kg-primary);
    --bs-btn-active-border-color: var(--kg-primary);
}

body {
    background: #f4f6f9;
    min-height: 100dvh;
}

.kg-navbar {
    height: var(--kg-header-h);
    padding-top: 0;
    padding-bottom: 0;
}

/* --- Pages centrées (connexion, erreurs) --- */
.kg-login {
    min-height: 100dvh;
}
.kg-login-card {
    width: 100%;
    max-width: 28rem;
}

/* --- Espace de travail : liste à gauche, matrice carrée à droite --- */
.kg-workspace {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    height: calc(100dvh - var(--kg-header-h));
}

.kg-sidebar {
    flex: 0 0 20rem;
    max-width: 30%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.kg-sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.kg-matrix-area {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    container-type: size;
}

/* Matrice carrée : côté = plus petite des deux dimensions disponibles dans la zone. */
.kg-matrix {
    width: min(100cqw, 100cqh);
    height: min(100cqw, 100cqh);
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: var(--kg-gap);
}

.kg-quadrant {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--kg-q-border);
    border-radius: 0.75rem;
    background: var(--kg-q-bg);
    overflow: hidden;
}
.kg-quadrant-title {
    margin: 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--kg-q-title);
    border-bottom: 1px solid var(--kg-q-border);
}
.kg-dropzone {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.kg-empty {
    margin: auto;
    font-size: 0.85rem;
    color: var(--kg-q-title);
    opacity: 0.55;
    text-align: center;
}
.kg-dropzone:not(:empty) > .kg-empty:not(:only-child),
.kg-sidebar-body:not(:empty) > .kg-empty:not(:only-child) {
    display: none;
}

/* Positions : haut-gauche = important+urgent, haut-droite = important, bas-gauche = urgent, bas-droite = ni l'un ni l'autre */
.kg-q1 { --kg-q-bg: #fdecea; --kg-q-border: #f2b8b2; --kg-q-title: #9c2a20; }
.kg-q2 { --kg-q-bg: #e8f1fc; --kg-q-border: #aecbf0; --kg-q-title: #1b4f8a; }
.kg-q3 { --kg-q-bg: #fff4dc; --kg-q-border: #efd08a; --kg-q-title: #7f5400; }
.kg-q4 { --kg-q-bg: #eef0f3; --kg-q-border: #cdd3db; --kg-q-title: #465160; }

/* --- Petit écran : les quatre cadrans deviennent quatre blocs superposés --- */
@media (max-width: 767.98px) {
    .kg-workspace {
        flex-direction: column;
        height: auto;
        padding: 0.75rem;
    }
    .kg-sidebar {
        flex: none;
        max-width: none;
        max-height: 40dvh;
    }
    .kg-matrix-area {
        display: block;
        container-type: normal;
    }
    .kg-matrix {
        width: auto;
        height: auto;
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-auto-rows: minmax(9rem, auto);
    }
    .kg-dropzone {
        overflow-y: visible;
    }
}

/* Respect des préférences de mouvement réduit */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* =========================================================================
   Rectangles (éléments)
   ========================================================================= */

/* Le texte « vide » ne doit jamais intercepter un dépôt : on dépose sur la zone elle-même. */
.kg-empty {
    pointer-events: none;
}

.kg-item {
    --kg-item-bg: #ffffff;
    --kg-item-fg: #212529;
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.45rem 0.5rem;
    background: var(--kg-item-bg);
    color: var(--kg-item-fg);
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 0.55rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
.kg-item:focus {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
}
.kg-item.is-overdue {
    border-color: #dc3545;
    box-shadow: inset 4px 0 0 #dc3545, 0 1px 2px rgba(0, 0, 0, 0.08);
}
.kg-item.is-unavailable {
    opacity: 0.7;
    font-style: italic;
}
.kg-item.is-busy {
    opacity: 0.6;
    pointer-events: none;
}
.kg-item.is-new {
    animation: kg-new 1.4s ease-out;
}
@keyframes kg-new {
    0% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0.7); }
    60% { box-shadow: 0 0 0 10px rgba(13, 110, 253, 0); }
    100% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0); }
}

.kg-item-kind {
    flex: none;
    margin-top: 0.12rem;
    opacity: 0.8;
}
.kg-item-main {
    flex: 1;
    min-width: 0;
}
.kg-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.kg-item-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem 0.5rem;
    margin-top: 0.15rem;
    font-size: 0.75rem;
}
.kg-item-date {
    white-space: nowrap;
    font-weight: 600;
}
.kg-item-sub {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.85;
}
.kg-item-shift {
    display: inline-flex;
    gap: 0.2rem;
}

/* Petits boutons ronds (coche, −1, +1) : tous de la même taille. Ils héritent la couleur du texte, donc restent lisibles sur n'importe quel fond. */
.kg-mini {
    --kg-btn: 1.8rem;
    flex: none;
    display: grid;
    place-items: center;
    width: var(--kg-btn);
    height: var(--kg-btn);
    padding: 0;
    border: 1px solid currentColor;
    background: transparent;
    color: inherit;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
    opacity: 0.75;
    cursor: pointer;
}
.kg-mini:hover {
    opacity: 1;
    background: rgba(127, 127, 127, 0.22);
}
.kg-complete {
    align-self: center;
    font-size: 1rem;
}
.kg-complete:hover {
    background: #198754;
    border-color: #198754;
    color: #fff;
}
@media (pointer: coarse) {
    .kg-mini { --kg-btn: 2.4rem; font-size: 0.8rem; }
    .kg-complete { font-size: 1.1rem; }
}

/* Glisser-déposer (SortableJS) */
.kg-ghost { opacity: 0.35; }
.kg-chosen { cursor: grabbing; }
.kg-drag { box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.25); }

/* Copie qui « glisse » d'un cadran à l'autre (déplacement au clavier) */
.kg-flying {
    position: fixed;
    margin: 0;
    z-index: 2500;
    pointer-events: none;
    box-sizing: border-box;
    box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.3);
}

/* =========================================================================
   Effet de récompense à la complétion
   ========================================================================= */
.kg-fx {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 3000;
}
.kg-ripple {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    will-change: transform, opacity;
}
.kg-ripple-green {
    border: 5px solid rgba(25, 135, 84, 0.8);
    background: radial-gradient(circle, rgba(25, 135, 84, 0.2) 0%, rgba(25, 135, 84, 0) 70%);
    box-shadow: 0 0 18px rgba(25, 135, 84, 0.55), inset 0 0 18px rgba(25, 135, 84, 0.35);
}
.kg-ripple-rainbow {
    background: conic-gradient(#ff3b30, #ff9500, #ffcc00, #34c759, #00c7be, #007aff, #af52de, #ff2d55, #ff3b30);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
}

/* =========================================================================
   Sélecteur de cadran (4 boutons en carré)
   ========================================================================= */
.kg-picker-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    max-width: 22rem;
}
.kg-picker-btn {
    border: 2px solid var(--kg-q-border);
    background: var(--kg-q-bg);
    color: var(--kg-q-title);
    border-radius: 0.6rem;
    padding: 0.6rem 0.5rem;
    min-height: 4rem;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.2;
}
.kg-picker-btn:hover {
    filter: brightness(0.97);
}
.kg-picker-btn:focus-visible {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
}
.kg-picker-btn.is-selected {
    border-color: var(--kg-q-title);
    box-shadow: inset 0 0 0 1px var(--kg-q-title);
}
.kg-picker-btn.is-selected::before {
    content: '✓ ';
}
.kg-picker-none {
    --kg-q-bg: #fff;
    --kg-q-border: #ced4da;
    --kg-q-title: #495057;
    display: block;
    width: 100%;
    max-width: 22rem;
    margin-top: 0.5rem;
    min-height: 2.5rem;
}

/* =========================================================================
   Fenêtres modales et divers
   ========================================================================= */
.min-w-0 { min-width: 0; }

.kg-fields {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
    margin-bottom: 1rem;
}
.kg-fields dt,
.kg-fields-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
}
.kg-fields dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.kg-due-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.kg-due-value {
    font-weight: 600;
}
.kg-body {
    margin: 0;
    padding: 0.75rem;
    max-height: 40vh;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 0.92rem;
    background: var(--bs-tertiary-bg);
    border-radius: 0.5rem;
}
.kg-body:empty { display: none; }
.kg-body.is-empty {
    color: var(--bs-secondary-color);
    font-style: italic;
}

.is-spinning .bi {
    animation: kg-spin 1s linear infinite;
}
@keyframes kg-spin {
    to { transform: rotate(360deg); }
}

/* --- Page Paramètres : ordre des cadrans --- */
.kg-settings { max-width: 56rem; }
.kg-w-8 { max-width: 8rem; }
.kg-w-16 { max-width: 16rem; }
.kg-slots {
    display: grid;
    gap: 0.5rem;
    padding: 0.5rem;
    border: 1px dashed #c3cbd6;
    border-radius: 0.75rem;
    background: #fff;
}
.kg-slots-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    width: min(100%, 22rem);
    aspect-ratio: 1;
}
.kg-slots-list {
    grid-template-columns: 1fr;
    width: min(100%, 16rem);
}
.kg-slot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    min-height: 3.4rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--kg-q-border);
    border-radius: 0.65rem;
    background: var(--kg-q-bg);
    color: var(--kg-q-title);
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: anywhere;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
.kg-slot:focus-visible {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
}
.kg-slot-pos {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: var(--kg-q-title);
    color: #fff;
    font-size: 0.75rem;
}
.kg-slot-grip { opacity: 0.5; }
.kg-slot-target { outline: 2px dashed var(--kg-primary); outline-offset: 2px; }
