:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --border: #e5e5ea;
  --border-strong: #d2d2d7;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --text-soft: #86868b;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-width: 280px;
  --sidebar-collapsed: 68px;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --border: #2c2c2e;
  --border-strong: #3a3a3c;
  --text: #f5f5f7;
  --text-muted: #a1a1a6;
  --text-soft: #8e8e93;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  transition: background var(--transition), color var(--transition);
}

body.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed) 1fr;
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: width var(--transition);
}

.sidebar-header {
  padding: 18px 16px 8px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.hamburger {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border-radius: 8px;
  transition: background var(--transition);
  flex-shrink: 0;
}

.hamburger:hover {
  background: var(--surface-2);
}

.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform var(--transition);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #34c759, #0071e3);
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 18px;
  color: white;
  flex-shrink: 0;
}

.brand-text {
  white-space: nowrap;
}

.brand-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.2;
}

.nav-section {
  padding: 14px 10px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.nav-section:first-of-type {
  border-top: none;
  margin-top: 0;
}

.nav-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--text-soft);
  padding: 6px 10px 10px;
}

.nav-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background var(--transition);
  user-select: none;
}

.nav-section li:hover {
  background: var(--surface-2);
}

.nav-section li.active {
  background: var(--accent);
  color: white;
}

.nav-section li.active .count {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.nav-section li .label {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section li .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-soft);
  flex-shrink: 0;
}

.nav-section li .count {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-title,
body.sidebar-collapsed .nav-section li .label span:not(.dot),
body.sidebar-collapsed .nav-section li .count,
body.sidebar-collapsed .theme-label,
body.sidebar-collapsed .updated,
body.sidebar-collapsed .nav-section li .label {
  display: none;
}

body.sidebar-collapsed .sidebar-header {
  padding: 18px 12px 8px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-theme {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), border var(--transition);
}

.btn-theme:hover {
  background: var(--surface-2);
}

.theme-icon {
  font-size: 16px;
}

.updated {
  font-size: 11px;
  color: var(--text-soft);
  padding: 0 4px;
}

/* ============ MAIN ============ */
.main {
  padding: 32px 40px 60px;
  max-width: 1400px;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.topbar-left h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  font-size: 14px;
  color: var(--text-soft);
  pointer-events: none;
}

#searchInput {
  width: 320px;
  max-width: 100%;
  padding: 9px 32px 9px 34px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 10px;
  font-size: 14px;
  transition: border var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

#searchInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.search-clear {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
  display: none;
}

.search-clear:hover {
  background: var(--surface-2);
}

.search.has-value .search-clear {
  display: block;
}

.select {
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: border var(--transition);
}

.select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ============ KPIs ============ */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.kpi-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-soft);
}

/* ============ PROJECTS ============ */
.projects {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition),
    border-color var(--transition);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--status-color, var(--accent));
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.card-porteur {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 20px;
  background: var(--status-bg, rgba(0, 122, 255, 0.12));
  color: var(--status-color, var(--accent));
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.card-specs {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.spec {
  display: flex;
  flex-direction: column;
}

.spec-value {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.spec-label {
  font-size: 11px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 2px;
}

.card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.meta-row {
  display: flex;
  gap: 6px;
}

.meta-icon {
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

.meta-value {
  color: var(--text);
}

/* ============ EMPTY ============ */
.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.empty-title {
  font-size: 17px;
  margin-bottom: 16px;
}

.btn-secondary {
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition);
}

.btn-secondary:hover {
  background: var(--surface-2);
}

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn 150ms ease;
}

.modal-backdrop[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: slideUp 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: grid;
  place-items: center;
  transition: background var(--transition);
  z-index: 1;
}

.modal-close:hover {
  background: var(--border-strong);
}

.modal-body {
  padding: 28px 32px 32px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}

.modal-title-wrap {
  flex: 1;
  min-width: 0;
}

.modal-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 4px;
}

.modal-porteur {
  font-size: 14px;
  color: var(--text-muted);
}

.modal-section {
  margin-bottom: 22px;
}

.modal-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  font-weight: 600;
  margin-bottom: 10px;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
}

.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-soft);
  margin-bottom: 3px;
}

.field-value {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.field-value.empty-val {
  color: var(--text-soft);
  font-weight: 400;
  font-style: italic;
}

.notes {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.sources-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sources-list a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  transition: background var(--transition);
}

.sources-list a:hover {
  background: var(--border);
}

.source-icon {
  font-size: 12px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  body {
    grid-template-columns: var(--sidebar-collapsed) 1fr;
  }
  body .brand-text,
  body .nav-title,
  body .nav-section li .label,
  body .nav-section li .count,
  body .theme-label,
  body .updated {
    display: none;
  }
  .main {
    padding: 24px 20px 60px;
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  #searchInput {
    width: 100%;
  }
  .modal-body {
    padding: 22px 18px 26px;
  }
}
