/* Muster Design System — editorial industrial
   Paper bg, monochrome, navy accent earned. No purple. No rounded-2xl.
*/

:root {
  --ink: #0A0E1A;
  --ink-soft: #2B3140;
  --mute: #6B7280;
  --mute-soft: #9CA3AF;
  --line: #E5E7EB;
  --line-soft: #F1F2F4;
  --paper: #FAFAF9;
  --surface: #FFFFFF;
  --navy: #294F8B;
  --navy-ink: #1F3E6F;
  --navy-whisper: #EEF3FB;
  --good: #047857;
  --good-whisper: #ECFDF5;
  --warn: #B45309;
  --warn-whisper: #FFFBEB;
  --bad: #B91C1C;
  --bad-whisper: #FEF2F2;
}

html, body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography utilities ── */
.m-label {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--mute);
  line-height: 1;
}
.m-data {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.m-h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink);
}
.m-h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--ink);
}
.m-h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.m-kpi {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.m-sub {
  font-size: 13px;
  color: var(--mute);
  line-height: 1.5;
}
.m-caption {
  font-size: 11px;
  color: var(--mute);
}

/* ── Structure ── */
.m-rule { border-bottom: 1px solid var(--line); }
.m-rule-soft { border-bottom: 1px solid var(--line-soft); }
.m-divide > * + * { border-top: 1px solid var(--line-soft); }

/* ── Buttons ── */
.m-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border-radius: 2px;
  font-size: 13px; font-weight: 700;
  font-family: inherit;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .04s;
  white-space: nowrap;
  text-decoration: none;
}
.m-btn:active { transform: translateY(0.5px); }
.m-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.m-btn-sm { height: 30px; padding: 0 11px; font-size: 12px; gap: 6px; }
.m-btn-lg { height: 42px; padding: 0 20px; font-size: 14px; }
.m-btn-primary { background: var(--ink); color: #fff; }
.m-btn-primary:hover { background: #000; }
.m-btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.m-btn-secondary:hover { background: var(--line-soft); border-color: var(--ink-soft); }
.m-btn-ghost { background: transparent; color: var(--ink); }
.m-btn-ghost:hover { background: var(--line-soft); }
.m-btn-danger { background: #fff; color: var(--bad); border-color: var(--line); }
.m-btn-danger:hover { background: var(--bad-whisper); border-color: var(--bad); }
.m-btn-navy { background: var(--navy); color: #fff; }
.m-btn-navy:hover { background: var(--navy-ink); }
.m-btn-icon { width: 36px; padding: 0; justify-content: center; }
.m-btn-icon.m-btn-sm { width: 30px; }

/* ── Inputs ── */
.m-input, .m-select, .m-textarea,
input[type=text], input[type=email], input[type=url], input[type=tel],
input[type=password], input[type=number], input[type=search],
input[type=date], input[type=time], input[type=datetime-local],
select, textarea {
  display: block; width: 100%;
  min-height: 38px; padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #fff;
  color: var(--ink);
  font-family: inherit; font-size: 14px;
  line-height: 1.4;
  box-shadow: inset 0 1px 0 rgba(10,14,26,.02);
  transition: border-color .12s, box-shadow .12s, background .12s;
  -webkit-appearance: none; appearance: none;
}
.m-input:hover, .m-select:hover, .m-textarea:hover,
input[type=text]:hover, input[type=email]:hover, input[type=url]:hover,
select:hover, textarea:hover { border-color: var(--ink-soft); }

.m-input:focus, .m-select:focus, .m-textarea:focus,
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(10,14,26,.08);
}

.m-input::placeholder, input::placeholder, textarea::placeholder { color: var(--mute-soft); }
.m-input.is-invalid, .m-select.is-invalid { border-color: var(--bad); }
.m-input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(185,28,28,.12); }
.m-textarea, textarea { min-height: 84px; line-height: 1.5; resize: vertical; }

/* Disabled */
.m-input:disabled, .m-select:disabled, .m-textarea:disabled,
input:disabled, select:disabled, textarea:disabled {
  background: var(--line-soft); color: var(--mute);
  cursor: not-allowed;
}

/* ── Select — custom caret chevron ── */
.m-select, select {
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%230A0E1A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}
.m-select::-ms-expand, select::-ms-expand { display: none; }

/* ── Input sizes ── */
.m-input-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.m-input-lg { min-height: 44px; padding: 10px 14px; font-size: 15px; }

/* ── Checkbox + Radio ── */
input[type="checkbox"], input[type="radio"], .m-checkbox, .m-radio {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px;
  min-height: 18px;
  padding: 0;
  border: 1.5px solid var(--line);
  background: #fff;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: border-color .12s, background .12s, box-shadow .12s;
  box-shadow: none;
}
input[type="checkbox"], .m-checkbox { border-radius: 3px; }
input[type="radio"], .m-radio { border-radius: 50%; }

input[type="checkbox"]:hover, input[type="radio"]:hover,
.m-checkbox:hover, .m-radio:hover { border-color: var(--ink-soft); }

input[type="checkbox"]:focus, input[type="radio"]:focus,
.m-checkbox:focus, .m-radio:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10,14,26,.08);
  border-color: var(--ink);
}

