/*
  CASCADE base stylesheet — implements the "Slate & Mint" palette and the
  UI/UX application matrix from the brief: keep dashboards visually neutral
  (Canvas / Pure Light / Charcoal) and reserve --c-critical / --c-warning
  EXCLUSIVELY for safety-critical signals (failed audits, hazards, near-miss
  / pending-review items). Tokens are CSS custom properties so an
  organisation's theme_overrides (see core.context_processors) can repaint
  the whole app without a rebuild.
*/

:root {
  --c-primary: #0D2323;     /* Deep Slate Teal — brand anchor          */
  --c-accent:  #4ECE85;     /* Tech Mint — primary actions / success    */
  --c-canvas:  #F7FAFA;     /* Crisp Canvas — app background            */
  --c-surface: #FFFFFF;     /* Pure Light — cards / tables              */
  --c-body:    #3A4D4D;     /* Muted Charcoal — body copy / borders     */
  --c-critical:#E64A19;     /* RESERVED: critical NC / immediate hazard */
  --c-warning: #FFA000;     /* RESERVED: near-miss / pending review     */

  --radius: 10px;
  --shadow: 0 1px 3px rgba(13, 35, 35, 0.08), 0 1px 2px rgba(13, 35, 35, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--c-canvas);
  color: var(--c-body);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--c-primary); }
a.accent { color: var(--c-accent); font-weight: 600; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--c-primary);
  color: #EAF3F0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.sidebar .brand .name { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; color: #FFFFFF; }
