/* ===== Variables ===== */
:root {
  --sidebar-width: 270px;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-text-hover: #f1f5f9;
  --sidebar-active-bg: rgba(59,130,246,0.15);
  --sidebar-active-text: #60a5fa;
  --content-bg: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
}

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

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--content-bg);
  color: var(--text);
}

a { color: inherit; }

/* ===== App layout ===== */
#app {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #f1f5f9;
  margin: 0;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.sidebar-brand .subtitle {
  font-size: .68rem;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: .2rem;
}

.sidebar-search {
  padding: .75rem 1rem;
}
.sidebar-search input {
  width: 100%;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 7px;
  color: #f1f5f9;
  padding: .45rem .75rem;
  font-size: .85rem;
  outline: none;
  transition: border-color .2s;
}
.sidebar-search input:focus { border-color: var(--primary); }
.sidebar-search input::placeholder { color: var(--sidebar-text); }

.sidebar-section { padding: .3rem 0; }

.sidebar-section-title {
  font-size: .64rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-text);
  padding: .5rem 1.25rem .2rem;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .45rem .75rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .865rem;
  border-radius: 6px;
  margin: .1rem .5rem;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.sidebar-nav-item:hover {
  color: var(--sidebar-text-hover);
  background: rgba(255,255,255,.06);
  text-decoration: none;
}
.sidebar-nav-item.active {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
}
.sidebar-nav-item i { font-size: 1rem; width: 1.1rem; text-align: center; }

/* Interrupteur du mode sombre : forcer une taille visible dans la sidebar */
.dark-mode-switch { padding-left: 0; }
.dark-mode-switch .form-check-input {
  width: 2.4em !important;
  height: 1.2em;
  min-width: 2.4em;
  margin-left: 0;
  cursor: pointer;
  flex-shrink: 0;
  background-color: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.3);
}
.dark-mode-switch .form-check-input:checked {
  background-color: #3b82f6;
  border-color: #3b82f6;
}

.category-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.07);
}
.user-info {
  display: flex;
  align-items: center;
  gap: .7rem;
  margin-bottom: .75rem;
}
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}
.user-name { font-size: .85rem; font-weight: 500; color: #f1f5f9; }
.user-role { font-size: .7rem; color: var(--sidebar-text); }

/* ===== Main content ===== */
#content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.page-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
}
.page-header .actions { display: flex; gap: .5rem; align-items: center; }

.page-body { padding: 1.75rem; flex: 1; }

/* ===== Hamburger (mobile) ===== */
#menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text);
  cursor: pointer;
  padding: 0 .5rem 0 0;
}

/* ===== Procedure cards ===== */
.procedure-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  height: 100%;
  text-decoration: none;
  color: inherit;
  transition: box-shadow .18s, border-color .18s, transform .1s;
}
.procedure-card:hover {
  box-shadow: 0 6px 24px rgba(0,0,0,.09);
  border-color: var(--primary);
  transform: translateY(-1px);
  color: inherit;
  text-decoration: none;
}
.card-title {
  font-size: .97rem;
  font-weight: 600;
  margin: .4rem 0 .45rem;
  line-height: 1.4;
  color: var(--text);
}
.card-summary {
  font-size: .83rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: .65rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}
