/* SyncBridge / Ceta'Connect — design system partagé */
:root {
  --ocean: #0A1628;
  --blue: #1B4F8A;
  --cyan: #00B4D8;
  --gold: #E8A020;
  --white: #FFFFFF;
  --bg: #EEF2F7;
  --card: #FFFFFF;
  --text: #0B1520;
  --muted: #64748B;
  --border: #E2E8F0;
  --success: #00A87B;
  --error: #DC2626;
  --sidebar-w: 240px;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 8px rgba(0,0,0,.03);
  --shadow-md: 0 8px 24px rgba(10,22,40,.08);
  --accent: var(--cyan);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }
input, select, button, textarea { font-family: inherit; }
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ─── LOGIN ─── */
#login-page {
  min-height: 100vh;
  background: var(--ocean);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}
#login-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(0,180,216,.14), transparent),
    radial-gradient(ellipse 50% 40% at 100% 0%, rgba(27,79,138,.25), transparent);
  pointer-events: none;
}
.login-box { width: 100%; max-width: 420px; position: relative; z-index: 1; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo img, .login-logo .logo-fallback {
  width: 88px; height: 88px;
  object-fit: contain;
  filter: drop-shadow(0 4px 20px rgba(0,180,216,.35));
  margin: 0 auto;
  display: block;
}
.login-logo h1 { color: #fff; font-size: 26px; font-weight: 800; margin-top: 14px; letter-spacing: -.02em; }
.login-logo p { color: rgba(255,255,255,.45); font-size: 12px; margin-top: 8px; line-height: 1.6; }
.login-card {
  background: rgba(0,180,216,.06);
  border: 1px solid rgba(0,180,216,.18);
  border-radius: 20px;
  padding: 28px;
  backdrop-filter: blur(8px);
}
.login-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.login-card-head .bar {
  width: 3px; height: 22px; border-radius: 2px;
  background: linear-gradient(var(--cyan), var(--blue));
}
.login-card-head .title { font-size: 14px; font-weight: 700; color: #fff; }
.login-card-head .sub { font-size: 11px; color: rgba(255,255,255,.35); margin-top: 1px; }
.login-label {
  font-size: 11px; font-weight: 700; color: rgba(255,255,255,.45);
  text-transform: uppercase; letter-spacing: .1em; display: block; margin-bottom: 8px;
}
.login-input {
  width: 100%; padding: 12px 44px 12px 16px; border-radius: 10px;
  border: 1.5px solid rgba(0,180,216,.22); background: rgba(255,255,255,.09);
  color: #fff; font-size: 14px; outline: none; transition: border .2s, box-shadow .2s;
  caret-color: var(--cyan);
}
.login-input::placeholder { color: rgba(255,255,255,.3); }
.login-input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(0,180,216,.15); }
.pw-wrap { position: relative; }
.pw-eye {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: rgba(255,255,255,.35);
  font-size: 16px; padding: 4px; line-height: 1;
}
.login-error {
  background: rgba(220,38,38,.1); border: 1px solid rgba(220,38,38,.25);
  border-radius: 8px; padding: 9px 14px; font-size: 12px; color: #FCA5A5;
  margin-top: 12px; display: none;
}
.login-btn {
  width: 100%; padding: 13px; border-radius: 10px; border: none; margin-top: 16px;
  background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #fff;
  font-size: 14px; font-weight: 700; cursor: pointer; transition: opacity .2s, transform .15s;
  box-shadow: 0 4px 20px rgba(0,180,216,.35);
}
.login-btn:hover { opacity: .92; transform: translateY(-1px); }
.login-btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; transform: none; }
.login-credit {
  text-align: center; margin-top: 20px; padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: 11px; color: rgba(255,255,255,.25);
}
.login-credit a { color: rgba(0,180,216,.55); font-weight: 600; }

/* ─── APP LAYOUT ─── */
#app { display: none; min-height: 100vh; }
.layout { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--ocean);
  display: flex; flex-direction: column;
  padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
  border-right: 1px solid rgba(255,255,255,.04);
}
.sb-brand { padding: 4px 8px 14px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 10px; }
.sb-logo-row { display: flex; align-items: center; gap: 10px; }
.sb-logo-row img, .sb-logo-row .logo-fallback { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; flex-shrink: 0; }
.sb-title { font-size: 13px; font-weight: 800; color: #fff; letter-spacing: -.01em; }
.sb-sub { font-size: 9.5px; color: rgba(255,255,255,.35); font-family: ui-monospace, monospace; margin-top: 1px; }
.sb-pill {
  background: rgba(0,180,216,.1); border: 1px solid rgba(0,180,216,.18);
  border-radius: 6px; padding: 5px 8px; margin-top: 10px;
  font-size: 9px; font-family: ui-monospace, monospace; color: rgba(0,180,216,.85); font-weight: 600;
}
.sb-section {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: rgba(255,255,255,.28); padding: 10px 10px 4px; margin-top: 4px;
}
.sb-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; scrollbar-width: thin; }
.sb-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 9px; cursor: pointer; font-size: 12.5px; font-weight: 500;
  color: rgba(255,255,255,.48); transition: all .15s; border: none; background: none;
  text-align: left; width: 100%;
}
.sb-item:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.85); }
.sb-item.active {
  background: rgba(0,180,216,.14); color: var(--cyan); font-weight: 700;
  box-shadow: inset 3px 0 0 var(--cyan);
}
.sb-item .icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; opacity: .9; }
.sb-logout { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.sb-logout button {
  width: 100%; padding: 8px 10px; border-radius: 9px; border: none;
  background: rgba(220,38,38,.1); color: #F87171;
  font-size: 12px; font-weight: 600; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 8px; transition: background .15s;
}
.sb-logout button:hover { background: rgba(220,38,38,.18); }

/* MAIN + TOPBAR */
.main { flex: 1; overflow: auto; display: flex; flex-direction: column; min-width: 0; }
.main-topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(238,242,247,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.main-topbar-title { font-size: 15px; font-weight: 800; color: var(--text); letter-spacing: -.02em; }
.main-topbar-meta {
  display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--muted);
}
.main-topbar-meta .pulse-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 0 rgba(0,168,123,.5);
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,168,123,.45); }
  50% { box-shadow: 0 0 0 5px rgba(0,168,123,0); }
}
.main-content { padding: 24px 28px 32px; flex: 1; }
.tab { display: none; }
.tab.active { display: block; animation: fade-tab .25s ease; }
@keyframes fade-tab { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* CARDS & KPI */
.card {
  background: var(--card); border-radius: var(--radius); padding: 22px 24px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
}
.card + .card, .card.mb { margin-bottom: 20px; }
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
}
.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted);
}
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.kpi-grid--5 { grid-template-columns: repeat(5, 1fr); }
.kpi-grid--3 { grid-template-columns: repeat(3, 1fr); }
.kpi {
  padding: 20px 22px; border-radius: var(--radius); background: var(--card);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border); border-top-width: 3px;
  transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi--blue { border-top-color: var(--blue); }
