/* Mars Brain hub - MMG internal product design system (design skill section 10+).
   All colors come from the token block; no raw hex below it. */

/* ---------- Fonts (self-hosted, latin subset; no CDN calls) ---------- */
@font-face {
  font-family: 'Poppins'; font-style: normal; font-weight: 400; font-display: swap;
  src: local('Poppins Regular'), url('/fonts/poppins-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins'; font-style: normal; font-weight: 600; font-display: swap;
  src: local('Poppins SemiBold'), url('/fonts/poppins-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins'; font-style: normal; font-weight: 800; font-display: swap;
  src: local('Poppins ExtraBold'), url('/fonts/poppins-800.woff2') format('woff2');
}

/* ---------- Tokens ---------- */
:root {
  /* Layout */
  --mmg-sidebar-width: 220px;
  --mmg-topbar-height: 64px;
  --mmg-content-bg: #e8eef4;
  --mmg-content-padding: 32px;

  /* Brand */
  --mmg-navy: #001478;
  --mmg-navy-hover: #001060;
  --mmg-sky: #47b7e4;
  --mmg-sky-hover: #3aa8d4;
  --mmg-ink: #000b2e;
  --mmg-green: #68bd62;
  --mmg-orange: #f9a51f;
  --mmg-red: #ec1c24;

  /* Surfaces and lines */
  --mmg-white: #ffffff;
  --mmg-line: rgba(0, 20, 120, 0.06);
  --mmg-line-strong: rgba(0, 20, 120, 0.12);
  --mmg-shadow: 0 1px 3px rgba(0, 11, 46, 0.06);
  --mmg-inset-bg: #f6f9fc;

  /* Text */
  --mmg-gray-500: #6b7280;
  --mmg-gray-400: #9ca3af;
  --mmg-on-navy: rgba(255, 255, 255, 0.7);
  --mmg-on-navy-dim: rgba(255, 255, 255, 0.5);

  /* Status badge system */
  --mmg-success-bg: #e6f7ef;
  --mmg-warning-bg: #fef3e6;
  --mmg-info-bg: #e6f4fc;
  --mmg-error-bg: #fce6e6;

  /* Focus ring: 3px sky at 55% */
  --mmg-focus: 0 0 0 3px rgba(71, 183, 228, 0.55);

  /* Breakpoint tokens (reference; media queries use the literal px values) */
  --mmg-bp-mobile: 480px;
  --mmg-bp-tablet: 768px;
  --mmg-bp-desktop: 1024px;
  --mmg-bp-wide: 1280px;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--mmg-content-bg);
  color: var(--mmg-ink);
  font: 400 14px/1.55 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
a { color: inherit; }
button { font-family: inherit; }
:is(button, a, input, select, textarea):focus { outline: none; }
:is(button, a, input, select, textarea):focus-visible { box-shadow: var(--mmg-focus); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--mmg-sidebar-width);
  background: var(--mmg-navy);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.3s ease;
  z-index: 200;
}
.sidebar-logo { margin-bottom: 32px; padding: 0 8px; }
.logo {
  font: 600 18px/1.2 'Poppins', sans-serif;
  color: var(--mmg-white);
  letter-spacing: 0.5px;
}
.logo span { color: var(--mmg-sky); }
/* flex:1 + min-height:0 + overflow-y:auto so a short viewport (phone in
   landscape, short desktop window) scrolls the nav instead of squashing the
   items and pushing the footnote past the sidebar's bottom edge. */
nav { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--mmg-on-navy);
  font: 500 14px/1.4 'Poppins', sans-serif;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
  flex-shrink: 0;
  /* Scoped to the two properties that actually animate. `transition: all`
     also catches the visibility the drawer inherits when it opens, and
     easing a discrete property freezes these buttons at hidden. */
  transition: color 0.15s ease, background-color 0.15s ease;
}
.nav-item:hover { color: var(--mmg-white); background: rgba(255, 255, 255, 0.05); }
.nav-item.active { color: var(--mmg-white); background: rgba(255, 255, 255, 0.1); }
.nav-item .ico { width: 20px; text-align: center; opacity: 0.8; }
nav .sep { height: 1px; background: rgba(255, 255, 255, 0.12); margin: 10px 4px; }
nav .footnote {
  margin-top: auto;
  flex-shrink: 0;
  color: var(--mmg-on-navy-dim);
  font: 400 11px/1.5 'Helvetica Neue', Helvetica, Arial, sans-serif;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

/* Overlay behind the open sidebar (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 11, 46, 0.5);
  z-index: 199;
}

/* ---------- Topbar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: var(--mmg-sidebar-width);
  right: 0;
  height: var(--mmg-topbar-height);
  background: var(--mmg-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 32px;
  border-bottom: 1px solid var(--mmg-line);
  z-index: 100;
  transition: left 0.3s ease;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 600 18px/1 'Poppins', sans-serif;
  color: var(--mmg-navy);
  white-space: nowrap;
}
.topbar-title .mark { color: var(--mmg-sky); }
.user-menu { display: flex; align-items: center; gap: 16px; }
.user-name { text-align: right; }
.user-name strong {
  display: block;
  font: 600 14px/1.3 'Poppins', sans-serif;
  color: var(--mmg-navy);
}
.user-name span {
  font: 400 12px/1 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: var(--mmg-sky);
}
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 600 14px/1 'Poppins', sans-serif;
  color: var(--mmg-white);
  background: var(--mmg-navy);
  flex-shrink: 0;
}

/* Hamburger (hidden on desktop) */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--mmg-navy);
  border-radius: 2px;
  transition: all 0.2s ease;
}
.hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ---------- Main content ---------- */
.main-content {
  margin-left: var(--mmg-sidebar-width);
  margin-top: var(--mmg-topbar-height);
  min-height: calc(100vh - var(--mmg-topbar-height));
  background: var(--mmg-content-bg);
  padding: var(--mmg-content-padding);
  transition: margin-left 0.3s ease;
}
h2 {
  font: 800 28px/1.2 'Poppins', sans-serif;
  color: var(--mmg-navy);
  margin: 0 0 4px 0;
}
.sub { font: 400 14px/1.4 'Helvetica Neue', Helvetica, Arial, sans-serif; color: var(--mmg-gray-500); margin: 0 0 20px; }
.muted { color: var(--mmg-gray-500); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- Stat cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.card {
  background: var(--mmg-white);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  border: 1px solid var(--mmg-line);
  box-shadow: var(--mmg-shadow);
}
.card .n {
  font: 800 32px/1 'Poppins', sans-serif;
  color: var(--mmg-navy);
  margin-bottom: 4px;
}
.card .l {
  font: 400 12px/1.3 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: var(--mmg-gray-500);
  text-transform: capitalize;
  letter-spacing: 0;
}

/* ---------- Panels (content cards) ---------- */
.panel {
  background: var(--mmg-white);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 18px;
  box-shadow: var(--mmg-shadow);
}
.panel h3 {
  font: 600 16px/1.3 'Poppins', sans-serif;
  color: var(--mmg-navy);
  margin: 0 0 16px;
}
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.col { flex: 1; min-width: 280px; }
.col b { color: var(--mmg-navy); }

/* ---------- Pills / status badges ---------- */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font: 500 11px/1.6 'Poppins', sans-serif;
  border: 1px solid var(--mmg-line-strong);
  color: var(--mmg-gray-500);
  background: var(--mmg-white);
  margin: 2px 3px 2px 0;
  white-space: nowrap;
}
.pill.skill { background: var(--mmg-info-bg); border-color: var(--mmg-sky); color: var(--mmg-navy); }
.pill.src { background: var(--mmg-success-bg); border-color: var(--mmg-green); color: var(--mmg-ink); }
.pill.deny { background: var(--mmg-error-bg); border-color: var(--mmg-red); color: var(--mmg-red); }
.pill.tier { background: var(--mmg-inset-bg); color: var(--mmg-gray-500); }
.pill.tier.org { color: var(--mmg-navy); border-color: var(--mmg-navy); }
.pill.tier.team { color: var(--mmg-sky-hover); border-color: var(--mmg-sky); }
.pill.tier.personal { color: var(--mmg-gray-500); }
.pill.tier.pending { background: var(--mmg-warning-bg); color: var(--mmg-orange); border-color: var(--mmg-orange); }