.card-footer {
  font-size: .73rem;
  color: var(--text-muted);
  margin-top: .5rem;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ===== Category badge ===== */
.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

/* ===== Tags ===== */
.tag {
  display: inline-block;
  font-size: .7rem;
  padding: 2px 7px;
  border-radius: 4px;
  background: #e2e8f0;
  color: #475569;
  margin: 2px;
}

/* Tags input widget */
.tags-field {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  border: 1px solid #ced4da;
  border-radius: .375rem;
  padding: .4rem .6rem;
  background: white;
  min-height: 42px;
  cursor: text;
  transition: border-color .15s, box-shadow .15s;
}
.tags-field.focused {
  border-color: #86b7fe;
  box-shadow: 0 0 0 .25rem rgba(13,110,253,.25);
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e2e8f0;
  color: #374151;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: .8rem;
}
.tag-chip button {
  background: none; border: none; padding: 0;
  cursor: pointer; color: #6b7280; line-height: 1;
  display: flex; align-items: center; font-size: .7rem;
}
.tag-chip button:hover { color: #ef4444; }
.tags-input {
  border: none; outline: none;
  flex: 1; min-width: 80px;
  font-size: .875rem; padding: 0;
  background: transparent;
}

/* ===== Markdown content ===== */
.prose {
  line-height: 1.75;
  color: var(--text);
  max-width: none;
}
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 600;
  margin-top: 1.6em;
  margin-bottom: .5em;
}
.prose h1 { font-size: 1.7rem; border-bottom: 2px solid var(--border); padding-bottom: .4rem; }
.prose h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: .25rem; }
.prose h3 { font-size: 1.05rem; }
.prose p { margin-bottom: 1em; }
.prose ul, .prose ol { padding-left: 1.5rem; margin-bottom: 1em; }
.prose li { margin-bottom: .3em; }
.prose code {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .875em;
  font-family: 'Fira Code', Consolas, monospace;
  color: #e11d48;
}
.prose pre {
  background: #1e293b;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1em;
}
.prose pre code {
  background: none; border: none; padding: 0;
  color: #e2e8f0; font-size: .875rem;
}
.prose blockquote {
  border-left: 4px solid var(--primary);
  margin: 0 0 1em;
  padding: .5rem 1rem;
  background: #f0f9ff;
  border-radius: 0 8px 8px 0;
  color: #0369a1;
}
.prose table { width: 100%; border-collapse: collapse; margin-bottom: 1em; }
.prose th, .prose td { border: 1px solid var(--border); padding: .45rem .7rem; }
.prose th { background: #f8fafc; font-weight: 600; }
.prose hr { border: none; border-top: 2px solid var(--border); margin: 1.5em 0; }
.prose img { max-width: 100%; border-radius: 6px; }
.prose a { color: var(--primary); text-decoration: underline; }

/* ===== Editor ===== */
.editor-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: 520px;
}
.editor-pane, .preview-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pane-header {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: .4rem 1rem;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.editor-textarea {
  flex: 1; width: 100%;
  border: none; outline: none; resize: none;
  padding: 1rem;
  font-family: 'Fira Code', Consolas, monospace;
  font-size: .875rem;
  line-height: 1.6;
}
.preview-body {
  flex: 1; overflow-y: auto;
  padding: 1rem 1.25rem;
}

/* ===== Login ===== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}
.login-card {
  background: white;
  border-radius: 14px;
  padding: 2.5rem 2rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 30px 60px rgba(0,0,0,.35);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo i { font-size: 3rem; color: var(--primary); }
.login-logo h1 { font-size: 1.45rem; font-weight: 700; margin-top: .5rem; }
.login-logo p { color: var(--text-muted); font-size: .875rem; margin: 0; }

/* ===== Procedure info bar ===== */
.proc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.proc-meta i { margin-right: 3px; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-state i { font-size: 4rem; display: block; opacity: .25; margin-bottom: 1rem; }
.empty-state p { font-size: 1rem; }

/* ===== Salon selector ===== */
.salon-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 3rem 1rem;
}
.salon-selector-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2.5rem;
  text-align: center;
  letter-spacing: .02em;
}
.salon-cards-grid {
  display: flex;
  gap: 2.5rem;
  flex-wrap: wrap;
  justify-content: center;
}
.salon-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 2.5rem 2.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all .22s ease;
  min-width: 230px;
  max-width: 300px;
  height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
  user-select: none;
  position: relative;
}
.salon-card-delete {
  position: absolute;
  top: .65rem; right: .65rem;
  background: none; border: none;
  color: #ef4444; font-size: .85rem;
  cursor: pointer; padding: .3rem;
  border-radius: 6px; opacity: 0;
  transition: opacity .18s, background .15s;
  line-height: 1;
}
.salon-card:hover .salon-card-delete { opacity: 1; }
.salon-card-delete:hover { background: #fee2e2; }
.salon-card:hover {
  border-color: var(--primary);
  box-shadow: 0 20px 56px rgba(59,130,246,.18);
  transform: translateY(-7px);
}
.salon-card img {
  max-height: 160px;
  max-width: 210px;
  object-fit: contain;
  flex: 1;
  margin-bottom: 1.25rem;
}
.salon-card-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-top: auto;
}
.salon-card-count {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .35rem;
}

