/* ============================================================
   CaniSuivi — Design system (charte graphique Victor Vergne)
   Palette: #8A4F2B brun · #D2A15F or · #E8D1A8 crème · #1E1A17 encre · #4A3324 brun foncé
   Type: Unbounded (display) · Hanken Grotesk (UI)
   ============================================================ */

:root {
  /* charte */
  --c-brown:    #8A4F2B;
  --c-gold:     #D2A15F;
  --c-cream:    #E8D1A8;
  --c-ink:      #1E1A17;
  --c-darkbrown:#4A3324;

  /* derived neutrals (warm) */
  --bg:        #F6F1E9;
  --surface:   #FFFFFF;
  --surface-2: #FBF7F0;
  --surface-3: #F3ECE0;
  --border:    #EBE1D2;
  --border-2:  #E0D3BF;

  --ink:       #1E1A17;
  --ink-2:     #6E6358;
  --ink-3:     #9A8E7F;

  /* roles */
  --primary:        var(--c-brown);
  --primary-press:  #774225;
  --primary-soft:   #F2E7DB;
  --accent:         var(--c-gold);
  --accent-soft:    #FAF0DE;

  /* status (harmonised, oklch on warm base) */
  --st-todo:   oklch(0.62 0.012 70);
  --st-todo-bg:oklch(0.94 0.012 80);
  --st-doing:  oklch(0.66 0.12 65);
  --st-doing-bg:oklch(0.94 0.05 80);
  --st-done:   oklch(0.58 0.10 150);
  --st-done-bg:oklch(0.93 0.05 150);
  --st-redo:   oklch(0.58 0.14 35);
  --st-redo-bg:oklch(0.93 0.05 40);

  /* shape */
  --r-sm: 8px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 28px;

  /* spacing scale knob (density) */
  --gap: 24px;
  --pad: 22px;

  --shadow-sm: 0 1px 2px rgba(60,40,20,.05), 0 1px 3px rgba(60,40,20,.04);
  --shadow:    0 2px 6px rgba(60,40,20,.06), 0 8px 24px rgba(60,40,20,.05);
  --shadow-lg: 0 12px 40px rgba(60,40,20,.12);

  --font-ui: 'Hanken Grotesk', system-ui, sans-serif;
  --font-display: 'Unbounded', system-ui, sans-serif;

  --sidebar-w: 248px;
  --topbar-h: 72px;
}

/* density variants */
[data-density="compact"] { --gap: 16px; --pad: 16px; --topbar-h: 62px; }
[data-density="comfy"]   { --gap: 30px; --pad: 28px; --topbar-h: 80px; }

/* dark theme */
[data-theme="dark"] {
  --bg:        #161210;
  --surface:   #211B17;
  --surface-2: #1B1612;
  --surface-3: #2A221C;
  --border:    #34291F;
  --border-2:  #413225;
  --ink:       #F4ECE0;
  --ink-2:     #B6A795;
  --ink-3:     #897C6C;
  --primary:        #D2A15F;
  --primary-press:  #C18E48;
  --primary-soft:   #2E241B;
  --accent:         #E8D1A8;
  --accent-soft:    #2A2118;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow:    0 2px 6px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.3);
  --shadow-lg: 0 16px 50px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--c-gold); color: var(--c-ink); }

h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

/* scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: padding-box; }

/* ---------- layout shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 22px 22px 18px;
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--primary); color: var(--c-cream);
  display: grid; place-items: center; flex: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.02em; line-height: 1; }
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase; margin-top: 3px; }

.nav { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 12px 12px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding: 16px 12px 7px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500; font-size: 14.5px;
  border: none; background: none; width: 100%; text-align: left;
  transition: background .14s, color .14s;
  position: relative; white-space: nowrap;
}
.nav-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; min-width: 0; }
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
[data-theme="dark"] .nav-item.active { color: var(--accent); }
.nav-item.active svg { color: var(--primary); }
[data-theme="dark"] .nav-item.active svg { color: var(--accent); }
.nav-item .nav-badge {
  margin-left: auto; background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 20px; height: 20px;
  border-radius: 99px; display: grid; place-items: center; padding: 0 6px; flex: none;
}
[data-theme="dark"] .nav-item .nav-badge { color: #1b150f; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: var(--r-sm);
  cursor: pointer; transition: background .14s;
}
.user-chip:hover { background: var(--surface-3); }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: var(--topbar-h); flex: none;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 18px;
  padding: 0 var(--pad);
}
.page-title { font-family: var(--font-display); font-size: 21px; font-weight: 600; letter-spacing: -0.02em; }
.page-crumb { color: var(--ink-3); font-size: 13px; margin-top: 2px; white-space: nowrap; }

.search {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface-3); border: 1px solid transparent;
  border-radius: 99px; padding: 9px 16px; min-width: 240px;
  color: var(--ink-3); transition: border .14s, background .14s;
}
.search:focus-within { border-color: var(--border-2); background: var(--surface); }
.search input { border: none; background: none; outline: none; font-family: inherit; font-size: 14px; color: var(--ink); width: 100%; }
.search input::placeholder { color: var(--ink-3); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); display: grid; place-items: center;
  position: relative; transition: background .14s, color .14s, border-color .14s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 99px; background: var(--c-gold); border: 2px solid var(--surface); }

.content { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: var(--pad); }
.content-inner { max-width: 1280px; margin: 0 auto; }

/* ---------- primitives ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--pad); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 18px var(--pad); border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 16px; white-space: nowrap; }
.card-head { flex-wrap: nowrap; }
.card-title-sm { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 11px; border: 1px solid transparent; padding: 10px 16px;
  font-weight: 600; font-size: 14px; transition: transform .08s, background .14s, box-shadow .14s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(60,40,20,.15); }
[data-theme="dark"] .btn-primary { color: #1b150f; }
.btn-primary:hover { background: var(--primary-press); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .btn-soft { color: var(--accent); }
.btn-soft:hover { filter: brightness(.97); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-3); color: var(--ink-2); white-space: nowrap;
}
.badge .bdot { width: 7px; height: 7px; border-radius: 99px; background: currentColor; }
.badge.todo  { background: var(--st-todo-bg);  color: var(--st-todo); }
.badge.doing { background: var(--st-doing-bg); color: var(--st-doing); }
.badge.done  { background: var(--st-done-bg);  color: var(--st-done); }
.badge.redo  { background: var(--st-redo-bg);  color: var(--st-redo); }

.avatar {
  border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 14px; overflow: hidden;
  background: var(--primary);
}
.avatar.sq { border-radius: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 99px; font-size: 12.5px; font-weight: 500;
  background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--border);
}
.tag.on { background: var(--accent-soft); color: var(--c-brown); border-color: var(--c-gold); }
[data-theme="dark"] .tag.on { color: var(--accent); }

/* meter / bars */
.meter { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 99px; background: var(--primary); }

/* grids */
.grid { display: grid; gap: var(--gap); min-width: 0; }
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: 1.7fr 1fr; }
.cols-2 { grid-template-columns: 1fr 1fr; }

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; align-items: center; gap: 12px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; }