/* ---------- Buttons ---------- */
button.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--mmg-navy);
  color: var(--mmg-white);
  border: none;
  border-radius: 999px;
  padding: 12px 32px;
  font: 600 14px/1 'Poppins', sans-serif;
  cursor: pointer;
  transition: background 0.15s ease;
}
button.btn:hover { background: var(--mmg-navy-hover); }
button.btn:focus-visible { box-shadow: var(--mmg-focus); }
button.ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--mmg-navy);
  border: 2px solid var(--mmg-navy);
  border-radius: 999px;
  padding: 8px 20px;
  font: 600 13px/1 'Poppins', sans-serif;
  cursor: pointer;
  transition: all 0.15s ease;
}
button.ghost:hover { background: var(--mmg-navy); color: var(--mmg-white); }

/* ---------- Forms ---------- */
input, textarea, select { font: inherit; }
.field {
  width: 100%;
  background: var(--mmg-white);
  border: 1px solid var(--mmg-line-strong);
  border-radius: 8px;
  color: var(--mmg-ink);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.field::placeholder { color: var(--mmg-gray-400); }
textarea.field { min-height: 64px; resize: vertical; }

/* ---------- Item cards (agents, skills, memories) ---------- */
.agent, .fcard, .skillcard {
  background: var(--mmg-white);
  border: 1px solid var(--mmg-line);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 10px;
  box-shadow: var(--mmg-shadow);
}
.panel :is(.agent, .fcard, .skillcard) { box-shadow: none; border-color: var(--mmg-line-strong); }
.agent .top, .skillcard .top, .fcard .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.agent .name, .skillcard .name { font: 600 15px/1.3 'Poppins', sans-serif; color: var(--mmg-navy); }
.fcard b { color: var(--mmg-navy); }
.reuse { font-size: 12px; color: var(--mmg-gray-500); }
.skillcard .top > div:last-child > div:nth-child(2) { color: var(--mmg-navy); font-family: 'Poppins', sans-serif; }
.locked { opacity: 0.55; }
.lockline { display: flex; align-items: center; gap: 8px; color: var(--mmg-gray-500); font-size: 12px; margin-top: 6px; }
.lineage { font-size: 12px; color: var(--mmg-gray-500); margin-top: 6px; }

/* ---------- Tables ---------- */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--mmg-line); font-size: 13px; vertical-align: top; }
th {
  color: var(--mmg-gray-500);
  text-transform: uppercase;
  font: 500 10px/1.4 'Poppins', sans-serif;
  letter-spacing: 0.6px;
}
tr:last-child td { border-bottom: none; }
td b { color: var(--mmg-navy); }