/* ===== Site tabs mini ===== */
.site-tab-logo {
  height: 22px;
  object-fit: contain;
  margin-right: 6px;
  vertical-align: middle;
}
#site-tabs .nav-link {
  color: var(--text-muted);
  background: none;
  border: 2px solid transparent;
  border-radius: 8px;
}
#site-tabs .nav-link:hover {
  color: var(--primary);
  border-color: #bfdbfe;
  background: none;
}
#site-tabs .nav-link.active {
  color: var(--primary);
  background: none;
  border-color: var(--primary);
  font-weight: 600;
}

/* ===== Toast ===== */
.toast-container-fixed {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 9999;
}

/* ===== Overlay (mobile) ===== */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
}
#sidebar-overlay.show { display: block; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #content { margin-left: 0; }
  #menu-toggle { display: block; }
  .editor-wrap { grid-template-columns: 1fr; height: auto; }
  .editor-pane, .preview-pane { height: 300px; }
  .page-body { padding: 1rem; }
  .page-header { padding: .85rem 1rem; }
}

/* ===== Mode sombre ===== */
[data-bs-theme="dark"] {
  --content-bg: #0f172a;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
}
[data-bs-theme="dark"] body { background: var(--content-bg); }
[data-bs-theme="dark"] .page-header,
[data-bs-theme="dark"] .procedure-card,
[data-bs-theme="dark"] .tags-field {
  background: #1e293b;
  border-color: var(--border);
}
[data-bs-theme="dark"] .tag,
[data-bs-theme="dark"] .tag-chip {
  background: #334155;
  color: #cbd5e1;
}
[data-bs-theme="dark"] .table-light {
  --bs-table-bg: #1e293b;
  --bs-table-color: #e2e8f0;
  --bs-table-border-color: var(--border);
}
[data-bs-theme="dark"] .table > thead th,
[data-bs-theme="dark"] .table-light th {
  color: #cbd5e1;
}

/* ===== RESPONSIVE IMPROVEMENTS ===== */

/* Tables responsive on mobile */
.table-responsive {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}
.table { margin-bottom: 0; width: 100%; }

/* Automatic table wrapping */
@media (max-width: 768px) {
  .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table thead, .table tbody, .table tr, .table td {
    display: block;
  }
  .table thead { display: none; }
  .table tr { margin-bottom: 1rem; border: 1px solid var(--border); }
  .table td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    border: none;
  }
  .table td::before {
    content: attr(data-label);
    font-weight: bold;
    min-width: 120px;
  }
}

/* Sidebar collapse on mobile */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  #sidebar {
    transform: translateX(-100%);
    z-index: 1000;
    position: fixed;
    width: 270px;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.show { transform: translateX(0); }
  #sidebar-overlay { display: none; background: rgba(0,0,0,0.5); position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 999; }
  #sidebar-overlay.show { display: block; }
  #content { margin-left: 0 !important; }
  .main-header { margin-left: 0 !important; }
  .page-content { margin-left: 0 !important; }
}

/* Main content responsive */
#content {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left .25s ease;
  overflow: auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Page header responsive */
