/* Ecran Design System — reusable components. Tokens only, no literal hex. */

/* --- Page header --- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); }
.page-header__title { font-size: var(--text-2xl); }
.page-header__subtitle { color: var(--text-muted); font-size: var(--text-sm); margin-top: 2px; }
.page-header__actions { display: flex; gap: var(--space-2); }

/* --- Card --- */
.card { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: var(--space-5); }
.card--link { transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
.card--link:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card__header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card__title { font-size: var(--text-lg); font-weight: 600; }
.card__subtitle { color: var(--text-muted); font-size: var(--text-sm); }
.card__actions { display: flex; gap: var(--space-2); }

/* --- KPI stat tile --- */
.kpi { position: relative; background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: var(--space-4) var(--space-5); overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent-primary); }
.kpi--green::before { background: var(--accent-green); }
.kpi--yellow::before { background: var(--accent-yellow); }
.kpi--blue::before { background: var(--accent-blue); }
.kpi--red::before { background: var(--accent-red); }
.kpi__label { font-size: var(--text-xs); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.kpi__value { font-family: var(--font-mono); font-size: var(--text-3xl); font-weight: 600; color: var(--text-primary); line-height: 1.2; margin-top: var(--space-2); }
.kpi__unit { font-size: var(--text-lg); color: var(--text-secondary); margin-left: 4px; }
.kpi__delta { font-size: var(--text-xs); font-weight: 500; margin-top: var(--space-1); }
.kpi__delta--up { color: var(--accent-green); }
.kpi__delta--down { color: var(--accent-red); }
.kpi__delta--flat { color: var(--text-muted); }

/* --- Buttons --- */
.btn { display: inline-flex; align-items: center; gap: var(--space-2); border: 1px solid transparent; border-radius: var(--radius-md); padding: 8px 16px; font-size: var(--text-sm); font-weight: 500; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--accent-primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-primary-hover); }
.btn--secondary { background: var(--bg-card); border-color: var(--border-medium); color: var(--text-primary); }
.btn--secondary:hover:not(:disabled) { background: var(--bg-secondary); }
.btn--ghost { background: transparent; color: var(--text-secondary); }
.btn--ghost:hover:not(:disabled) { background: var(--bg-secondary); color: var(--text-primary); }
.btn--success { background: var(--accent-green); color: #fff; }
.btn--success:hover:not(:disabled) { filter: brightness(.95); }
.btn--danger { background: var(--bg-card); border-color: var(--accent-red); color: var(--accent-red); }
.btn--danger:hover:not(:disabled) { background: var(--accent-red); color: #fff; }
.btn--sm { padding: 5px 12px; font-size: var(--text-xs); }
.btn--icon { padding: 8px; }
.btn .icon { width: 16px; height: 16px; }

/* --- Badges & pills --- */
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 500; padding: 2px 10px; border: 1px solid transparent; }
.badge--ontrack { background: color-mix(in srgb, var(--accent-green) 14%, var(--bg-card)); color: var(--accent-green); }
.badge--atrisk { background: color-mix(in srgb, var(--accent-yellow) 16%, var(--bg-card)); color: var(--accent-yellow); }
.badge--breached { background: color-mix(in srgb, var(--accent-red) 14%, var(--bg-card)); color: var(--accent-red); border-color: color-mix(in srgb, var(--accent-red) 30%, transparent); }

.risk { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: 500; color: var(--text-secondary); }
.risk::before { content: ""; width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--text-muted); }
.risk--low::before { background: var(--accent-green); }
.risk--med::before { background: var(--accent-yellow); }
.risk--high::before { background: var(--accent-red); }
.risk--critical::before { background: var(--accent-red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-red) 25%, transparent); }

.status-pill { display: inline-flex; align-items: center; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 500; padding: 2px 10px; }
.status-pill--green { background: color-mix(in srgb, var(--accent-green) 14%, var(--bg-card)); color: var(--accent-green); }
.status-pill--blue { background: color-mix(in srgb, var(--accent-blue) 14%, var(--bg-card)); color: var(--accent-blue); }
.status-pill--yellow { background: color-mix(in srgb, var(--accent-yellow) 16%, var(--bg-card)); color: var(--accent-yellow); }
.status-pill--red { background: color-mix(in srgb, var(--accent-red) 14%, var(--bg-card)); color: var(--accent-red); }
.status-pill--muted { background: var(--bg-secondary); color: var(--text-secondary); }

