/* Styles custom Fintable (complément Tailwind CDN) */

:root {
  --fintable-500: #2563EB;
  --fintable-600: #1D4ED8;
  --fintable-100: #DBEAFE;
  --fintable-50: #EFF6FF;
}

html {
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
}

body {
  background-color: #F8FAFC;
  color: #0F172A;
  -webkit-font-smoothing: antialiased;
}

/* Chiffres tabulaires pour alignement colonnes */
.tabular,
td.num,
th.num {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* Boutons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25rem;
  border: 1px solid transparent;
  transition: background-color 150ms, border-color 150ms, color 150ms;
  cursor: pointer;
}
.btn-primary { background-color: var(--fintable-500); color: #fff; }
.btn-primary:hover { background-color: var(--fintable-600); }
.btn-secondary { background-color: #fff; color: #334155; border-color: #CBD5E1; }
.btn-secondary:hover { background-color: #F1F5F9; }
.btn-ghost { color: #334155; }
.btn-ghost:hover { background-color: #F1F5F9; }
.btn-danger { background-color: #F43F5E; color: #fff; }
.btn-danger:hover { background-color: #E11D48; }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }
.btn-lg { padding: 0.75rem 1.25rem; font-size: 1rem; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1rem;
}
.badge-success { background-color: #D1FAE5; color: #065F46; }
.badge-warning { background-color: #FEF3C7; color: #92400E; }
.badge-danger  { background-color: #FFE4E6; color: #9F1239; }
.badge-neutral { background-color: #F1F5F9; color: #334155; }
.badge-info    { background-color: var(--fintable-100); color: var(--fintable-600); }

/* Card */
.card {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}

/* Sidebar active item */
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  color: #334155;
  font-size: 0.875rem;
}
.nav-item:hover { background-color: #F1F5F9; }
.nav-item.active {
  background-color: var(--fintable-100);
  color: var(--fintable-600);
  font-weight: 600;
}

/* Table TdB */
.tdb-wrapper {
  overflow: auto;
  max-height: 72vh;
  border: 1px solid #E2E8F0;
  border-radius: 0.5rem;
  background: #fff;
}
.tdb-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.75rem;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.tdb-table th,
.tdb-table td {
  border-bottom: 1px solid #F1F5F9;
  padding: 0.375rem 0.625rem;
  white-space: nowrap;
  text-align: right;
}
.tdb-table th.label,
.tdb-table td.label {
  text-align: left;
  min-width: 240px;
}
.tdb-table thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #F8FAFC;
  color: #475569;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.625rem;
}
.tdb-table thead th.flag-row {
  top: 0;
  background: #EEF2FF;
  font-size: 0.625rem;
  font-weight: 500;
  text-transform: none;
  color: #4338CA;
}
.tdb-table thead tr:nth-child(2) th { top: 1.6rem; }
.tdb-table th.sticky-col,
.tdb-table td.sticky-col {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 10;
  border-right: 1px solid #E2E8F0;
}
.tdb-table thead th.sticky-col {
  z-index: 30;
  background: #F8FAFC;
}
.tdb-table tr.section {
  background: #F1F5F9;
  font-weight: 600;
}
.tdb-table tr.section td.sticky-col { background: #F1F5F9; }
.tdb-table tr.calc {
  background: var(--fintable-100);
  font-weight: 700;
  color: var(--fintable-600);
}
.tdb-table tr.calc td.sticky-col { background: var(--fintable-100); }
.tdb-table td.projected {
  color: #64748B;
  font-style: italic;
  background: repeating-linear-gradient(-45deg, #fff, #fff 6px, #F8FAFC 6px, #F8FAFC 7px);
}
.tdb-table td.projected.first-projected {
  border-left: 2px dashed #94A3B8;
}
.tdb-table td.num { text-align: right; }
.tdb-table td.positive { color: #047857; }
.tdb-table td.negative { color: #BE123C; }
.tdb-table td.clickable { cursor: pointer; }
.tdb-table td.clickable:hover { background-color: var(--fintable-50); }

.marge-good   { color: #047857; font-weight: 600; }
.marge-medium { color: #B45309; font-weight: 600; }
.marge-bad    { color: #BE123C; font-weight: 600; }

/* KPI stat-card */
.stat-card {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 0.5rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stat-card .label { font-size: 0.75rem; color: #64748B; text-transform: uppercase; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; color: #0F172A; }
.stat-card .trend { font-size: 0.75rem; }
.stat-card .trend.up { color: #047857; }
.stat-card .trend.down { color: #BE123C; }

/* Toasts */
.toast {
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 10px 25px rgba(15,23,42,0.1);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  min-width: 280px;
}

/* Skeleton */
.skeleton {
  background: linear-gradient(90deg, #F1F5F9 0%, #E2E8F0 50%, #F1F5F9 100%);
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
  border-radius: 0.25rem;
}
@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Mobile drawer helpers */
.drawer-overlay {
  background-color: rgba(15, 23, 42, 0.5);
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--fintable-500);
  outline-offset: 2px;
}

/* Banner wireframe */
.wf-banner {
  background: repeating-linear-gradient(-45deg, #FEF3C7 0 8px, #FDE68A 8px 16px);
  color: #92400E;
  font-size: 0.7rem;
  text-align: center;
  padding: 0.25rem;
  border-bottom: 1px solid #FBBF24;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ============================================================ */
/* Layout : header global + sidebar (inliné dans certaines pages) */
/* ============================================================ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.625rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #E2E8F0;
  box-shadow: 0 1px 2px rgba(15,23,42,0.03);
}
.app-header .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: #0F172A;
}
.app-header .brand-logo {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.375rem;
  background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: -0.05em;
}
.app-header .search {
  flex: 1;
  max-width: 420px;
  position: relative;
}
.app-header .search input {
  width: 100%;
  padding: 0.5rem 0.875rem 0.5rem 2.25rem;
  border: 1px solid #E2E8F0;
  border-radius: 0.5rem;
  background: #F8FAFC;
  font-size: 0.8125rem;
  color: #0F172A;
}
.app-header .search input:focus {
  background: #fff;
  border-color: #2563EB;
}
.app-header .search svg {
  position: absolute;
  left: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  color: #94A3B8;
}
.app-header .actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.app-header .icon-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748B;
  position: relative;
  cursor: pointer;
}
.app-header .icon-btn:hover { background: #F1F5F9; color: #0F172A; }
.app-header .icon-btn .dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: #F43F5E;
  border: 2px solid #fff;
  border-radius: 50%;
}
.app-header .avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: #2563EB;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.app-shell { display: flex; min-height: calc(100vh - 80px); }

.app-sidebar {
  width: 244px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #E2E8F0;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 57px;
  align-self: flex-start;
  height: calc(100vh - 57px);
  overflow-y: auto;
}
.app-sidebar .sb-section {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.app-sidebar .sb-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94A3B8;
  padding: 0 0.75rem;
  margin-bottom: 0.25rem;
}
.app-sidebar .sb-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  color: #334155;
  font-size: 0.8125rem;
  text-decoration: none;
  transition: background-color 120ms;
}
.app-sidebar .sb-item svg { width: 1rem; height: 1rem; color: #94A3B8; flex-shrink: 0; }
.app-sidebar .sb-item:hover { background: #F1F5F9; }
.app-sidebar .sb-item.active {
  background: var(--fintable-50);
  color: var(--fintable-600);
  font-weight: 600;
}
.app-sidebar .sb-item.active svg { color: var(--fintable-500); }
.app-sidebar .sb-item .badge-count {
  margin-left: auto;
  background: var(--fintable-500);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 600;
  border-radius: 9999px;
  padding: 0 0.375rem;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.app-sidebar .sb-company-card {
  margin: 0 -0.25rem;
  padding: 0.625rem 0.75rem;
  background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
  border: 1px solid #BFDBFE;
  border-radius: 0.5rem;
}
.app-sidebar .sb-company-card .ttl {
  font-size: 0.625rem;
  font-weight: 600;
  color: #1D4ED8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.app-sidebar .sb-company-card .name {
  font-size: 0.875rem;
  font-weight: 700;
  color: #0F172A;
  margin-top: 0.125rem;
}
.app-sidebar .sb-company-card .sub {
  font-size: 0.6875rem;
  color: #64748B;
  margin-top: 0.125rem;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 1.5rem;
}

.app-footer {
  border-top: 1px solid #E2E8F0;
  background: #fff;
  padding: 1rem 1.5rem;
  font-size: 0.75rem;
  color: #94A3B8;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
}
.app-footer a { color: #64748B; text-decoration: none; }
.app-footer a:hover { color: var(--fintable-500); }

/* Renforce stat-card */
.stat-card {
  transition: transform 150ms, box-shadow 150ms;
}
.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15,23,42,0.06);
}
.stat-card .label {
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* Badges raffinés */
.badge { letter-spacing: 0.02em; }

/* Card hover */
.card.interactive:hover {
  border-color: var(--fintable-500);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
  cursor: pointer;
}

/* Boutons améliorés */
.btn { font-feature-settings: "cv11"; }
.btn-primary { box-shadow: 0 1px 2px rgba(37,99,235,0.3); }
.btn-primary:active { transform: translateY(1px); }

/* Divider vertical pour KPI groups */
.kpi-row {
  display: flex;
  gap: 0;
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 0.5rem;
  overflow: hidden;
}
.kpi-row > .kpi {
  flex: 1;
  padding: 1rem 1.25rem;
  border-left: 1px solid #E2E8F0;
}
.kpi-row > .kpi:first-child { border-left: 0; }
.kpi .kpi-label { font-size: 0.6875rem; color: #64748B; text-transform: uppercase; font-weight: 600; letter-spacing: 0.04em; }
.kpi .kpi-value { font-size: 1.5rem; font-weight: 700; color: #0F172A; margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.kpi .kpi-trend { font-size: 0.75rem; margin-top: 0.25rem; font-weight: 500; }
.kpi .kpi-trend.up { color: #047857; }
.kpi .kpi-trend.down { color: #BE123C; }

/* Section title */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: #0F172A;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.section-title .hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: #94A3B8;
}
.section-title .more {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--fintable-500);
  font-weight: 500;
  text-decoration: none;
}
.section-title .more:hover { text-decoration: underline; }

/* List company */
.co-row {
  display: grid;
  grid-template-columns: 2.25rem 1fr auto auto auto;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 0.875rem;
  border-radius: 0.375rem;
  transition: background-color 120ms;
}
.co-row:hover { background: #F8FAFC; }
.co-row .co-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  background: linear-gradient(135deg, #E0E7FF 0%, #DBEAFE 100%);
  color: #1D4ED8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}
.co-row .co-name { font-size: 0.875rem; font-weight: 600; color: #0F172A; }
.co-row .co-meta { font-size: 0.75rem; color: #64748B; }

/* Divider doux */
.soft-divider {
  border-top: 1px solid #F1F5F9;
  margin: 0.75rem 0;
}

/* Timeline */
.ftl-item {
  display: flex;
  gap: 0.75rem;
  padding-bottom: 1rem;
  position: relative;
}
.ftl-item::before {
  content: "";
  position: absolute;
  left: 0.875rem;
  top: 2rem;
  bottom: 0;
  width: 1px;
  background: #E2E8F0;
}
.ftl-item:last-child::before { display: none; }
.ftl-dot {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F1F5F9;
  color: #64748B;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  z-index: 1;
}
.ftl-dot.success { background: #D1FAE5; color: #047857; }
.ftl-dot.warning { background: #FEF3C7; color: #92400E; }
.ftl-dot.danger { background: #FFE4E6; color: #9F1239; }

/* Chart container */
.chart-wrapper {
  position: relative;
  height: 220px;
}

/* Responsive */
@media (max-width: 1024px) {
  .app-sidebar { display: none; }
}