.kpi--cyan { border-top-color: var(--cyan); }
.kpi--gold { border-top-color: var(--gold); }
.kpi--error { border-top-color: var(--error); }
.kpi--muted { border-top-color: #64748B; }
.kpi-icon { font-size: 22px; margin-bottom: 10px; }
.kpi-val { font-size: 30px; font-weight: 800; letter-spacing: -.03em; color: var(--text); line-height: 1.1; }
.kpi-lbl { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* PAGE HEADER */
.ph { margin-bottom: 24px; }
.ph-row { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; }
.ph h1 { font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
.ph p { font-size: 13px; color: var(--muted); margin-top: 5px; }
.ph-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* TABLES */
.tbl-wrap {
  overflow: auto; border-radius: var(--radius); border: 1px solid var(--border);
  max-width: 100%;
}
.tbl-wrap--scroll { max-height: min(70vh, 640px); }
.tbl-wrap table thead tr { background: #F8FAFC; }
.tbl-wrap table th {
  padding: 10px 16px; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); text-align: left; white-space: nowrap;
  position: sticky; top: 0; z-index: 2; background: #F8FAFC;
  box-shadow: 0 1px 0 var(--border);
}
.tbl-wrap table td { padding: 11px 16px; font-size: 13px; border-top: 1px solid #F8FAFC; vertical-align: middle; }
.tbl-wrap table tbody tr:hover td { background: #FAFBFD; }
.cell-mono { font-family: ui-monospace, monospace; font-size: 12px; }
.cell-muted { font-size: 12px; color: var(--muted); word-break: break-all; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px;
  border-radius: 20px; font-size: 11px; font-weight: 700;
}
.badge.ok { background: #D1FAE5; color: #065F46; }
.badge.err { background: #FEE2E2; color: #991B1B; }
.badge.skip { background: #F1F5F9; color: #64748B; }
.badge.warn { background: #FEF3C7; color: #92400E; }

/* SEARCH / FILTERS */
.search-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-bar input, .search-bar select, .filter-input {
  padding: 8px 14px; border-radius: 9px; border: 1.5px solid var(--border);
  font-size: 13px; outline: none; background: #fff; color: var(--text);
}
.search-bar input:focus, .search-bar select:focus, .filter-input:focus { border-color: var(--cyan); }
.search-bar input { flex: 1; min-width: 180px; }

/* CHARTS */
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding: 0 4px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.bar-val { font-size: 9px; color: var(--muted); font-family: ui-monospace, monospace; }
.bar-stack { width: 100%; display: flex; flex-direction: column; justify-content: flex-end; height: 130px; gap: 1px; }
.bar-ok { width: 100%; border-radius: 4px 4px 0 0; background: linear-gradient(180deg, var(--cyan), var(--blue)); min-height: 3px; transition: height .4s; }
.bar-err { width: 100%; background: #F87171; min-height: 2px; }
.bar-gold { width: 100%; border-radius: 4px 4px 0 0; background: linear-gradient(180deg, var(--gold), #B8761A); min-height: 3px; transition: height .4s; }
.bar-lbl { font-size: 9px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* FORMS */
.form-section { margin-bottom: 24px; }
.form-section h3 {
  font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 14px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field label {
  display: block; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em; margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 9px; border: 1.5px solid var(--border);
  font-size: 13px; outline: none; color: var(--text); background: #fff;
}
.field input:focus, .field select:focus { border-color: var(--cyan); }
.field-help { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* BUTTONS */
.btn {
  padding: 10px 20px; border-radius: 9px; border: none; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 6px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.is-loading { pointer-events: none; opacity: .7; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #153d6e; }
.btn-outline { background: #fff; color: var(--blue); border: 1.5px solid rgba(27,79,138,.25); }
.btn-outline:hover:not(:disabled) { background: #EFF6FF; }
.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn-danger { background: #FEE2E2; color: var(--error); border: none; }

/* SEGMENTED CONTROL */
.segmented {
  display: inline-flex; background: #fff; border-radius: 10px;
  border: 1px solid var(--border); overflow: hidden;
}
.segmented .btn { border-radius: 0; background: transparent; color: var(--muted); font-weight: 600; }
.segmented .btn.active { background: var(--text); color: #fff; }

/* CREDIT BAR */
.credit-bar-wrap { margin-bottom: 6px; }
.credit-bar-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.credit-bar-bg { height: 7px; background: #F1F5F9; border-radius: 4px; overflow: hidden; }
.credit-bar-fill { height: 100%; background: linear-gradient(90deg, var(--cyan), var(--blue)); border-radius: 4px; transition: width .5s; }

/* FLOW */
.flow { display: flex; align-items: center; gap: 0; margin: 20px 0; flex-wrap: wrap; }
.flow-step {
  flex: 1; min-width: 120px; padding: 14px 16px; border-radius: 12px;
  background: #F8FAFC; border: 1px solid var(--border); text-align: center;
}
.flow-step .icon { font-size: 22px; margin-bottom: 6px; }
.flow-step .name { font-size: 11px; font-weight: 700; color: var(--text); }
.flow-step .desc { font-size: 10px; color: var(--muted); margin-top: 2px; }
.flow-arrow { font-size: 18px; color: var(--muted); padding: 0 6px; flex-shrink: 0; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.dot.ok { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.dot.err { background: #F87171; }
.dot.off { background: #CBD5E1; }

/* SPINNER / EMPTY / LOADING */
.spinner {
  display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(0,0,0,.1);
  border-top-color: var(--cyan); border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 200px; gap: 12px; color: var(--muted); font-size: 13px;
}
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: .85; }
.empty-state p { font-size: 13px; max-width: 360px; margin: 0 auto; line-height: 1.5; }

/* TOAST */
#toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 20px; border-radius: 12px;
  background: var(--blue); color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 9999;
  transform: translateY(100px); opacity: 0; transition: all .3s; pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.toast-ok { background: linear-gradient(135deg, var(--blue), #153d6e); }
#toast.toast-err { background: linear-gradient(135deg, #DC2626, #991B1B); }

/* MODAL */
.sb-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(10,22,40,.72); z-index: 10050;
  align-items: center; justify-content: center; padding: 16px;
  backdrop-filter: blur(4px);
}
.sb-modal-overlay.open { display: flex; }
.sb-modal {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  width: 720px; max-width: 100%; max-height: 85vh;
  display: flex; flex-direction: column; box-shadow: 0 24px 80px rgba(0,0,0,.35);
  animation: modal-in .2s ease;
}
@keyframes modal-in { from { opacity: 0; transform: scale(.97) translateY(8px); } to { opacity: 1; transform: none; } }
.sb-modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.sb-modal-head h2 { font-size: 16px; font-weight: 800; margin: 0; }
.sb-modal-head .accent { color: var(--cyan); }
.sb-modal-body { overflow-y: auto; flex: 1; padding: 16px 22px; }

/* MAPPING */
.mapping-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.mapping-row input { flex: 1; padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 12px; outline: none; }
.mapping-row button { padding: 6px 10px; border-radius: 8px; border: none; background: #FEE2E2; color: var(--error); cursor: pointer; font-size: 13px; }

.db-snapshot { font-size: 11px; color: var(--muted); margin: -8px 0 16px; line-height: 1.5; }

/* RESPONSIVE */
@media (max-width: 1024px) {
  :root { --sidebar-w: 210px; }
  .main-content { padding: 20px; }
  .main-topbar { padding: 10px 20px; }
}
@media (max-width: 768px) {
  .layout { display: block; }
  .sidebar {
    position: static; top: auto; height: auto; width: 100%; min-width: 0;
    padding: 12px 10px; border-right: none; border-bottom: 1px solid rgba(255,255,255,.06);
  }
  .sb-brand { padding-bottom: 10px; margin-bottom: 8px; }
  .sb-section { display: none; }
  .sb-nav {
    flex-direction: row; overflow-x: auto; overflow-y: hidden; gap: 6px;
    padding-bottom: 4px; scroll-snap-type: x proximity;
  }
  .sb-item {
    flex: 0 0 auto; white-space: nowrap; padding: 8px 12px; border-radius: 999px;
    font-size: 12px; background: rgba(255,255,255,.04); scroll-snap-align: start;
    box-shadow: none;
  }
  .sb-item.active { box-shadow: none; border: 1px solid rgba(0,180,216,.35); }
  .sb-item .icon { width: auto; }
  .sb-logout { padding-top: 10px; }
  .sb-logout button { justify-content: center; }
  .main-topbar { position: static; }
  .main-content { padding: 14px; }
  .ph h1 { font-size: 20px; }
  .kpi-grid, .kpi-grid--5, .kpi-grid--3 { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 14px; }
  .kpi-val { font-size: 24px; }
  .card { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .search-bar input { min-width: 0; width: 100%; }
  .search-bar .btn { width: 100%; justify-content: center; }
  .flow { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .flow-arrow { display: none; }
  .mapping-row { flex-direction: column; align-items: stretch; }
}
@media (max-width: 480px) {
  .login-card { padding: 20px; }
  .kpi-grid, .kpi-grid--5, .kpi-grid--3 { grid-template-columns: 1fr; }
  .tbl-wrap table th, .tbl-wrap table td { padding: 9px 10px; font-size: 12px; }
  #toast { left: 12px; right: 12px; bottom: 12px; }
}