.role-badge { display: inline-flex; align-items: center; border-radius: var(--radius-full); font-size: var(--text-xs); padding: 2px 9px; background: var(--bg-secondary); color: var(--text-secondary); }

/* --- Data table --- */
.table-wrap { border: 1px solid var(--border-light); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); overflow-x: auto; background: var(--bg-card); }
.data-table { font-size: var(--text-sm); width: 100%; border-collapse: collapse; }
/* Cells don't wrap: the table expands to its natural width and the .table-wrap
   scrolls horizontally when it exceeds the container (instead of squishing). */
.data-table th, .data-table td { white-space: nowrap; }
/* Allow deliberately long text columns to wrap when marked. */
.data-table td.wrap, .data-table th.wrap { white-space: normal; }
.data-table thead th { background: var(--bg-secondary); color: var(--text-muted); text-transform: uppercase; font-size: var(--text-xs); letter-spacing: .04em; font-weight: 600; text-align: left; padding: var(--space-3) var(--space-4); position: sticky; top: 0; z-index: 2; box-shadow: inset 0 -1px 0 var(--border-medium); }
.data-table th.is-num, .data-table td.is-num { text-align: right; font-family: var(--font-mono); }
.data-table tbody td { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-light); color: var(--text-secondary); }
.data-table tbody tr:hover { background: var(--bg-secondary); }
.data-table tbody tr.is-clickable { cursor: pointer; }
.data-table .th-sort { background: none; border: 0; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; display: inline-flex; align-items: center; gap: 4px; padding: 0; }
.data-table th[aria-sort] .th-sort::after { content: "↕"; opacity: .4; }
.data-table th[aria-sort="ascending"] .th-sort::after { content: "↑"; opacity: 1; }
.data-table th[aria-sort="descending"] .th-sort::after { content: "↓"; opacity: 1; }
.data-table--compact tbody td { padding: var(--space-2) var(--space-4); }

/* --- Workflow steps strip --- */
.wf-steps { display: flex; align-items: stretch; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-5); }
.wf-step { display: flex; align-items: center; gap: var(--space-3); background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); box-shadow: var(--shadow-card); }
.wf-step.is-active { border-color: var(--accent-primary); background: color-mix(in srgb, var(--accent-primary) 6%, var(--bg-card)); }
.wf-step__num { width: 26px; height: 26px; flex: 0 0 26px; border-radius: var(--radius-full); display: grid; place-items: center; font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600; background: var(--bg-secondary); color: var(--text-muted); }
.wf-step.is-active .wf-step__num { background: var(--accent-primary); color: #fff; }
.wf-step__title { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); }
.wf-step__desc { font-size: var(--text-xs); color: var(--text-muted); }
.wf-step__arrow { display: flex; align-items: center; color: var(--text-light); }
@media (max-width: 720px) { .wf-steps { flex-direction: column; } .wf-step { width: 100%; } .wf-step__arrow { display: none; } }

/* --- "Why this decision" panel --- */
.why-panel { background: color-mix(in srgb, var(--accent-primary) 6%, var(--bg-card)); border: 1px solid var(--border-light); border-left: 3px solid var(--accent-primary); border-radius: var(--radius-md); padding: var(--space-4); margin-bottom: var(--space-4); }
.why-panel__head { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: var(--space-3); }
.why-panel__decision { margin-bottom: var(--space-2); }
.why-panel__reason { font-size: var(--text-base); color: var(--text-primary); margin: 0; }

/* --- Forms --- */
.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.field__label { font-size: var(--text-sm); font-weight: 500; color: var(--text-secondary); }
.field__help { font-size: var(--text-xs); color: var(--text-muted); }
.field__error { font-size: var(--text-xs); color: var(--accent-red); }
.input, .select, .textarea { background: var(--bg-card); border: 1px solid var(--border-medium); border-radius: var(--radius-md); padding: 8px 12px; font-size: var(--text-sm); color: var(--text-primary); width: 100%; transition: border-color var(--dur) var(--ease); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary) 18%, transparent); }
.select--compact { width: auto; padding: 6px 28px 6px 10px; font-size: var(--text-sm); }
.industry-switch { display: inline-flex; align-items: center; gap: var(--space-2); margin-right: var(--space-3); }
.industry-switch__label { font-size: var(--text-xs, 12px); color: var(--text-secondary, var(--text-muted)); text-transform: uppercase; letter-spacing: .04em; }

