/* TubeFactory — thème sombre industriel */

:root {
  --bg: #0f1419;
  --bg-card: #161b22;
  --bg-hover: #21262d;
  --border: #30363d;
  --text: #e7ecf1;
  --text-muted: #8b949e;
  --accent: #ff6b6b;
  --accent-hover: #ff8787;
  --blue: #58a6ff;
  --green: #3fb950;
  --yellow: #d29922;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Login --- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-box h1 {
  color: var(--accent);
  font-size: 1.6rem;
  margin-bottom: 0.25rem;
}

.login-box .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

/* --- Layout principal --- */
.app { display: none; }
.app.visible { display: block; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  padding-top: max(0.65rem, env(safe-area-inset-top));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 120;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.topbar-title {
  color: var(--accent);
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.topbar-filter {
  max-width: 140px;
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
}

/* Bouton hamburger */
.btn-menu {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-menu-bar {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  background: var(--text);
  border-radius: 1px;
  transition: transform .2s, opacity .2s;
}

.btn-menu.open .btn-menu-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.btn-menu.open .btn-menu-bar:nth-child(2) { opacity: 0; }
.btn-menu.open .btn-menu-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Bulle profil avec initiales */
.profile-wrap {
  position: relative;
}

.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: linear-gradient(135deg, #2d333b, #21262d);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, box-shadow .15s;
}

.profile-avatar:hover,
.profile-avatar:focus {
  transform: scale(1.05);
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.25);
  outline: none;
}

.profile-avatar.admin {
  border-color: var(--blue);
  background: linear-gradient(135deg, #1a3050, #21262d);
}

/* Menu déroulant profil */
.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 150;
  overflow: hidden;
}

.nav-admin-only[hidden],
.profile-menu-item[hidden],
.admin-card[hidden] { display: none !important; }

.profile-menu[hidden] { display: none !important; }

.profile-menu-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.profile-menu-header span:first-child {
  font-weight: 600;
  font-size: 0.9rem;
}

.profile-menu-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.profile-menu-item {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  font-size: 0.9rem;
  cursor: pointer;
}

.profile-menu-item:hover { background: var(--bg-hover); }
.profile-menu-logout { color: #f85149; }

/* Navigation */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 109;
}

.nav-overlay.visible { display: block; }

.nav {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  min-height: 44px;
}

.nav button:hover { color: var(--text); }
.nav button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.nav-admin-only[hidden],
.profile-menu-item[hidden],
.admin-card[hidden] { display: none !important; }

/* Carte admin sur le profil */
.admin-card {
  border-color: var(--blue);
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.08), var(--bg-card));
}

.main {
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* --- Composants communs --- */
h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.stat-card .number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-hover);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background .15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: var(--border); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ai {
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  border-color: #6c5ce7;
  color: #fff;
}
.btn-ai:hover { filter: brightness(1.08); }
.btn-ai:disabled { opacity: 0.6; cursor: wait; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-danger { border-color: #f85149; color: #f85149; }

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
}

textarea { min-height: 100px; resize: vertical; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.filter-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filter-bar select { width: auto; min-width: 140px; flex: 1; }

/* --- Tableaux responsive --- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card > .table-wrap,
.card[style*="padding:0"] {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:hover td { background: var(--bg-hover); }

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-draft { background: #21262d; color: var(--text-muted); }
.badge-valid { background: #1a3a2a; color: var(--green); }
.badge-prod { background: #2a2a1a; color: var(--yellow); }
.badge-done { background: #1a2a3a; color: var(--blue); }
.badge-archived { background: #2a1a1a; color: #f85149; }

.priority-1 { color: #f85149; }
.priority-2 { color: var(--yellow); }
.priority-3 { color: var(--text-muted); }

/* --- Kanban --- */
.kanban {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 1rem;
}

.kanban-col {
  min-width: 220px;
  max-width: 260px;
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
}

.kanban-col-header {
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.kanban-col-header .count {
  background: var(--bg-hover);
  padding: 0 0.4rem;
  border-radius: 10px;
  font-size: 0.75rem;
}

.kanban-cards {
  padding: 0.5rem;
  flex: 1;
  min-height: 120px;
}

.kanban-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: border-color .15s;
}

.kanban-card:hover { border-color: var(--accent); }
.kanban-card-content { cursor: pointer; }
.kanban-card-content:active { opacity: 0.85; }
.kanban-card .title { font-size: 0.85rem; font-weight: 500; }
.kanban-card .channel { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }
.kanban-card .actions {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.4rem;
}

/* --- Modale --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.1rem; }
.modal-body { padding: 1.25rem; }
.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover { color: var(--text); }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.error-msg {
  color: #f85149;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.card-subtitle {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

/* --- Listes responsive (cartes mobile / tableau desktop) --- */
.list-container {
  padding: 0;
  overflow: visible;
}

.mobile-cards {
  display: none;
  padding: 0.75rem;
}

.cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.item-card:last-child { margin-bottom: 0; }

.item-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  word-break: break-word;
}

.item-card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.item-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.item-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.item-card-actions .btn {
  flex: 1;
  justify-content: center;
  min-width: 110px;
}

.item-card-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.2rem 0;
}