/* kpi card */
.kpi { padding: var(--pad); }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .kpi .kpi-ico { color: var(--accent); }
.kpi .kpi-num { font-family: var(--font-display); font-size: 34px; font-weight: 600; letter-spacing: -0.03em; margin-top: 14px; line-height: 1; }
.kpi .kpi-lbl { color: var(--ink-2); font-size: 13.5px; margin-top: 6px; }
.kpi-trend { white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.kpi .kpi-trend { font-size: 12.5px; }
.kpi .kpi-trend.up { color: var(--st-done); }

/* list rows */
.lrow { display: flex; align-items: center; gap: 14px; padding: 13px var(--pad); border-bottom: 1px solid var(--border); transition: background .12s; cursor: pointer; }
.lrow:last-child { border-bottom: none; }
.lrow:hover { background: var(--surface-2); }

/* timeline (agenda du jour) */
.tl-item { display: grid; grid-template-columns: 56px 1fr; gap: 14px; padding: 0 var(--pad); }
.tl-time { font-size: 13px; font-weight: 600; color: var(--ink-2); text-align: right; padding-top: 14px; }
.tl-body { border-left: 2px solid var(--border); padding: 12px 0 18px 18px; position: relative; min-width: 0; }
.tl-item:last-child .tl-body { padding-bottom: 8px; }
.tl-body::before { content: ''; position: absolute; left: -7px; top: 17px; width: 12px; height: 12px; border-radius: 99px; background: var(--surface); border: 3px solid var(--primary); }
.tl-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 13px 15px; transition: box-shadow .14s, transform .08s; cursor: pointer; }
.tl-card:hover { box-shadow: var(--shadow-sm); transform: translateX(2px); }
.tl-card .between { gap: 10px; }
.tl-card .between > .row:first-child { flex: 1; min-width: 0; }
.tl-card .between > .row:first-child > div:not(.avatar) { min-width: 0; flex: 1; }
.tl-card .between > .row:first-child > div:not(.avatar) > div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-card .badge { flex: none; }

/* photo placeholder (striped) */
.ph {
  position: relative; border-radius: var(--r); overflow: hidden;
  background:
    repeating-linear-gradient(45deg, var(--surface-3) 0 10px, var(--surface-2) 10px 20px);
  border: 1px dashed var(--border-2);
  display: grid; place-items: center;
}
.ph span { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--ink-3); background: var(--surface); padding: 3px 9px; border-radius: 99px; border: 1px solid var(--border); }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-3); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: none; background: none; padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; padding: 12px var(--pad); border-bottom: 1px solid var(--border); }
.tbl td { padding: 13px var(--pad); border-bottom: 1px solid var(--border); font-size: 14px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .12s; cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }

/* fade-in — transform-only so a frozen/paused capture frame is never invisible.
   Resting state is fully visible; entrance only when motion is allowed. */
@keyframes rise { from { transform: translateY(10px); } to { transform: none; } }
@media (prefers-reduced-motion: no-preference) {
  .view { animation: rise .3s ease; }
}

/* progress ring */
.ring-wrap { position: relative; display: grid; place-items: center; }
.ring-wrap .ring-val { position: absolute; font-family: var(--font-display); font-weight: 600; font-size: 20px; }

/* misc */
.divider { height: 1px; background: var(--border); }
.chiplist { display: flex; flex-wrap: wrap; gap: 8px; }
.sr { position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0); }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2,1fr); }
  .cols-3, .cols-2 { grid-template-columns: 1fr; }
}

/* ============================================================
   Login screen
   ============================================================ */
