:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #dfe3e8;
  --color-text: #1f2933;
  --color-muted: #6b7785;
  --color-primary: #2b6cb0;
  --color-primary-dark: #1e4e8c;
  --color-danger: #c53030;
  --color-success: #2f855a;
  --radius: 6px;
}

* { box-sizing: border-box; }

/* Any element toggled via el.hidden must actually disappear — without this,
   an element whose own class sets an explicit `display` (e.g. .btn's
   inline-block) silently overrides the browser's default [hidden] rule,
   since author styles always beat user-agent defaults regardless of
   specificity. Toggle visibility with el.hidden everywhere, never style.display. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

a { color: var(--color-primary); }

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

.app-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--color-primary-dark);
  color: #fff;
}
.app-brand {
  background: #fff;
  padding: 6px 12px;
  border-radius: var(--radius);
  line-height: 0;
}
.app-logo { height: 24px; width: auto; display: block; }
.app-user { font-size: 0.9rem; }
.app-user a { color: #cfe3f7; }

/* Organigramme */
.org-list { list-style: none; margin: 0; padding: 0; }
.org-list .org-list { margin-left: 14px; padding-left: 18px; border-left: 2px solid var(--color-border); }
.org-list li { margin: 8px 0; position: relative; }
.org-list .org-list > li::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 22px;
  width: 16px;
  border-top: 2px solid var(--color-border);
}
.org-chart details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.org-chart details > summary::-webkit-details-marker { display: none; }
.org-chart details > summary::before { content: "\25BE"; color: var(--color-muted); }
.org-chart details:not([open]) > summary::before { content: "\25B8"; }
.org-card {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
  padding: 8px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--color-text);
}
.org-card:hover { border-color: var(--color-primary); }
.org-me { border-color: var(--color-primary); box-shadow: 0 0 0 2px rgba(30, 78, 140, 0.2); }
.org-name { font-weight: 600; }
.org-role { color: var(--color-muted); font-size: 0.85rem; }
.org-status { color: #b26a00; font-size: 0.75rem; }
.org-count { background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 999px; padding: 0 8px; font-size: 0.8rem; color: var(--color-muted); }
.org-flat > li::before { display: none; }

/* Horizontal org chart: each person above their team, teams side by side. */
.org-h { overflow-x: auto; -webkit-overflow-scrolling: touch; text-align: center; padding: 20px 12px; }
.org-h ul { display: inline-flex; justify-content: center; list-style: none; margin: 0; padding: 20px 0 0; position: relative; }
.org-h > ul { padding-top: 0; align-items: flex-start; gap: 40px; }
.org-h li { position: relative; display: flex; flex-direction: column; align-items: center; padding: 20px 8px 0; }
.org-h > ul > li { padding-top: 0; }
.org-h li::before, .org-h li::after { content: ""; position: absolute; top: 0; right: 50%; width: 50%; height: 20px; border-top: 2px solid var(--color-border); }
.org-h li::after { right: auto; left: 50%; border-left: 2px solid var(--color-border); }
.org-h li:only-child::before, .org-h li:only-child::after { display: none; }
.org-h li:only-child { padding-top: 20px; }
.org-h li:first-child::before, .org-h li:last-child::after { border: 0 none; }
.org-h li:last-child::before { border-right: 2px solid var(--color-border); border-radius: 0 6px 0 0; }
.org-h li:first-child::after { border-radius: 6px 0 0 0; }
.org-h > ul > li::before, .org-h > ul > li::after { display: none; }
.org-h ul ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 20px; border-left: 2px solid var(--color-border); }
.org-h .org-card { min-width: 150px; max-width: 200px; text-align: center; align-items: center; }
@media print {
  .app-topbar, .app-nav, .nav-toggle, .btn, .stub-notice button { display: none !important; }
  .org-chart details > summary::before { content: ""; }
}

/* Notification bell */
.notif { position: relative; display: inline-block; vertical-align: middle; margin-right: 10px; }
.notif-btn {
  position: relative;
  background: transparent;
  border: 0;
  color: #fff;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 0;
  border-radius: var(--radius);
}
.notif-btn:hover { background: rgba(255, 255, 255, 0.15); }
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  box-sizing: border-box;
  background: #d93025;
  color: #fff;
  border-radius: 9px;
  font-size: 0.7rem;
  font-weight: bold;
  line-height: 18px;
  text-align: center;
}
.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  max-width: 92vw;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  z-index: 60;
  text-align: left;
}
.notif-head { padding: 10px 14px; font-weight: bold; border-bottom: 1px solid var(--color-border); }
.notif-empty { padding: 16px 14px; color: var(--color-muted); font-size: 0.9rem; }
.notif-item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--color-border); color: var(--color-text); text-decoration: none; }
.notif-item:hover { background: var(--color-bg); }
.notif-title { display: block; font-weight: 600; font-size: 0.9rem; }
.notif-meta { display: block; color: var(--color-muted); font-size: 0.8rem; margin-top: 2px; }
.notif-foot { padding: 8px 14px; margin: 0; }
.notif-markall { background: none; border: 0; padding: 0; color: var(--color-primary); cursor: pointer; font-size: 0.85rem; text-decoration: underline; }

