/*
 * Cedrus GenAut - Shared Styles
 * Charte : bleu marine Cedrus & Partners (#032859), fonds clairs, cartes blanches.
 */

/* ============================================================================
   TOKENS
   ============================================================================ */

:root {
    --navy: #032859;
    --navy-700: #0a3a78;
    --navy-050: #eef2f8;
    --navy-100: #dce4f0;

    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-muted: #f8f9fb;
    --border: #e2e6ec;
    --border-strong: #cdd4de;

    --text: #172033;
    --text-muted: #5d6a7e;
    --text-faint: #8b96a8;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 8px 24px rgba(16, 24, 40, 0.06);
    --focus-ring: 0 0 0 3px rgba(3, 40, 89, 0.18);

    /* Statuts */
    --st-pending: #9aa4b2;
    --st-running: #2f6fd0;
    --st-success: #1f8a5b;
    --st-warning: #c98a0b;
    --st-error: #c93b3b;

    --success-soft: #eaf6f0;
    --warning-soft: #fdf5e4;
    --error-soft: #fcefef;
    --info-soft: #edf3fc;

    /* Compatibilité avec les anciennes variables */
    --cedrus-primary: var(--navy);
    --cedrus-secondary: var(--navy-700);
    --cedrus-dark: var(--navy);
    --cedrus-light: var(--navy-050);
    --cedrus-lighter: var(--surface-muted);
    --cedrus-text: var(--text);
    --cedrus-border: var(--border);
}

/* ============================================================================
   BASE
   ============================================================================ */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--navy);
}

h1, h2, h3, h4 {
    color: var(--navy);
    line-height: 1.25;
}

small {
    color: var(--text-faint);
    font-size: 0.82em;
}

[hidden] {
    display: none !important;
}

/* ============================================================================
   TOP BAR
   ============================================================================ */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 28px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    flex-shrink: 0;
}

.brand img {
    height: 34px;
    width: auto;
    display: block;
}

.brand-app {
    padding-left: 14px;
    border-left: 1px solid var(--border-strong);
    color: var(--text-muted);
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.nav {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav a {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.93em;
    transition: background 0.15s, color 0.15s;
}

.nav a:hover {
    background: var(--navy-050);
    color: var(--navy);
}

.nav a.active {
    color: var(--navy);
    background: var(--navy-050);
}

/* ============================================================================
   PAGE LAYOUT
   ============================================================================ */

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 24px 56px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.65em;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.page-header p {
    color: var(--text-muted);
    margin-top: 4px;
}

.page-narrow {
    max-width: 880px;
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: 24px;
    align-items: start;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ============================================================================
   CARDS
   ============================================================================ */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 1.02em;
    font-weight: 600;
}

.card-header p {
    color: var(--text-muted);
    font-size: 0.88em;
    margin-top: 2px;
}

.card-body {
    padding: 22px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state img {
    width: 56px;
    opacity: 0.18;
    margin-bottom: 12px;
}

/* ============================================================================
   FORMS
   ============================================================================ */

.form-group {
    margin-bottom: 18px;
    text-align: left;
}

.form-group label,
.label-row label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.88em;
    color: var(--text);
}

.label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.label-row label {
    margin-bottom: 0;
}

.form-group input,
.form-group select {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:hover,
.form-group select:hover {
    border-color: var(--text-faint);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--navy);
    box-shadow: var(--focus-ring);
}

.form-group input:disabled {
    background: var(--surface-muted);
    color: var(--text-muted);
}

.form-group small {
    display: block;
    margin-top: 5px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.date-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Choix de la tâche : boutons segmentés (radios) */
.segmented {
    display: flex;
    padding: 4px;
    gap: 4px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.segmented label {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    cursor: pointer;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9em;
    text-align: center;
    line-height: 1.3;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.segmented label:hover span {
    color: var(--navy);
}

.segmented input:checked + span {
    background: var(--navy);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.segmented input:focus-visible + span {
    box-shadow: var(--focus-ring);
}

.task-hint {
    margin: 10px 0 20px;
    color: var(--text-muted);
    font-size: 0.86em;
}

.form-cols-3 {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
}

.form-cols-3 .form-group {
    margin-bottom: 0;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}

.form-actions .btn {
    min-width: 140px;
}

.hint {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--navy-050);
    color: var(--navy);
    font-size: 0.86em;
}

.endpoint-description {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--navy-050);
    color: var(--navy);
    font-size: 0.86em;
}

.client-info {
    display: none;
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    border: 1px solid var(--border);
    font-size: 0.86em;
    color: var(--text-muted);
}

.client-info dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 12px;
}

.client-info dt {
    color: var(--text-faint);
}

.client-info dd {
    color: var(--text);
    font-weight: 500;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 42px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    font-size: 0.93em;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--navy-700);
}

.btn-secondary {
    background: var(--surface);
    color: var(--navy);
    border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--navy-050);
    border-color: var(--navy-100);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--navy-050);
    color: var(--navy);
}

