/* ──────────────────────────────────────────────────
   FunnelRover — Design System
   main.css — all pages inherit from base.html
────────────────────────────────────────────────── */

/* DM Sans — auto-hébergé, pas de dépendance Google Fonts */
@font-face {
    font-family: 'DM Sans';
    src: url("../fonts/dm-sans-v17-latin-ext-normal.b9209b52c467.woff2") format('woff2');
    font-weight: 300 700;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'DM Sans';
    src: url("../fonts/dm-sans-v17-latin-normal.6c1e961057d2.woff2") format('woff2');
    font-weight: 300 700;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'DM Sans';
    src: url("../fonts/dm-sans-v17-latin-ext-italic.168f36adb1d7.woff2") format('woff2');
    font-weight: 300 700;
    font-style: italic;
    font-display: swap;
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'DM Sans';
    src: url("../fonts/dm-sans-v17-latin-italic.c0645a1b8188.woff2") format('woff2');
    font-weight: 300 700;
    font-style: italic;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* 1. RESET + VARIABLES */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange:      #E8621A;
  --orange-dark: #C4511A;
  --black:       #1A1A1A;
  --gray-text:   #6B6B6B;
  --gray-light:  #F5F5F5;
  --white:       #FFFFFF;
  --border:      #E8E8E8;
  --sidebar-w:   220px;
  --topbar-h:    56px;
  --font:        'DM Sans', sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--gray-light);
  color: var(--black);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

* { text-wrap: pretty; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: #D0D0D0; border-radius: 3px; }

a { color: inherit; }

/* 2. LAYOUT */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.app-sidebar {
  width: var(--sidebar-w);
  background: var(--black);
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  flex-shrink: 0;
}

.app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* 3. SIDEBAR */
.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-logo img {
  width: 140px;
  height: auto;
  display: block;
}

.sidebar-org {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sidebar-org-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s;
}

.sidebar-org-btn:hover {
  background: rgba(255,255,255,0.09);
  text-decoration: none;
}

.sidebar-org-avatar {
  width: 24px;
  height: 24px;
  background: var(--orange);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-org-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--white);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.sidebar-org-role {
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  white-space: nowrap;
}

.sidebar-nav {
  padding: 12px 10px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: all 0.12s;
  background: transparent;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
}

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.55);
  text-decoration: none;
}

.nav-item.active {
  background: var(--orange);
  color: var(--white);
  font-weight: 600;
}

.nav-item.active:hover {
  background: var(--orange);
  color: var(--white);
}

.nav-item svg { flex-shrink: 0; }

.nav-badge-active {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #22c55e;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-badge-upgrade {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 3px;
  background-color: rgba(249, 115, 22, 0.15);
  color: #F97316;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-item-locked span:not(.nav-badge-upgrade) {
  opacity: 0.45;
}

/* Sidebar — liens permanents bas */
.sidebar-bottom-links {
  margin-top: auto;
  padding: 8px;
  border-top: 0.5px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-bottom-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.sidebar-bottom-link:hover,
.sidebar-bottom-link.active {
  background: rgba(255,255,255,0.08);
  color: #fff;
  text-decoration: none;
}

.sidebar-bottom-link svg { flex-shrink: 0; }

.sidebar-bottom-link--danger { color: rgba(255,255,255,0.4); }
.sidebar-bottom-link--danger:hover {
  background: rgba(239,68,68,0.1);
  color: #ef4444;
}

/* 4. TOPBAR */
.topbar-title-group { flex: 1; min-width: 0; }

/* Page-level action buttons. On desktop they sit at the right of the topbar
   (pushed there by the flex:1 title group); on mobile they wrap to their own
   row (see the responsive block). Collapsed entirely on pages with no actions. */
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-actions:empty { display: none; }

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--black);
}

