/* =========================================================
   SUIVI PRO - Styles Mobile-First PWA (Constructeur Bois)
   ========================================================= */

:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --accent: #f59e0b;
  --accent-strong: #d97706;
  --accent-text: #0f172a;
  --success: #10b981;
  --danger: #ef4444;
  --info: #38bdf8;
  --extra-bg: rgba(249, 115, 22, 0.22);
  --extra-border: #f97316;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
}

html[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #cbd5e1;
  --accent: #d97706;
  --accent-strong: #b45309;
  --accent-text: #ffffff;
  --success: #059669;
  --danger: #dc2626;
  --info: #0284c7;
  --extra-bg: rgba(249, 115, 22, 0.16);
  --extra-border: #ea580c;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

body.modal-open {
  overflow: hidden;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.network-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.network-badge.online {
  background: rgba(16, 185, 129, 0.18);
  color: var(--success);
}

.network-badge.offline {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* Main container */
.main-content {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Buttons */
.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, opacity 0.15s ease, background-color 0.15s ease;
  user-select: none;
}

.btn:active,
.icon-btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-lg {
  min-height: 52px;
  padding: 12px 18px;
  font-size: 1rem;
}

.btn-md {
  min-height: 46px;
  padding: 10px 16px;
  font-size: 0.95rem;
}

.btn-sm {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 1.2rem;
  background: var(--bg-input);
  color: var(--text);
  border-color: var(--border);
}

.file-btn {
  position: relative;
  overflow: hidden;
}

/* Home actions */
.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 560px) {
  .home-actions {
    grid-template-columns: 1fr;
  }
}

/* Search & Filter */
.search-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.search-icon {
  position: absolute;
  left: 14px;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px 10px 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1rem;
}

.filter-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.pill {
  min-height: 42px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* Cards & Chantier List */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.chantiers-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chantier-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.chantier-card:hover {
  border-color: var(--accent);
}

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

.chantier-card-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

.chantier-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-preparer {
  background: rgba(56, 189, 248, 0.2);
  color: var(--info);
}

.status-encours {
  background: rgba(245, 158, 11, 0.22);
  color: var(--accent);
}

.status-termine {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.8rem;
  margin-bottom: 10px;
}

/* Chantier Detail Header */
.chantier-header-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.detail-top-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.detail-client-name {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
}

.detail-ref-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.detail-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 4 Main Tabs */
.main-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 640px) {
  .main-tabs {
    grid-template-columns: repeat(2, 1fr);
  }
}

.main-tab {
  min-height: 50px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
}

.main-tab.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Photos Tab */
.folder-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.folder-tab {
  min-height: 48px;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

.folder-tab.active {
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.16);
  color: var(--accent);
}

.count-badge {
  background: var(--border);
  color: var(--text);
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 999px;
}

.photo-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 480px) {
  .photo-actions-grid {
    grid-template-columns: 1fr;
  }
}

.sync-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.photo-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
}

.photo-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}

.photo-card-footer {
  padding: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.sync-badge {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
}

.sync-badge.local {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent);
}

.sync-badge.drive {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
}

/* Docs Tab */
.doc-upload-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

@media (max-width: 560px) {
  .doc-upload-row {
    grid-template-columns: 1fr;
  }
}

.docs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.doc-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.doc-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Checklists & Journal */
.checklists-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-header {
  margin-bottom: 10px;
}

.card-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

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

.quick-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-add-form .input {
  flex: 1;
}

.quick-add-task {
  flex-wrap: wrap;
}

.date-input {
  max-width: 165px;
}

.checklist-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checklist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.checklist-label {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  cursor: pointer;
  min-height: 28px;
}

.checklist-label input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.checklist-item.done .item-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.item-date {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 700;
  margin-left: 6px;
}

/* Journal Notes */
.note-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.note-form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.extra-checkbox,
.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.extra-checkbox input,
.toggle-chip input {
  width: 20px;
  height: 20px;
  accent-color: #f97316;
}

.journal-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.journal-note {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.journal-note.is-extra {
  background: var(--extra-bg);
  border: 2px solid var(--extra-border);
}

.journal-note-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.extra-pill {
  background: #f97316;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
}

.journal-note-body {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Forms & Inputs */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 520px) {
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

.field-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.textarea {
  min-height: 84px;
  resize: vertical;
}

.muted-text {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.agenda-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 560px) {
  .agenda-actions {
    grid-template-columns: 1fr;
  }
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 6, 23, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-backdrop.modal-fullscreen {
  padding: 0;
}

.modal-dialog {
  width: 100%;
  max-width: 580px;
  max-height: 92dvh;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.paste-quote-box {
  background: var(--bg-input);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.paste-quote-box summary {
  font-weight: 700;
  cursor: pointer;
  color: var(--accent);
}

.paste-quote-inner {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Camera & Annotation Fullscreen */
.camera-dialog,
.preview-dialog {
  width: 100%;
  height: 100dvh;
  background: #020617;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
}

.camera-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: #0f172a;
  border-bottom: 1px solid #334155;
}

.badge-pill {
  margin-left: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #d97706;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
}

.cam-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

#cam-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000000;
}

.cam-controls {
  position: absolute;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
}

.shutter-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 5px solid #ffffff;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.shutter-btn span {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #ffffff;
}

.annotate-toolbar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  background: #0f172a;
  border-bottom: 1px solid #334155;
}

.tool-btn {
  min-height: 42px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #f8fafc;
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  cursor: pointer;
}

.tool-btn.active {
  background: #f59e0b;
  color: #0f172a;
  border-color: #f59e0b;
}

.canvas-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: #000000;
}

#cam-canvas {
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
  border-radius: 6px;
}

.text-prompt-bar {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: #1e293b;
  border-top: 1px solid #334155;
}

.annotate-footer {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  padding: 10px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: #0f172a;
  border-top: 1px solid #334155;
}

.alert-error {
  margin: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.22);
  border: 1px solid #ef4444;
  color: #fecaca;
}

/* Preview modal */
.preview-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: auto;
}

.preview-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.preview-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  border-radius: 8px;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-switch-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 440px);
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #475569;
  font-weight: 700;
  box-shadow: var(--shadow);
  text-align: center;
}

.toast.success {
  border-color: var(--success);
  background: #064e3b;
}

.toast.error {
  border-color: var(--danger);
  background: #7f1d1d;
}