/* --- Ecran brand --- */
.ecran-mark { display: block; flex: none; }
.sidebar__brand { display: flex; align-items: center; gap: 10px; }
.sidebar__logo { font-family: var(--font-serif); font-weight: 700; letter-spacing: .06em; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: var(--space-5); text-align: center; }
.auth-brand__word { font-family: var(--font-serif); font-weight: 700; letter-spacing: .22em; font-size: 30px; color: var(--text-primary); padding-left: .22em; }
.auth-brand__tag { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.5; }
.auth-brand__em { font-style: italic; }
.range-row { display: flex; align-items: center; gap: var(--space-3); }
.range { flex: 1; accent-color: var(--accent-primary); }
.range-out { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-primary); min-width: 54px; text-align: right; }

.toggle { position: relative; display: inline-block; width: 38px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle__track { position: absolute; inset: 0; background: var(--border-medium); border-radius: var(--radius-full); transition: background var(--dur) var(--ease); }
.toggle__track::before { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; background: #fff; border-radius: var(--radius-full); box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease); }
.toggle input:checked + .toggle__track { background: var(--accent-primary); }
.toggle input:checked + .toggle__track::before { transform: translateX(16px); }

/* --- Segmented control --- */
.segmented { display: inline-flex; background: var(--bg-secondary); border-radius: var(--radius-md); padding: 2px; gap: 2px; }
.segmented button { background: none; border: 0; padding: 4px 12px; font-size: var(--text-xs); border-radius: var(--radius-sm); color: var(--text-secondary); }
.segmented button[aria-pressed="true"] { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* --- Toasts --- */
.toast-root { position: fixed; top: var(--space-4); right: var(--space-4); z-index: 60; display: flex; flex-direction: column; gap: var(--space-2); }
.toast { background: var(--bg-glass); backdrop-filter: blur(8px); border: 1px solid var(--border-light); border-left: 3px solid var(--accent-primary); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: var(--space-3) var(--space-4); font-size: var(--text-sm); min-width: 240px; animation: toast-in var(--dur) var(--ease); }
.toast--success { border-left-color: var(--accent-green); }
.toast--error { border-left-color: var(--accent-red); }
.toast--info { border-left-color: var(--accent-blue); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* --- Timeline (audit trail) --- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item { position: relative; padding: 0 0 var(--space-4) var(--space-5); border-left: 1px solid var(--border-light); }
.timeline__item:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline__item::before { content: ""; position: absolute; left: -5px; top: 3px; width: 9px; height: 9px; border-radius: var(--radius-full); background: var(--accent-primary); }
.timeline__meta { font-size: var(--text-xs); color: var(--text-muted); font-family: var(--font-mono); }
.timeline__action { font-weight: 500; }

/* --- Empty / skeleton --- */
.empty-state { text-align: center; padding: var(--space-7) var(--space-4); color: var(--text-muted); }
.empty-state .icon { width: 36px; height: 36px; color: var(--text-light); margin-bottom: var(--space-3); }
.empty-state__title { font-family: var(--font-serif); font-size: var(--text-lg); color: var(--text-secondary); margin-bottom: var(--space-1); }
.skeleton { background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-card) 37%, var(--bg-secondary) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-md); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* --- Chart wrapper --- */
.chart-box { position: relative; }
.chart-box canvas { width: 100% !important; }
.chart-caption { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-2); }

/* --- Helpers --- */
.icon { display: inline-block; vertical-align: middle; width: 20px; height: 20px; }
.muted { color: var(--text-muted); }
.text-sm { font-size: var(--text-sm); }
.num { font-family: var(--font-mono); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.flex { display: flex; align-items: center; gap: var(--space-2); }
.flex-wrap { flex-wrap: wrap; }
.mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); }