.topbar-subtitle {
  font-size: 12px;
  color: var(--gray-text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-bell {
  position: relative;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  margin-left: 4px;
  color: var(--gray-text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.topbar-bell:hover { color: var(--orange); }

.notification-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #EF4444;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
  border: 2px solid var(--white);
}

.topbar-avatar {
  width: 32px;
  height: 32px;
  background: var(--black);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
}

.topbar-avatar:hover { text-decoration: none; opacity: 0.85; }

/* 5. BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.12s;
  text-decoration: none;
  border: none;
  flex-shrink: 0;
  line-height: 1;
}

.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--orange);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--orange-dark);
  color: var(--white);
}

.btn-secondary {
  background: var(--white);
  color: var(--black);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--gray-light);
  color: var(--black);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-danger {
  background: #FEE2E2;
  color: #DC2626;
  border: 1px solid #FECACA;
}

.btn-danger:hover {
  background: #FECACA;
  color: #DC2626;
}

/* 6. CARDS */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--black);
}

.card-subtitle {
  font-size: 12px;
  color: var(--gray-text);
  margin-top: 2px;
}

/* Stat cards */
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
}

.stat-card-label {
  font-size: 12px;
  color: var(--gray-text);
  font-weight: 500;
  margin-bottom: 6px;
}

.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--black);
  line-height: 1;
}

.stat-card-sub {
  font-size: 12px;
  color: var(--gray-text);
  margin-top: 6px;
}