/* ---------- Result block, states, misc ---------- */
.result {
  border-left: 3px solid var(--mmg-sky);
  background: var(--mmg-inset-bg);
  border-radius: 0 10px 10px 0;
  padding: 14px 16px;
  margin-top: 14px;
  white-space: pre-wrap;
}
.result b { color: var(--mmg-navy); }
.ok-text { color: var(--mmg-green); }
.bad-text { color: var(--mmg-red); }
.warn-text { color: var(--mmg-orange); }
.bar { height: 6px; border-radius: 4px; background: rgba(0, 20, 120, 0.1); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--mmg-navy); }
.spin { color: var(--mmg-gray-500); font-size: 13px; padding: 18px; }
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--mmg-navy);
  color: var(--mmg-white);
  font: 500 13px/1.4 'Poppins', sans-serif;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--mmg-shadow);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  z-index: 300;
}
.toast.show { opacity: 1; }

/* ---------- Responsive (design skill section 12) ---------- */
@media (min-width: 1281px) {
  .main-content { padding: 48px; }
}

@media (max-width: 1024px) {
  .main-content { padding: 24px; }
}

@media (max-width: 768px) {
  /* visibility (not just transform) so the closed drawer leaves the tab order
     and the accessibility tree. It is deliberately NOT in the transition:
     visibility is discrete, and both easing it and delaying it leave the
     drawer stuck at the wrong value. Flipping it instantly costs only the
     slide-out animation on close; the slide-in still plays. */
  .sidebar { transform: translateX(-100%); visibility: hidden; }
  .sidebar.open { transform: translateX(0); visibility: visible; }
  .sidebar.open + .sidebar-overlay { display: block; }
  .hamburger { display: flex; }
  .topbar { left: 0; padding: 0 16px; }
  .user-name { display: none; }
  .main-content { margin-left: 0; padding: 16px; }
  h2 { font-size: 24px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .row { gap: 12px; }
  .col { min-width: 100%; }
  /* Touch targets: minimum 44px; 16px inputs prevent iOS zoom */
  button.btn, button.ghost { min-height: 44px; padding: 12px 24px; }
  .nav-item { min-height: 44px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
}

@media (max-width: 480px) {
  /* Retune the token so topbar height, main margin-top AND the min-height
     calc all stay in sync (a literal 56px here left min-height on 64px and
     pushed 8px of dead scroll onto every short page). */
  :root { --mmg-topbar-height: 56px; }
  .topbar { padding: 0 12px; }
  .topbar-title .word { display: none; }
  .main-content { padding: 12px; }
  h2 { font-size: 20px; }
  .cards { grid-template-columns: 1fr; }
  .card .n { font-size: 24px; }
}