.item-card-row span:first-child {
  color: var(--text-muted);
  flex-shrink: 0;
}

.td-actions {
  white-space: nowrap;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* Production mobile : liste verticale par étape */
.production-step {
  margin-bottom: 1.25rem;
}

.production-step-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.production-step-count {
  background: var(--bg-hover);
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  font-size: 0.75rem;
}

.template-card .item-card-actions { margin-top: 0.5rem; }

.template-preview {
  white-space: pre-wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
  max-height: 100px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.overdue { color: #f85149; font-weight: 500; }

/* ============================================
   RESPONSIVE — Mobile (< 768px)
   ============================================ */
@media (max-width: 767px) {
  .btn-menu { display: flex; }

  .topbar-filter {
    max-width: 110px;
    font-size: 0.75rem;
  }

  .topbar-title { font-size: 1rem; }

  /* Menu latéral (drawer) */
  .nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 85vw);
    flex-direction: column;
    gap: 0;
    padding: 4.5rem 0 1rem;
    border-bottom: none;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 110;
    overflow-y: auto;
  }

  .nav.open { transform: translateX(0); }

  .nav button {
    width: 100%;
    text-align: left;
    padding: 0.9rem 1.25rem;
    border-bottom: none;
    border-left: 3px solid transparent;
    font-size: 1rem;
  }

  .nav button.active {
    border-bottom-color: transparent;
    border-left-color: var(--accent);
    background: var(--bg-hover);
  }

  .main { padding: 1rem 0.75rem; }

  h2 { font-size: 1.15rem; }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }

  .stat-card { padding: 1rem 0.75rem; }
  .stat-card .number { font-size: 1.6rem; }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar h2 { margin-bottom: 0; }

  .filter-bar {
    width: 100%;
  }

  .filter-bar select {
    min-width: 0;
    flex: 1;
  }

  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }

  .kanban-col { min-width: 85vw; max-width: 85vw; }

  .modal {
    max-height: 95vh;
    border-radius: var(--radius) var(--radius) 0 0;
    align-self: flex-end;
  }

  .modal-overlay.open {
    align-items: flex-end;
    padding: 0;
  }

  .login-box { padding: 1.5rem; }

  /* Mobile : cartes visibles, tableaux et kanban masqués */
  .mobile-cards { display: block; }
  .desktop-table-wrap { display: none; }
  .desktop-kanban { display: none !important; }
  .production-mobile { display: block; }
}

/* Desktop — barre nav horizontale visible */
@media (min-width: 768px) {
  .topbar { padding: 0.75rem 1.5rem; }
  .topbar-title { font-size: 1.25rem; }
  .topbar-filter { max-width: 200px; }

  .nav-overlay { display: none !important; }

  .production-mobile { display: none; }
  .desktop-kanban { display: flex; }
}

/* Très petits écrans */
@media (max-width: 380px) {
  .topbar-filter { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