.stat-card-sub.trend-up { color: #39B54A; }
.stat-card-sub.trend-down { color: #DC2626; }

/* 7. BADGES */
.badge-ai {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #FFF3EE;
  color: var(--orange);
  border: 1px solid #FDDAC8;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  letter-spacing: 0.3px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-success { background: #DCFCE7; color: #16A34A; }
.badge-warning { background: #FEF9C3; color: #D97706; }
.badge-danger  { background: #FEE2E2; color: #DC2626; }
.badge-info    { background: #EFF8FF; color: #2D7DD2; }
.badge-neutral { background: var(--gray-light); color: var(--gray-text); }
.badge-orange  { background: #FFF3EE; color: var(--orange); }

/* Score badges */
.score-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.score-high   { background: #DCFCE7; color: #16A34A; }
.score-medium { background: #FEF9C3; color: #D97706; }
.score-low    { background: #FEE2E2; color: #DC2626; }

/* 8. FORMS */
.form-group { margin-bottom: 16px; }

label, .form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--black);
  margin-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  background: var(--white);
  color: var(--black);
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--orange);
}

textarea { resize: vertical; min-height: 80px; }

.form-hint {
  font-size: 12px;
  color: var(--gray-text);
  margin-top: 4px;
}

.form-error {
  font-size: 12px;
  color: #DC2626;
  margin-top: 4px;
}

.errorlist {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.errorlist li {
  font-size: 12px;
  color: #DC2626;
}

/* 9. TABLES */
table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--black);
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-light); }
tr.row-active td { background: #FFFBF5; }

.table-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* 10. DJANGO MESSAGES */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }

.messages li {
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 8px;
}

.messages .success { background: #DCFCE7; color: #16A34A; border: 1px solid #BBF7D0; }
.messages .error   { background: #FEE2E2; color: #DC2626; border: 1px solid #FECACA; }
.messages .warning { background: #FEF9C3; color: #D97706; border: 1px solid #FDE68A; }
.messages .info    { background: #EFF8FF; color: #2D7DD2; border: 1px solid #BFDBFE; }

/* 10b. ALERT BANNERS */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.5;
}
.alert-warning { background: #FEF9C3; color: #D97706; border: 1px solid #FDE68A; }
.alert-info    { background: #EFF8FF; color: #2D7DD2; border: 1px solid #BFDBFE; }

/* 11. GRID UTILITIES */
.grid-4   { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid-3   { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-2   { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; }

/* 12. FLEX UTILITIES */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col     { display: flex; flex-direction: column; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* 13. TEXT UTILITIES */
.text-sm     { font-size: 12px; }
.text-xs     { font-size: 11px; }
.text-muted  { color: var(--gray-text); }
.text-orange { color: var(--orange); }
.font-bold     { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium   { font-weight: 500; }

/* 14. SPACING UTILITIES */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }

/* 15. PAGINATION */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

.page-link {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  color: var(--black);
  text-decoration: none;
  background: var(--white);
}

.page-link:hover {
  background: var(--gray-light);
  text-decoration: none;
}

.page-link.active {
  background: var(--orange);
  color: var(--white);
  border-color: var(--orange);
}

/* 16. EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-text);
}

.empty-state-icon  { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--black); margin-bottom: 6px; }
.empty-state-text  { font-size: 13px; color: var(--gray-text); margin-bottom: 20px; }

/* 17. PROGRESS BAR */
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }

.progress-fill  { height: 100%; border-radius: 2px; background: var(--orange); transition: width 0.3s; }
.progress-green  { background: #39B54A; }
.progress-yellow { background: #F59E0B; }

/* 18. ACTIVITY FEED */
.activity-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child { border-bottom: none; }

.activity-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--gray-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-text);
}

.activity-avatar.ai { background: #FFF3EE; color: var(--orange); }
.activity-avatar.visit { background: #EFF8FF; color: #2D7DD2; }

.activity-action { font-size: 12px; color: var(--black); line-height: 1.4; }
.activity-time   { font-size: 11px; color: var(--gray-text); margin-top: 2px; }

/* 19. SEARCH BAR */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
}

.search-bar:focus-within { border-color: var(--orange); }

.search-bar input {
  border: none;
  outline: none;
  font-size: 13px;
  font-family: var(--font);
  color: var(--black);
  background: transparent;
  width: 100%;
  padding: 0;
}

/* 20. FILTER BAR */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar .search-bar { flex: 1; min-width: 200px; }

/* 21. UNIFIED APP SUBNAV */
.app-subnav {
  display: flex;
  gap: 2px;
  padding: 0 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.app-subnav::-webkit-scrollbar { display: none; }
.app-subnav-item {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-text);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color .12s, border-color .12s;
}
.app-subnav-item:hover { color: var(--orange); text-decoration: none; }
.app-subnav-item.active { color: var(--orange); border-bottom-color: var(--orange); font-weight: 600; }
.app-subnav-item.disabled { color: var(--border); cursor: default; pointer-events: none; }

/* Level-2 pills (section sub-navigation) */
.app-subnav-pills {
  display: flex;
  gap: 4px;
  margin: 16px 0 8px;
  flex-wrap: wrap;
}
.app-subnav-pill {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 20px;
  text-decoration: none;
  color: var(--gray-text);
  background: var(--gray-light);
  transition: all .12s;
}
.app-subnav-pill.active { background: var(--orange); color: #fff; }
.app-subnav-pill:hover:not(.active) { background: var(--border); color: var(--black); text-decoration: none; }

/* ===================================================================
   22. MOBILE / RESPONSIVE — app shell pages (Phase 2)
   The app shell (sidebar -> drawer) is handled in templates/base.html.
   Here: content density, wide tables, and stacking grids.
   =================================================================== */
@media (max-width: 860px) {
  .app-content { padding: 16px 12px; }

  /* Topbar wraps: row 1 = menu toggle + title + bell + avatar, row 2 = page
     action buttons (full width, right-aligned). Fixes the actions overlapping
     the title/subtitle on narrow screens. */
  .app-topbar  { flex-wrap: wrap; height: auto; min-height: var(--topbar-h); padding: 8px 12px; gap: 10px; }
  .topbar-actions { order: 3; flex-basis: 100%; justify-content: flex-end; }

  /* Section navigation wraps to multiple lines instead of scrolling
     horizontally, so every section is visible at once (level 2 already wraps). */
  .app-subnav { flex-wrap: wrap; overflow-x: visible; }

  /* Wide data tables scroll horizontally inside their card. Cards are
     auto-height, so this only ever adds a horizontal scrollbar, never a
     vertical one. No template change needed. */
  .card { overflow-x: auto; }

  /* Stacking grids: 2-up on tablet/large phone, then 1-up below. */
  .grid-4, .grid-3            { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .grid-4, .grid-3 { grid-template-columns: 1fr; }
}