.app-body { display: flex; flex: 1; }

.app-nav {
  width: 220px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 0;
}
.nav-section { margin-bottom: 4px; }
.nav-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--color-muted);
  padding: 8px 16px;
  letter-spacing: 0.05em;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.nav-section-label::-webkit-details-marker { display: none; }
.nav-section-label::after {
  content: "\25BE";
  font-size: 0.9rem;
  transition: transform 0.15s ease;
}
.nav-section:not([open]) .nav-section-label::after { transform: rotate(-90deg); }
.nav-section-label:hover { background: var(--color-bg); }
.app-nav ul { list-style: none; margin: 0; padding: 0; }
.app-nav li a {
  display: block;
  padding: 8px 16px;
  color: var(--color-text);
  text-decoration: none;
}
.app-nav li a:hover { background: var(--color-bg); }

.app-main { flex: 1; padding: 24px; max-width: 1100px; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.flash-success { background: #e6f4ea; color: var(--color-success); border: 1px solid #b7e0c4; }
.flash-error { background: #fbeaea; color: var(--color-danger); border: 1px solid #f0b8b8; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.stat-grid { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-card .stat-label { color: var(--color-muted); font-size: 0.85rem; }

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
}
table.data-table th { background: var(--color-bg); font-size: 0.85rem; text-transform: uppercase; color: var(--color-muted); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; }
.badge-active { background: #e6f4ea; color: var(--color-success); }
.badge-absent { background: #fdf2e3; color: #b7791f; }
.badge-on_leave { background: #e6effc; color: var(--color-primary); }
.badge-departed { background: #f0f0f0; color: var(--color-muted); }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
}
.btn:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-primary); }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field label { font-size: 0.85rem; color: var(--color-muted); }
.form-field input, .form-field select, .form-field textarea {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}
.form-actions { margin-top: 18px; display: flex; gap: 10px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 18px; }
.tabs a {
  padding: 8px 16px;
  text-decoration: none;
  color: var(--color-muted);
  border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.search-box { margin-bottom: 12px; }
.search-box input { width: 100%; max-width: 320px; padding: 8px 10px; border: 1px solid var(--color-border); border-radius: var(--radius); }

.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--color-bg); }
.auth-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 32px;
  width: 340px;
}
.auth-box h1 { font-size: 1.3rem; margin-top: 0; }
.auth-logo { max-width: 100%; height: auto; margin-bottom: 20px; }

.stub-notice { color: var(--color-muted); }

.checklist-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item-desc { font-weight: 500; margin-bottom: 8px; }
.checklist-item-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.status-radios { display: flex; gap: 12px; font-size: 0.9rem; }
.status-radios label { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.checklist-item-form input[type="text"] { flex: 1; min-width: 160px; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: var(--radius); }
.checklist-item-photos { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.photo-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.85rem;
}

/* Wide tables (e.g. the role access grid) scroll sideways on small screens. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Hamburger button + overlay: only used on phones and tablets. */
.nav-toggle, .nav-overlay { display: none; }

@media (max-width: 1024px) {
  .app-topbar { justify-content: flex-start; gap: 12px; padding: 10px 14px; position: sticky; top: 0; z-index: 30; }
  .app-user { margin-left: auto; font-size: 0.8rem; text-align: right; min-width: 0; }

  .nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0 10px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius);
    cursor: pointer;
    flex-shrink: 0;
  }
  .nav-toggle span { display: block; height: 2px; background: #fff; border-radius: 2px; }

  .app-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 50;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-right: 1px solid var(--color-border);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }
  body.nav-open .app-nav { transform: translateX(0); visibility: visible; }
  body.nav-open { overflow: hidden; }
  body.nav-open .nav-overlay {
    display: block;
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
  }
  /* Bigger touch targets inside the drawer. */
  .nav-section-label { padding: 12px 16px; }
  .app-nav li a { padding: 12px 16px; }

  .app-main { padding: 16px; max-width: none; width: 100%; }
}

@media (max-width: 720px) {
  .app-body { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
}