input[type="checkbox"]:checked, .m-checkbox:checked {
  background: var(--ink);
  border-color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M2.5 6.5l2.5 2.5 4.5-5' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 12px;
  background-position: center;
  background-repeat: no-repeat;
}
input[type="radio"]:checked, .m-radio:checked {
  border-color: var(--ink);
  background: radial-gradient(circle, var(--ink) 0 40%, #fff 45%);
}

/* Inline label + control pairing */
.m-check-row { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.m-check-row:hover input[type="checkbox"]:not(:checked),
.m-check-row:hover input[type="radio"]:not(:checked) { border-color: var(--ink); }

/* File input */
input[type="file"] {
  font-size: 13px;
  padding: 6px 0;
  cursor: pointer;
}
input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover {
  background: var(--line-soft);
  border-color: var(--ink-soft);
}

/* Stacked field (label + input) */
.m-field { display: flex; flex-direction: column; gap: 6px; }
.m-field-error { font-size: 11.5px; color: var(--bad); }
.m-field-help { font-size: 11.5px; color: var(--mute); }

/* ── Pills / Badges ── */
.m-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px;
  border-radius: 2px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  line-height: 1.2;
}
.m-pill-mute { background: var(--line-soft); color: var(--mute); }
.m-pill-navy { background: var(--navy-whisper); color: var(--navy); }
.m-pill-good { background: var(--good-whisper); color: var(--good); }
.m-pill-warn { background: var(--warn-whisper); color: var(--warn); }
.m-pill-bad  { background: var(--bad-whisper); color: var(--bad); }
.m-pill-ink  { background: var(--ink); color: #fff; }

/* ── Filter chips — editorial tab-like ── */
.m-chip {
  display: inline-flex; align-items: center;
  padding: 6px 12px;
  font-size: 12px; font-weight: 600;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 2px;
  transition: border-color .15s, background .15s;
}
.m-chip:hover { border-color: var(--ink-soft); }
.m-chip-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.m-chip-active .text-mute { color: rgba(255,255,255,.55) !important; }

/* ── Tables ── */
.m-table { width: 100%; border-collapse: collapse; }

/* On narrow viewports, wide data tables get a horizontal scroll. The browser's
   default is to bleed off-screen — that breaks layouts and confuses users.
   Force the parent to scroll, keep the table happy with min-width, and show a
   subtle scroll-cue shadow at the right edge. */
@media (max-width: 768px) {
  .m-table { min-width: 640px; }
  /* Block-level table wrappers: any direct parent that's display:block should
     scroll. Most templates render tables inside a div without scroll — this
     fallback uses a combinator. */
  .m-table-wrap, main table.m-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Tighter cell padding on phones */
  .m-table thead th, .m-table tbody td { padding: 9px 10px; font-size: 13px; }
  /* Stacked buttons in narrow toolbars */
  .m-btn { white-space: nowrap; }
}

/* Always — tables scrolling inside a card should not break the rounded corner */
.m-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.m-table thead th {
  text-align: left;
  padding: 10px 16px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--mute);
  border-bottom: 1px solid var(--line);
  background: transparent;
}
.m-table tbody td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.m-table tbody tr:last-child td { border-bottom: 1px solid var(--line); }
.m-table tbody tr.m-tr-click { cursor: pointer; }
.m-table tbody tr.m-tr-click:hover { background: var(--line-soft); }
.m-table .num { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; text-align: right; }

/* ── Nav ── */
.m-nav a {
  display: flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 10px;
  border-radius: 4px;
  font-size: 13px; font-weight: 500;
  color: var(--mute);
  border-left: 2px solid transparent;
  transition: background .1s, color .1s, border-color .1s;
  margin-left: -2px;
}
.m-nav a svg { width: 16px; height: 16px; stroke-width: 1.5; }
.m-nav a:hover { background: var(--line-soft); color: var(--ink); }
.m-nav a.active { background: var(--surface); color: var(--ink); font-weight: 600; border-left-color: var(--navy); }
.m-nav-label {
  padding: 18px 12px 6px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--mute-soft);
}

/* ── KPI strip ── */
.m-kpi-strip { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 40px; }
@media (max-width: 768px) { .m-kpi-strip { grid-auto-flow: row; grid-auto-columns: unset; gap: 24px; } }
.m-kpi-block .m-label { margin-bottom: 8px; }
.m-kpi-block .m-kpi { margin-bottom: 4px; }
.m-kpi-block .m-caption { display: block; margin-top: 4px; }

/* ── Surface card (use sparingly) ── */
.m-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.m-card-hd {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.m-card-bd { padding: 20px; }

/* ── Avatar ── */
.m-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: 9999px;
  background: var(--line-soft);
  color: var(--ink);
  font-size: 11px; font-weight: 700;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0;
  flex-shrink: 0;
}
.m-avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.m-avatar-lg { width: 40px; height: 40px; font-size: 14px; }
.m-avatar-outline {
  background: transparent;
  border: 1px dashed var(--mute-soft);
  color: var(--mute);
}

/* ── Empty state ── */
.m-empty {
  padding: 64px 24px;
  text-align: center;
  color: var(--mute);
}
.m-empty svg { width: 24px; height: 24px; stroke-width: 1.5; color: var(--mute-soft); margin: 0 auto 16px; display: block; }
.m-empty .m-empty-title { font-size: 15px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.m-empty .m-empty-desc { font-size: 13px; max-width: 360px; margin: 0 auto 16px; line-height: 1.5; }

/* ── Modal ── */
.m-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,14,26,.4);
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.m-modal {
  background: var(--surface);
  border-radius: 8px;
  width: 100%; max-width: 480px;
  padding: 28px;
  box-shadow: 0 24px 48px -12px rgba(10,14,26,.25);
}

/* ── Form-level niceties ── */
.m-hr { border: 0; height: 1px; background: var(--line); margin: 32px 0; }

/* Kbd (keyboard hint) */
.m-kbd {
  display: inline-flex; align-items: center;
  padding: 0 5px; height: 18px;
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 2px;
  background: var(--surface);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px; font-weight: 600;
  color: var(--mute);
}

/* Utility */
.m-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }

/* Focus ring for interactive non-form elements */
.m-focus-ring:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(41,79,139,.25);
  border-radius: 4px;
}