.btn-danger {
    background: var(--surface);
    color: var(--st-error);
    border-color: #efc9c9;
}

.btn-danger:hover:not(:disabled) {
    background: var(--error-soft);
}

.btn-sm,
.action-btn {
    height: 32px;
    padding: 0 12px;
    font-size: 0.84em;
}

.btn-block {
    width: 100%;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

/* Bouton avec indicateur de chargement */
.btn .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================================
   TABLES
   ============================================================================ */

.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.table th,
.table td {
    padding: 11px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table th {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.table tbody tr:hover {
    background: var(--surface-muted);
}

.table tr.clickable {
    cursor: pointer;
}

.table tr.selected {
    background: var(--navy-050);
}

.table .muted {
    color: var(--text-faint);
}

.table .actions {
    text-align: right;
}

.table .actions .btn + .btn {
    margin-left: 6px;
}

/* ============================================================================
   BADGES / STATUS
   ============================================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78em;
    font-weight: 600;
    white-space: nowrap;
    background: #eef0f3;
    color: var(--text-muted);
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge.running,
.badge.queued { background: var(--info-soft); color: var(--st-running); }
.badge.success { background: var(--success-soft); color: var(--st-success); }
.badge.partial,
.badge.stale { background: var(--warning-soft); color: var(--st-warning); }
.badge.failed { background: var(--error-soft); color: var(--st-error); }
.badge.running::before { animation: pulse 1.2s ease-in-out infinite; }

.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: var(--navy-050);
    color: var(--navy);
    font-size: 0.82em;
    font-weight: 500;
}

/* Messages ponctuels (formulaires) */
.status {
    display: none;
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-size: 0.9em;
    white-space: pre-line;
}

.status.success { background: var(--success-soft); color: #165c3d; border-color: #c4e5d4; }
.status.error { background: var(--error-soft); color: #8a2626; border-color: #f0caca; }
.status.loading { background: var(--info-soft); color: #1d4f9c; border-color: #cbdcf5; }

/* ============================================================================
   SUIVI DES TRAITEMENTS
   ============================================================================ */

.job-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.job-title {
    font-weight: 600;
    font-size: 1.02em;
    color: var(--navy);
}

.job-sub {
    color: var(--text-muted);
    font-size: 0.86em;
    margin-top: 2px;
}

.progress {
    height: 8px;
    background: #e9edf2;
    border-radius: 999px;
    overflow: hidden;
    margin: 18px 0 10px;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--navy);
    border-radius: 999px;
    transition: width 0.6s ease;
}

.progress-bar.running {
    background-color: var(--navy);
    background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.18) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.18) 50%, rgba(255, 255, 255, 0.18) 75%, transparent 75%);
    background-size: 18px 18px;
    animation: stripes 1s linear infinite;
}

.progress-bar.success { background: var(--st-success); }
.progress-bar.partial { background: var(--st-warning); }
.progress-bar.failed { background: var(--st-error); }

@keyframes stripes {
    from { background-position: 18px 0; }
    to { background-position: 0 0; }
}

.job-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    color: var(--text-muted);
    font-size: 0.86em;
}

.job-meta strong {
    color: var(--text);
}

.job-meta .meta-error { color: var(--st-error); }
.job-meta .meta-warning { color: var(--st-warning); }

.job-alert {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid #f0caca;
    background: var(--error-soft);
    color: #8a2626;
    font-size: 0.9em;
    white-space: pre-line;
}

.job-alert.warn { border-color: #f1dfb4; background: var(--warning-soft); color: #7a5306; }
.job-alert.ok { border-color: #c4e5d4; background: var(--success-soft); color: #165c3d; }

.job-alert summary,
.step-error summary {
    cursor: pointer;
    margin-top: 6px;
    font-weight: 600;
}

.job-alert pre,
.step-error pre {
    margin-top: 6px;
    padding: 10px;
    max-height: 260px;
    overflow: auto;
    white-space: pre-wrap;
    font-family: Consolas, "SFMono-Regular", Menlo, monospace;
    font-size: 0.8em;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* Liste des étapes en frise verticale */
.steps {
    list-style: none;
    margin-top: 18px;
}

.steps li {
    position: relative;
    display: grid;
    grid-template-columns: 18px 1fr auto;
    gap: 4px 12px;
    align-items: baseline;
    padding: 7px 0;
}

.steps li::before {
    content: "";
    position: absolute;
    left: 8px;
    top: 22px;
    bottom: -8px;
    width: 2px;
    background: var(--border);
}

.steps li:last-child::before {
    display: none;
}

.steps li.success::before,
.steps li.warning::before { background: #cfe7da; }

.dot {
    position: relative;
    z-index: 1;
    width: 12px;
    height: 12px;
    margin: 0 3px;
    align-self: center;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--st-pending);
}

.steps li.running .dot { border-color: var(--st-running); background: var(--st-running); box-shadow: 0 0 0 4px rgba(47, 111, 208, 0.15); animation: pulse 1.2s ease-in-out infinite; }
.steps li.success .dot { border-color: var(--st-success); background: var(--st-success); }
.steps li.warning .dot { border-color: var(--st-warning); background: var(--st-warning); }
.steps li.error .dot { border-color: var(--st-error); background: var(--st-error); }
.steps li.skipped .dot { border-style: dashed; }

.step-label { font-size: 0.92em; }
.steps li.pending .step-label,
.steps li.skipped .step-label { color: var(--text-faint); }
.steps li.running .step-label { font-weight: 600; color: var(--navy); }

.step-right {
    color: var(--text-faint);
    font-size: 0.8em;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.steps li.error .step-right { color: var(--st-error); }
.steps li.warning .step-right { color: var(--st-warning); }

.step-detail {
    grid-column: 2 / 4;
    color: var(--text-muted);
    font-size: 0.82em;
}

.step-error {
    grid-column: 2 / 4;
    color: #8a2626;
    font-size: 0.84em;
}

.step-error.warning { color: #7a5306; }

@keyframes pulse {
    50% { opacity: 0.4; }
}

.job-logs {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.job-logs summary {
    cursor: pointer;
    color: var(--navy);
    font-weight: 600;
    font-size: 0.9em;
}

.job-logs pre {
    margin-top: 10px;
    max-height: 340px;
    overflow: auto;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: #0f1b2d;
    color: #d3dbe7;
    font-family: Consolas, "SFMono-Regular", Menlo, monospace;
    font-size: 0.76em;
    line-height: 1.5;
    white-space: pre-wrap;
}

.log-WARNING { color: #f3c969; }
.log-ERROR,
.log-CRITICAL { color: #ff9a92; }

.job-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

/* ============================================================================
   LOGIN
   ============================================================================ */

.login-page {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    min-height: 100vh;
}

.login-aside {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 48px;
    background: var(--navy);
    color: #fff;
}

.login-aside::after {
    content: "&";
    position: absolute;
    right: -6%;
    top: -12%;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 46vw;
    line-height: 1;
    color: rgba(255, 255, 255, 0.05);
    pointer-events: none;
}

.login-aside h2 {
    position: relative;
    z-index: 1;
    color: #fff;
    font-size: 1.9em;
    font-weight: 600;
    max-width: 420px;
}

.login-aside p {
    position: relative;
    z-index: 1;
    margin-top: 10px;
    max-width: 420px;
    color: rgba(255, 255, 255, 0.72);
}

.login-main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    background: var(--surface);
}

.login-container {
    width: 100%;
    max-width: 360px;
}

.login-container .login-logo {
    height: 52px;
    width: auto;
    margin-bottom: 36px;
}

.login-container h1 {
    font-size: 1.45em;
    font-weight: 600;
}

.login-container .subtitle {
    color: var(--text-muted);
    margin: 4px 0 26px;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 960px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .login-page {
        grid-template-columns: 1fr;
    }

    .login-aside {
        display: none;
    }

    .brand-app {
        display: none;
    }
}

@media (max-width: 600px) {
    .topbar-inner {
        padding: 10px 16px;
        gap: 12px;
    }

    .brand img {
        height: 26px;
    }

    .nav a {
        padding: 6px 8px;
    }

    .page {
        padding: 22px 16px 40px;
    }

    .card-header,
    .card-body {
        padding: 16px;
    }

    .form-row,
    .date-group,
    .form-cols-3 {
        grid-template-columns: 1fr;
    }

    .segmented {
        display: flex;
        flex-direction: column;
    }

    .button-group {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }
}