.sidebar .brand .tagline { font-size: 11px; color: var(--c-accent); text-transform: uppercase; letter-spacing: 1px; }
.sidebar nav a {
  display: block; padding: 10px 12px; border-radius: var(--radius);
  color: #CFE3DD; text-decoration: none; font-size: 14px; margin-bottom: 2px;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(78, 206, 133, 0.15); color: #FFFFFF; }
.sidebar .section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #7FA29A; margin: 16px 12px 6px; }
.sidebar .userbox { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 13px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--c-surface); border-bottom: 1px solid #E4ECEC;
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { font-size: 20px; margin: 0; color: var(--c-primary); }
.content { padding: 24px 28px; flex: 1; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px; border: 1px solid #EAF1F1;
}
.card h2, .card h3 { color: var(--c-primary); margin-top: 0; }

table.cascade-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.cascade-table th {
  text-align: left; background: var(--c-primary); color: #fff; padding: 10px 12px;
  font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.4px;
}
table.cascade-table th:first-child { border-radius: 8px 0 0 0; }
table.cascade-table th:last-child { border-radius: 0 8px 0 0; }
table.cascade-table td { padding: 10px 12px; border-bottom: 1px solid #EEF3F3; }
table.cascade-table tr:hover td { background: #F2F8F6; }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-block; padding: 9px 18px; border-radius: var(--radius);
  background: var(--c-accent); color: #07261A; font-weight: 600; text-decoration: none;
  border: none; cursor: pointer; font-size: 14px;
}
.btn:hover { filter: brightness(0.95); }
.btn.secondary { background: transparent; color: var(--c-primary); border: 1px solid var(--c-primary); }
.btn.subtle { background: #EAF3F0; color: var(--c-primary); }

form p, .form-row { margin-bottom: 14px; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; color: var(--c-primary); }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #D7E3E1; border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--c-body);
}
input[type="checkbox"] { width: auto; }

/* ---------- Rich-text (Markdown) editor ---------- */
.richtext-wrap { border: 1px solid #D7E3E1; border-radius: 8px; overflow: hidden; background: #fff; }
.richtext-toolbar {
  display: flex; align-items: center; gap: 2px; padding: 6px 8px;
  background: var(--c-canvas); border-bottom: 1px solid #D7E3E1;
}
.richtext-btn {
  width: auto; min-width: 28px; padding: 4px 8px; border: 1px solid transparent;
  border-radius: 6px; background: transparent; color: var(--c-primary);
  font-size: 13px; cursor: pointer; line-height: 1.3;
}
.richtext-btn:hover { background: #fff; border-color: #D7E3E1; }
.richtext-preview-toggle { font-weight: 600; font-size: 12px; }
.richtext-preview-toggle.active { background: var(--c-accent); color: #07261A; border-color: var(--c-accent); }
.richtext-wrap textarea.richtext-editor {
  border: none; border-radius: 0; display: block;
}
.richtext-wrap textarea.richtext-editor:focus { outline: none; }
.richtext-preview {
  padding: 12px 14px; min-height: 80px; font-size: 14px; line-height: 1.55; color: var(--c-body);
}
.richtext-preview :first-child { margin-top: 0; }
.richtext-preview :last-child { margin-bottom: 0; }
.richtext-preview ul, .richtext-preview ol { padding-left: 22px; }
.richtext-hint { display: block; padding: 4px 10px 6px; font-size: 11px; color: #8AA0A0; }

/* ---------- Badges (alerts reserved per brand guidance) ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; }
.badge.critical { background: var(--c-critical); }
.badge.warning  { background: var(--c-warning); color: #3A2400; }
.badge.normal   { background: var(--c-accent); color: #07261A; }
.badge.neutral  { background: var(--c-body); }

.toggle-pill { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.toggle-pill .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.toggle-pill.on .dot { background: var(--c-accent); }
.toggle-pill.off .dot { background: #C8D4D2; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.messages .success { background: #E4F8EC; color: #1B6B3F; border: 1px solid #BFE9D2; }
.messages .warning { background: #FFF4E0; color: #8A5A00; border: 1px solid #FFE0A6; }
.messages .error   { background: #FDE7E0; color: #A6371A; border: 1px solid #F6C3B0; }

.muted { color: #7E938F; font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }

/* ---------- Risk matrix ---------- */
.matrix { border-collapse: collapse; }
.matrix th, .matrix td { border: 1px solid #E4ECEC; width: 48px; height: 40px; text-align: center; font-size: 13px; }
.matrix th { background: var(--c-primary); color: #fff; font-weight: 600; }
.matrix td.s-low { background: #EAF8EF; }
.matrix td.s-med { background: #FFF1D6; }
.matrix td.s-high { background: #FBDCD2; }

/* ---------- Mobile menu button (hidden on desktop) ---------- */
.hamburger {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 38px; height: 34px; padding: 6px 8px; border: 1px solid #E4ECEC;
  border-radius: 8px; background: var(--c-surface); cursor: pointer; flex-shrink: 0;
}
.hamburger span { display: block; height: 2px; width: 100%; background: var(--c-primary); border-radius: 2px; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(13,35,35,0.45); z-index: 998; }

/* ---------- Responsive: tablets and phones ---------- */
@media (max-width: 860px) {
  .hamburger { display: inline-flex; }

  /* Sidebar becomes an off-canvas drawer toggled by the hamburger. */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 264px; z-index: 999;
    transform: translateX(-100%); transition: transform .25s ease; overflow-y: auto;
    box-shadow: 0 0 24px rgba(0,0,0,0.25);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body:not(.nav-open) .sidebar-backdrop { display: none; }

  .main { width: 100%; min-width: 0; }
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar h1 { font-size: 17px; }
  .content { padding: 14px; }

  /* Search drops to its own full-width row below the title on small screens. */
  .topbar-search { order: 5; width: 100%; }
  .topbar-search input { width: 100% !important; box-sizing: border-box; }

  /* Wide data tables scroll horizontally instead of breaking the layout. */
  .cascade-table, .data-table, .matrix {
    display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap;
  }

  /* Cards and flex form rows stack full width. */
  .card { padding: 14px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .topbar .toggle-pill { display: none; }   /* free up space on the smallest screens */
  .content { padding: 10px; }
  .card { padding: 12px; }
}
