/* KPI Cards Layout */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--card-shadow);
    transition: border-color var(--transition-speed);
}

.kpi-card:hover {
    border-color: var(--line-strong);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon i {
    width: 24px;
    height: 24px;
}

.kpi-icon.blue {
    background-color: var(--info-bg);
    color: var(--info);
}

.kpi-icon.emerald {
    background-color: var(--success-bg);
    color: var(--success);
}

.kpi-icon.violet {
    background-color: rgba(13, 148, 136, 0.08);
    color: #0d9488;
}

.kpi-icon.amber {
    background-color: var(--warning-bg);
    color: var(--warning);
}

.kpi-data {
    display: flex;
    flex-direction: column;
}

.kpi-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.kpi-value {
    font-size: 20px;
    font-weight: 700;
    margin-top: 4px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.kpi-subtext {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
}

.chart-card h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.chart-container {
    position: relative;
    height: 240px;
    width: 100%;
}

/* Tables and Panels */
.table-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.panel-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.panel-header p.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.text-link-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color var(--transition-speed);
}

.text-link-btn i {
    width: 14px;
    height: 14px;
}

.text-link-btn:hover {
    color: var(--primary-hover);
}

.table-container {
    overflow-x: auto;
    max-height: 500px;
}

.table-container.mini-table {
    max-height: 300px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

th {
    padding: 14px 20px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    /* Solid color: sticky headers must not let scrolled rows bleed through */
    background-color: var(--surface-2);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 1;
}

/* PPM plan: let category tables flow full-length on the page instead of
   trapping the lines inside nested 500px scroll areas */
#ppm-lines-container .table-container {
    max-height: none;
}

td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
    color: var(--text);
}

tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background-color: var(--surface-2);
}

.loading-cell {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px !important;
    font-style: italic;
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.review {
    background-color: var(--warn-weak);
    color: var(--warn);
}

.status-badge.clean {
    background-color: var(--ok-weak);
    color: var(--ok);
}

.status-badge.avenant {
    background-color: var(--info-weak);
    color: var(--info);
}

.status-badge.contract {
    background-color: var(--info-weak);
    color: var(--info);
}

.status-badge.late {
    background-color: var(--danger-weak);
    color: var(--danger);
}

/* Filter Bar styles */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.search-box {
    position: relative;
    flex-grow: 1;
    max-width: 480px;
}

.search-box i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 18px;
    height: 18px;
}

.search-box input {
    width: 100%;
    padding: 12px 16px 12px 48px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: all var(--transition-speed);
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.filters-container {
    display: flex;
    gap: 12px;
}

select {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    padding: 12px 16px;
    font-size: 13px;
    outline: none;
    cursor: pointer;
    min-width: 160px;
}

/* D-11: tokens.css's `* { margin: 0 }` reset beats the UA sheet's
   `dialog:modal { margin: auto }` (author origin wins over UA origin,
   before specificity is even considered), so every bare <dialog> in this
   app -- #modal-institution, #modal-coi, and the create-contract dialog --
   renders flush against the top-left of the viewport instead of centred. */
dialog {
    margin: auto;
}

select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

option {
    background-color: var(--bg-elevated);
    color: var(--text);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-speed);
    border: 1px solid transparent;
}

/* Without this a disabled button was pixel-identical to an enabled one: it
   invited the click and then silently did nothing. */
.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:disabled:hover,
.btn[disabled]:hover {
    border-color: var(--line);
    box-shadow: none;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: none;
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--line);
}

.btn-secondary:hover {
    border-color: var(--line-strong);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.btn-icon:hover {
    border-color: var(--line-strong);
    color: var(--text-primary);
}

.width-100 {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 11px;
    border-radius: 6px;
}

/* UI-01/UI-02 focusable controls: a visible indicator in both themes. */
#besoins :focus-visible,
#decision-modal :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* #decision-modal has no CSS class of its own beyond the generic
   .modal-header/.modal-body rules -- it was previously shown only via an
   inline style="display:none" toggled from JS. This makes visibility
   class-driven (paired with .hidden) instead. */
#decision-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(5, 8, 15, 0.8);
}

/* Toast Notifications Container */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 9999;
}

.toast-notification {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 320px;
    max-width: 420px;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    pointer-events: auto;
}

.toast-notification.visible {
    transform: translateY(0);
    opacity: 1;
}

.toast-notification.info i { color: var(--info); }
.toast-notification.success i { color: var(--success); }
.toast-notification.warning i { color: var(--warning); }
.toast-notification.danger i { color: var(--danger); }

.toast-body {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Loading animations */
.loading-text {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.loading-text::after {
    content: "...";
    animation: dots 1.5s steps(5, end) infinite;
    width: 12px;
    text-align: left;
}

@keyframes dots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}


/* The neutral counterpart to .form-hint, which is deliberately loud
   because it carries a derogation notice. An explainer is not a warning. */
.field-hint {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
}
