/* ==========================================================================
   QMS/DMS Enterprise — QSE Theme
   Forest-green corporate palette, dense cartography-oriented layout.
   Optimised for compliance documentation portals.
   ========================================================================== */

/* ---------------- Design tokens ---------------- */
:root {
  --bg:            #f4f6f2;
  --bg-2:          #eaefe6;
  --surface:       #ffffff;
  --surface-2:     #fbfcf9;
  --border:        #d6ded1;
  --ink:           #14251a;
  --ink-2:         #38513f;
  --muted:         #6c7f70;

  --green-900:     #0f3d1e;
  --green-800:     #16552a;
  --green-700:     #1a6d36;
  --green-600:     #2b8a4c;
  --green-500:     #4aa66a;
  --green-100:     #dcebd8;
  --green-50:      #eff5eb;

  --gold:          #c99a3e;
  --gold-soft:     #f6ecd5;

  --ok:            #2d7d47;
  --ok-soft:       #dceecf;
  --warn:          #b7801d;
  --warn-soft:     #fbe7c5;
  --err:           #a53131;
  --err-soft:      #f5d9d4;
  --info:          #2465a0;
  --info-soft:     #d3e4f2;

  --shadow-sm:     0 1px 2px rgba(15, 61, 30, 0.05);
  --shadow-md:     0 6px 20px rgba(15, 61, 30, 0.10);
  --shadow-lg:     0 12px 40px rgba(15, 61, 30, 0.16);
  --radius:        6px;
  --radius-lg:     10px;
  --sans:          "Public Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif:         "Playfair Display", Georgia, "Times New Roman", serif;
  --mono:          "IBM Plex Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

/* ---------------- Reset ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }
a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--green-600); color: #fff; }

/* ---------------- QSE Header banner ---------------- */
.qse-banner {
  position: relative;
  background:
    linear-gradient(135deg, rgba(15, 61, 30, 0.90) 0%, rgba(22, 85, 42, 0.85) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><defs><pattern id='leaf' width='40' height='40' patternUnits='userSpaceOnUse'><path d='M20 5 Q30 20 20 35 Q10 20 20 5 Z' fill='%2316552a' opacity='0.15'/></pattern></defs><rect width='100' height='100' fill='url(%23leaf)'/></svg>");
  background-size: cover;
  color: #fff;
  padding: 32px 32px 26px;
  border-bottom: 4px solid var(--gold);
}
.qse-banner__inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
}
.qse-banner__brand { display: flex; align-items: center; gap: 16px; }
.qse-banner__logo {
  width: 68px; height: 68px; border-radius: 50%;
  background: #fff; padding: 6px;
  display: grid; place-items: center;
  box-shadow: var(--shadow-md);
  color: var(--green-800); font-weight: 800; font-size: 24px;
  font-family: var(--serif);
}
.qse-banner__logo img { max-height: 56px; }
.qse-banner__titles h1 {
  font-family: var(--serif);
  font-size: 34px; margin: 0; line-height: 1.05;
  letter-spacing: 0.01em;
}
.qse-banner__titles h1 small {
  display: block; font-family: var(--sans); font-weight: 400;
  font-size: 13px; letter-spacing: 0.14em;
  text-transform: uppercase; opacity: 0.88; margin-bottom: 4px;
}
.qse-banner__badges { display: flex; gap: 12px; flex-wrap: wrap; }
.iso-badge {
  background: #fff; color: var(--green-800);
  padding: 8px 14px; border-radius: 999px;
  font-weight: 700; font-size: 12px;
  box-shadow: var(--shadow-sm);
  border: 2px solid var(--gold);
  display: inline-flex; align-items: center; gap: 6px;
}
.iso-badge b { color: var(--gold); }
@media (max-width: 720px) {
  .qse-banner { padding: 22px 18px; }
  .qse-banner__titles h1 { font-size: 24px; }
  .qse-banner__logo { width: 54px; height: 54px; font-size: 20px; }
}

/* ---------------- Layout with sidebar ---------------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; background: var(--bg); }
.sidebar {
  background: var(--green-900);
  color: #d7e2d3; padding: 18px 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar__brand {
  padding: 0 22px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-family: var(--serif); font-size: 18px;
  color: #fff;
}
.sidebar__brand small { display: block; font-family: var(--sans); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.65; }
.sidebar__section {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em;
  color: rgba(255,255,255,0.5); padding: 14px 22px 6px;
}
.sidebar__link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 22px; color: #c9d5c5;
  border-left: 3px solid transparent;
  transition: background-color .15s, color .15s, border-color .15s;
}
.sidebar__link:hover { background: rgba(255,255,255,0.05); color: #fff; text-decoration: none; }
.sidebar__link.active { background: rgba(201, 154, 62, 0.12); color: #fff; border-left-color: var(--gold); }
.sidebar__link .ico { width: 16px; text-align: center; opacity: 0.85; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; position: sticky; top: 0; z-index: 10;
}
.topbar__title { font-size: 15px; font-weight: 600; color: var(--ink); }
.topbar__meta { color: var(--muted); font-size: 12px; }

.user-menu { position: relative; }
.user-menu__btn { background: transparent; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.user-menu__avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--green-700); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.user-menu__dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); min-width: 200px; display: none; z-index: 20; }
.user-menu.open .user-menu__dropdown { display: block; }
.user-menu__dropdown a, .user-menu__dropdown button { display: block; width: 100%; text-align: left; padding: 10px 14px; background: transparent; border: none; color: var(--ink); }
.user-menu__dropdown a:hover, .user-menu__dropdown button:hover { background: var(--bg-2); text-decoration: none; }

.content { padding: 24px; max-width: 1400px; width: 100%; }

/* ---------------- Cards ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card__header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--green-50); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.card__header h3 { margin: 0; font-size: 14px; letter-spacing: 0.02em; color: var(--green-900); }
.card__body { padding: 18px; }
.card__footer { padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 12px; color: var(--muted); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; padding: 9px 16px;
  border-radius: var(--radius); font-size: 13px; font-weight: 600;
  transition: background-color .15s, border-color .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green-700); color: #fff; }
.btn-primary:hover { background: var(--green-800); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-2); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--ink); border-color: transparent; }
.btn-ghost:hover { background: var(--bg-2); text-decoration: none; }
.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: #7c2222; text-decoration: none; }
.btn-gold { background: var(--gold); color: var(--green-900); }
.btn-gold:hover { background: #b78b32; text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* ---------------- Forms ---------------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--green-600);
  box-shadow: 0 0 0 3px rgba(74, 166, 106, 0.18);
}
.textarea { min-height: 90px; resize: vertical; font-family: var(--sans); }
.help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.error-text { color: var(--err); font-size: 12px; margin-top: 4px; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 14px; text-align: left; }
.table thead th { background: var(--green-50); color: var(--green-900); border-bottom: 1px solid var(--border); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.actions { text-align: right; white-space: nowrap; }

/* ---------------- Badges ---------------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--bg-2); color: var(--ink-2); border: 1px solid transparent; }
.badge-draft { background: var(--bg-2); color: var(--ink-2); }
.badge-review, .badge-in_progress, .badge-open { background: var(--info-soft); color: var(--info); }
.badge-approved, .badge-verification { background: var(--warn-soft); color: var(--warn); }
.badge-published, .badge-completed, .badge-closed, .badge-low { background: var(--ok-soft); color: var(--ok); }
.badge-archived, .badge-cancelled { background: #e2e2e2; color: #666; }
.badge-rejected { background: var(--err-soft); color: var(--err); }
.badge-critical, .badge-high { background: var(--err-soft); color: var(--err); font-weight: 700; }
.badge-medium { background: var(--warn-soft); color: var(--warn); }
.badge-public { background: var(--green-100); color: var(--green-800); }
.badge-group  { background: var(--gold-soft); color: #7a5b1a; }
.badge-internal { background: var(--gold-soft); color: #7a5b1a; }

/* ---------------- Stat tiles ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; position: relative; overflow: hidden; }
.stat::before { content: ''; position: absolute; left: 0; top: 0; width: 4px; height: 100%; background: var(--green-600); }
.stat.accent::before { background: var(--gold); }
.stat__label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.stat__value { font-family: var(--serif); font-size: 30px; margin-top: 6px; color: var(--green-900); }
.stat__hint  { margin-top: 4px; color: var(--muted); font-size: 12px; }

/* ---------------- Cartography ---------------- */
.carto { display: grid; grid-template-columns: 1fr; gap: 20px; }
.carto__row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }
.carto__row-title { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.carto__row-title .band {
  padding: 6px 16px; border-radius: 999px;
  font-weight: 700; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
}
.carto__row.management .band { background: var(--green-800); color: #fff; }
.carto__row.realisation .band { background: var(--gold); color: var(--green-900); }
.carto__row.support .band { background: var(--green-100); color: var(--green-800); }
.carto__row-title small { color: var(--muted); font-size: 12px; }
.carto__boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.carto__box {
  background: var(--green-50); border: 1px solid var(--green-100);
  padding: 14px; border-radius: var(--radius-lg);
  cursor: pointer; transition: transform .15s, box-shadow .15s, background-color .15s;
  display: flex; flex-direction: column; gap: 4px;
}
.carto__box:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); background: #fff; text-decoration: none; }
.carto__box code { font-family: var(--mono); font-size: 11px; color: var(--gold); font-weight: 700; }
.carto__box .lbl { font-weight: 700; color: var(--green-900); font-size: 14px; }
.carto__box .desc { color: var(--muted); font-size: 12px; }
.carto__box .count { font-size: 11px; color: var(--green-700); margin-top: 4px; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 61, 30, 0.55);
  backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
}
.modal-backdrop.open { display: flex; animation: fadein .15s ease-out; }
.modal { background: var(--surface); border-radius: var(--radius-lg); max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal__header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--green-50); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.modal__header h3 { margin: 0; font-size: 16px; color: var(--green-900); font-family: var(--serif); }
.modal__body { padding: 22px; }
.modal__footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.modal__close { background: transparent; border: none; font-size: 22px; color: var(--muted); }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------------- Toast ---------------- */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--info); padding: 12px 18px 12px 14px; border-radius: var(--radius); box-shadow: var(--shadow-md); min-width: 260px; max-width: 360px; animation: slidein .25s ease-out; }
.toast.ok  { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
.toast strong { display: block; font-size: 13px; margin-bottom: 2px; color: var(--green-900); }
.toast small { color: var(--muted); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- Cookie banner ---------------- */
.cookie-modal .modal__body p { font-size: 13px; color: var(--ink-2); }
.cookie-modal .modal__body strong { color: var(--green-800); }

/* ---------------- Utilities ---------------- */
.row { display: flex; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.center { align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.mono { font-family: var(--mono); }
.serif { font-family: var(--serif); }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-0{margin-top:0} .mt-1{margin-top:8px} .mt-2{margin-top:16px} .mt-3{margin-top:24px} .mt-4{margin-top:32px}
.mb-0{margin-bottom:0} .mb-1{margin-bottom:8px} .mb-2{margin-bottom:16px} .mb-3{margin-bottom:24px}
.hide { display: none !important; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h4 { margin: 0 0 6px; color: var(--ink); font-family: var(--serif); font-size: 18px; }
.empty p { margin: 0 0 14px; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--green-700); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-loader { display: flex; align-items: center; justify-content: center; padding: 60px; color: var(--muted); gap: 10px; }

/* ---------------- Auth landing ---------------- */
.public-wrap { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.public-main { flex: 1; padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

.footer {
  background: var(--green-900); color: #d7e2d3; padding: 28px 32px;
  margin-top: 40px;
}
.footer__inner { max-width: 1400px; margin: 0 auto; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 20px; }
.footer__col { flex: 1 1 220px; }
.footer h4 { color: #fff; font-family: var(--serif); font-size: 15px; margin: 0 0 8px; }
.footer p, .footer li, .footer a { font-size: 12px; color: #b3c4b0; }
.footer ul { list-style: none; padding: 0; margin: 0; }
.footer ul li { margin-bottom: 4px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar__nav { display: flex; flex-wrap: wrap; padding: 8px 12px; }
  .sidebar__section { display: none; }
  .sidebar__link { border-left: none; border-bottom: 3px solid transparent; padding: 8px 12px; }
  .sidebar__link.active { border-bottom-color: var(--gold); border-left-color: transparent; }
  .content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