.login-screen {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--primary-soft), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 30px 26px;
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
}
.login-logo { width: 76px; height: 76px; object-fit: contain; align-self: center; }
.login-brand { text-align: center; font-family: var(--font-display); font-weight: 600; font-size: 24px; letter-spacing: -0.02em; }
.login-sub { text-align: center; color: var(--ink-3); font-size: 13px; margin-bottom: 8px; }
.login-field { display: flex; flex-direction: column; gap: 5px; }
.login-field > span { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.login-btn { width: 100%; margin-top: 6px; padding: 11px; font-size: 15px; }
.login-err {
  display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500;
  color: var(--st-redo); background: var(--st-redo-bg); border-radius: var(--r-sm); padding: 9px 11px;
}
.login-foot { color: var(--ink-3); font-size: 12px; }
.auth-splash { min-height: 100vh; display: grid; place-items: center; color: var(--ink-3); background: var(--bg); }

/* ============================================================
   Responsive — small screens adopt the mobile mockup chrome
   (bottom tab bar + "Plus" sheet + compact header)
   ============================================================ */

/* desktop-only by default; revealed on mobile */
.topbar-brand { display: none; width: 34px; height: 34px; object-fit: contain; flex: none; }
.m-only { display: none !important; }
.topbar-search-row { display: none; }
.mnav, .msheet, .msheet-scrim { display: none; }
.tbl-wrap { width: 100%; }

/* collapse every multi-column grid (incl. inline templates) below the desktop width */
@media (max-width: 980px) {
  .grid:not(.kpis) { grid-template-columns: 1fr !important; }
  .hero-grid { grid-template-columns: 1fr !important; }
}

/* phone / small tablet: mockup-style layout */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }

  .topbar { gap: 10px; padding: 0 14px; }
  .topbar-brand { display: block; }
  .page-title { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .search-desktop { display: none; }
  .m-only { display: grid !important; }
  .btn-label { display: none; }
  .topbar-cta { padding: 10px; }

  .topbar-search-row { display: block; max-height: 0; overflow: hidden; background: var(--surface); border-bottom: 1px solid transparent; transition: max-height .22s ease, border-color .22s ease; }
  .topbar-search-row.open { max-height: 70px; border-bottom-color: var(--border); }
  .topbar-search-row .search { width: auto; min-width: 0; margin: 11px 14px; }

  .content { padding-bottom: 88px; }
  .content-inner { max-width: 100%; }
  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* timeline (agenda du jour) — compact so cards fit without clipping */
  .tl-item { grid-template-columns: 44px 1fr; padding: 0 2px; }
  .tl-time { font-size: 12px; padding-top: 13px; }
  .tl-body { padding-left: 14px; }

  /* section headers wrap instead of overflowing */
  .card-head { flex-wrap: wrap; row-gap: 4px; }
  .card-head h3 { white-space: normal; }

  /* bottom tab bar */
  .mnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .mnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    border: none; background: none; color: var(--ink-3); font-size: 11px; font-weight: 600;
    padding: 6px 2px; border-radius: 10px; position: relative;
  }
  .mnav-item.on { color: var(--primary); }
  [data-theme="dark"] .mnav-item.on { color: var(--accent); }
  .mnav-badge {
    position: absolute; top: 2px; right: 22%; background: var(--c-gold); color: #1b150f;
    font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 99px;
    display: grid; place-items: center; padding: 0 4px;
  }

  /* "Plus" sheet */
  .msheet-scrim {
    display: block; position: fixed; inset: 0; z-index: 950;
    background: rgba(20,12,6,.4); opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .msheet-scrim.open { opacity: 1; pointer-events: auto; }
  .msheet {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 960;
    background: var(--surface); border-radius: 20px 20px 0 0;
    padding: 10px 14px calc(20px + env(safe-area-inset-bottom, 0px));
    transform: translateY(105%); transition: transform .26s cubic-bezier(.22,.61,.36,1);
    box-shadow: 0 -10px 40px rgba(0,0,0,.18);
  }
  .msheet.open { transform: translateY(0); }
  .msheet-grab { width: 40px; height: 4px; border-radius: 99px; background: var(--border-2); margin: 6px auto 12px; }
  .msheet-h { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 600; padding: 0 6px 8px; }
  .msheet-item { display: flex; align-items: center; gap: 12px; width: 100%; border: none; background: none; padding: 12px 8px; border-radius: 12px; color: var(--ink); font-size: 15px; font-weight: 600; }
  .msheet-item.on { background: var(--primary-soft); color: var(--primary); }
  [data-theme="dark"] .msheet-item.on { color: var(--accent); }
  .msheet-ic { width: 38px; height: 38px; border-radius: 11px; background: var(--surface-3); display: grid; place-items: center; color: var(--ink-2); flex: none; }
  .msheet-item.on .msheet-ic { background: var(--primary); color: #fff; }
  [data-theme="dark"] .msheet-item.on .msheet-ic { color: #1b150f; }
}

@media (max-width: 560px) {
  .content { padding: 14px; padding-bottom: 88px; }
  .tbl th, .tbl td { padding-left: 12px; padding-right: 12px; }
  /* top-of-view toolbars (title + action button) stack instead of overflowing */
  .view > .between { flex-wrap: wrap; }
}