.page-header {
  padding: 1.5rem;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-body {
  flex: 1;
  padding: 1.5rem;
  overflow: auto;
}

/* Mobile-friendly modals */
@media (max-width: 576px) {
  .modal-dialog { margin: 0.5rem; }
  .modal-dialog.modal-lg { max-width: calc(100% - 1rem); }
  .modal-dialog.modal-xl { max-width: calc(100% - 1rem); }
  .modal-body { max-height: calc(100vh - 200px); overflow-y: auto; }
}

/* Flexible forms on mobile */
@media (max-width: 768px) {
  .form-control, .form-select, input[type="text"],
  input[type="email"], input[type="password"],
  input[type="search"], textarea {
    font-size: 16px; /* Prevent zoom on iOS */
  }
  .row > [class*="col-"] {
    min-width: 100%;
  }
  .row.g-3 > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* Card responsive spacing */
@media (max-width: 768px) {
  .card { margin-bottom: 1rem; }
  .card-body { padding: 1rem; }
}

/* Badge and button responsive */
@media (max-width: 576px) {
  .btn { padding: 0.375rem 0.75rem; font-size: 0.875rem; }
  .badge { padding: 0.25em 0.5em; }
}

/* Flex utilities for mobile */
@media (max-width: 768px) {
  .d-flex { flex-direction: column; }
  .flex-wrap { flex-wrap: wrap; }
  .gap-2 > *, .gap-2 { gap: 0.5rem !important; }
  .gap-3 > *, .gap-3 { gap: 0.75rem !important; }
}

/* Text responsive */
@media (max-width: 576px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.1rem; }
  .small { font-size: 0.8rem; }
}

/* Input styles for mobile */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
textarea,
select {
  width: 100%;
  max-width: 100%;
}

/* Navbar/header mobile */
.navbar { flex-wrap: wrap; }
@media (max-width: 576px) {
  .navbar { padding: 0.5rem 0; }
  .navbar-brand { font-size: 1rem; }
}

/* Overflow prevention */
body { overflow-x: hidden; }
* { max-width: 100%; }

/* Scrollable containers */
.table-responsive,
.list-group {
  max-width: 100%;
  overflow: auto;
}

/* Touch-friendly spacing on mobile */
@media (max-width: 768px) {
  button, a.btn, [role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 1rem;
  }
}

/* Extra-small screens */
@media (max-width: 576px) {
  #content { padding: 0; }
  .page-header { padding: 1rem; }
  .page-body { padding: 1rem; }
  .container-fluid { padding-left: 0.5rem; padding-right: 0.5rem; }
  .card { margin-bottom: 0.75rem; }
  .card-body { padding: 0.75rem; }
  .badge { font-size: 0.75rem; }
  .row { margin-left: -0.25rem; margin-right: -0.25rem; }
  .col { padding-left: 0.25rem; padding-right: 0.25rem; }
}

/* Ensure no horizontal scroll */
@media (max-width: 768px) {
  body, html {
    overflow-x: hidden;
    width: 100%;
  }
  main { width: 100%; overflow-x: hidden; }
  .container, .container-fluid { width: 100%; padding: 0; }
}

/* Navigation pills responsive */
@media (max-width: 768px) {
  .nav-pills {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .nav-pills .nav-link {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }
}

/* Modal responsive */
@media (max-width: 576px) {
  .modal-dialog {
    max-width: none;
    width: calc(100% - 1rem);
    margin: 0.5rem auto;
  }
}

/* Actions bar responsive */
@media (max-width: 768px) {
  .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .actions > * {
    flex: 0 1 auto;
    min-width: 0;
  }
}

/* Alert responsive */
@media (max-width: 576px) {
  .alert {
    padding: 0.75rem;
    margin-bottom: 0.75rem;
  }
  .alert-heading { font-size: 1rem; }
}

/* List groups responsive */
@media (max-width: 768px) {
  .list-group { margin-bottom: 1rem; }
  .list-group-item { padding: 0.75rem; }
}

/* Grid responsive adjustments */
@media (max-width: 992px) {
  .col-lg-6 { flex: 0 0 100%; max-width: 100%; }
  .col-lg-4 { flex: 0 0 50%; max-width: 50%; }
}

@media (max-width: 768px) {
  .col-md-6, .col-md-4, .col-md-3 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ===== <code> lisible (IP, n° interne, groupes de sécurité…) =====
 * Bootstrap affiche <code> en rose-rouge #d63384, peu lisible surtout
 * en mode sombre. On le remplace par un bleu contrasté en pastille,
 * cohérent avec l'accent de l'application, dans les deux thèmes.
 * (.prose code garde son style propre pour le contenu de type note.) */
code:not(.prose code) {
  color: #1d4ed8;
  background: rgba(37, 99, 235, .10);
  padding: .1rem .4rem;
  border-radius: .35rem;
  font-weight: 600;
  font-size: .85em;
  font-family: 'Fira Code', Consolas, monospace;
}
[data-bs-theme="dark"] code:not(.prose code) {
  color: #93c5fd;
  background: rgba(147, 197, 253, .15);
}
