:root {
  --navy: #0b1220;
  --navy-2: #111b2e;
  --navy-3: #1a2740;
  --navy-text: #c5d0e2;
  --navy-muted: #8b9bb3;
  --accent: #1d6fe8;
  --accent-hover: #1558c4;
  --accent-soft: #e8f1fd;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e5eaf1;
  --success: #15803d;
  --success-bg: #ecfdf3;
  --warning: #b45309;
  --warning-bg: #fff7ed;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #1d4ed8;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.04);
  --sidebar: 248px;
  --topbar: 64px;
  --font: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; }

/* Auth */
.mg-auth {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #dbe7f8 0%, transparent 55%),
    var(--bg);
  display: grid;
  place-items: center;
  padding: 32px 16px;
}
.mg-auth-wrap { width: 100%; max-width: 440px; }
.mg-auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
}
.mg-auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.mg-auth-brand strong { font-size: 18px; letter-spacing: -0.03em; }
.mg-logo-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(180deg, #2b7ff0, #1a5fd0);
  position: relative;
  display: inline-block;
}
.mg-logo-mark:after {
  content: "";
  position: absolute; inset: 7px 8px 8px 8px;
  border: 2px solid #fff; border-radius: 3px 3px 6px 6px;
  border-top: 0;
}
.mg-auth h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -0.04em; }
.mg-auth-sub { margin: 0 0 24px; color: var(--muted); }
.mg-auth-row { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 20px; font-size: 13px; }
.mg-auth-foot { text-align: center; color: var(--muted); font-size: 12px; margin: 20px 0 0; }
.mg-field { display: block; margin-bottom: 14px; }
.mg-field span { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.mg-field input, .mg-field select, .mg-field textarea,
.mg-input, .mg-select, .mg-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  font-size: 14px;
}
.mg-field input:focus, .mg-field select:focus, .mg-field textarea:focus,
.mg-input:focus, .mg-select:focus, .mg-textarea:focus {
  border-color: #93c0ff;
  box-shadow: 0 0 0 3px rgba(29, 111, 232, 0.15);
}
.mg-check { display: flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.mg-btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.mg-btn:hover { background: #f8fafc; }
.mg-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.mg-btn-primary:hover { background: var(--accent-hover); }
.mg-btn-ghost { background: transparent; }
.mg-btn-danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.mg-btn-block { width: 100%; padding: 11px 14px; }
.mg-alert { border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px; }
.mg-alert-danger { background: var(--danger-bg); color: #991b1b; }
.mg-alert-success { background: var(--success-bg); color: #166534; }

/* Shell */
.mg-shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.mg-sidebar {
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 12px 12px;
}
.mg-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; }
.mg-brand strong { font-size: 16px; letter-spacing: -0.03em; }
.mg-workspace {
  margin: 0 8px 16px;
  padding: 10px 12px;
  background: var(--navy-2);
  border: 1px solid #223250;
  border-radius: 10px;
  font-size: 12px;
}
.mg-workspace small { color: var(--navy-muted); display: block; }
.mg-workspace b { font-weight: 600; }
.mg-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
.mg-nav a {
  color: var(--navy-text);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13.5px;
}
.mg-nav a svg { opacity: 0.85; flex: 0 0 auto; }
.mg-nav a:hover, .mg-nav a.is-active { background: var(--navy-3); color: #fff; }
.mg-side-foot { border-top: 1px solid #1d2b44; padding-top: 10px; margin-top: 8px; }
.mg-side-foot a, .mg-side-user {
  display: flex; align-items: center; gap: 10px;
  color: var(--navy-text); padding: 8px 10px; border-radius: 8px; font-size: 13px;
}
.mg-side-foot a:hover { background: var(--navy-3); color: #fff; }
.mg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #2a4a7a; color: #fff; display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.mg-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.mg-topbar {
  height: var(--topbar);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.mg-menu-btn { display: none; }
.mg-page-title { font-size: 16px; font-weight: 650; letter-spacing: -0.03em; margin-right: auto; }
.mg-search {
  width: min(420px, 42vw);
  position: relative;
}
.mg-search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 12px 8px 34px;
}
.mg-search svg { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.mg-icon-btn {
  width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; display: grid; place-items: center; position: relative;
}
.mg-icon-btn .dot {
  position: absolute; top: 7px; right: 8px; width: 7px; height: 7px;
  background: var(--danger); border-radius: 50%; border: 2px solid #fff;
}
.mg-top-user { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.mg-top-user:hover { background: var(--bg); }
.mg-top-user span { font-weight: 600; font-size: 13px; }
.mg-content { padding: 24px; max-width: 1320px; width: 100%; }

/* Cards / layout */
.mg-h1 { font-size: 24px; letter-spacing: -0.04em; margin: 0 0 4px; }
.mg-sub { color: var(--muted); margin: 0 0 20px; }
.mg-row { display: flex; align-items: center; gap: 10px; }
.mg-row.spread { justify-content: space-between; }
.mg-grid { display: grid; gap: 14px; }
.mg-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.mg-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.mg-card-pad { padding: 16px 18px; }
.mg-kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.mg-kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.04em; margin-top: 6px; }
.mg-kpi .hint { color: var(--success); font-size: 12px; margin-top: 6px; }
.mg-section-title { font-size: 14px; font-weight: 650; margin: 0 0 12px; letter-spacing: -0.02em; }
.mg-pipe-overview { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.mg-stage {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfc;
}
.mg-stage .n { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; }
.mg-stage .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mg-stage .v { font-size: 12px; font-weight: 600; margin-top: 8px; }
.mg-sources { display: flex; flex-direction: column; gap: 10px; }
.mg-source { display: grid; grid-template-columns: 110px 1fr 40px; gap: 8px; align-items: center; font-size: 13px; }
.mg-bar { height: 8px; background: #eef2f6; border-radius: 99px; overflow: hidden; }
.mg-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.mg-table { width: 100%; border-collapse: collapse; }
.mg-table th, .mg-table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.mg-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.mg-table tr:last-child td { border-bottom: 0; }
.mg-table tbody tr { cursor: pointer; }
.mg-table tbody tr:hover { background: #f8fafc; }
.mg-person { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.mg-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: #eef2f6; color: #334155;
}
.mg-badge.qualified, .mg-badge.won, .mg-badge.active, .mg-badge.connected { background: var(--success-bg); color: var(--success); }
.mg-badge.new-lead, .mg-badge.contacted { background: var(--accent-soft); color: var(--info); }
.mg-badge.proposal, .mg-badge.negotiation, .mg-badge.site-survey { background: var(--warning-bg); color: var(--warning); }
.mg-badge.lost, .mg-badge.paused, .mg-badge.danger { background: var(--danger-bg); color: var(--danger); }
.mg-badge.draft { background: #f1f5f9; color: #475569; }
.mg-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.mg-empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.mg-empty h3 { color: var(--text); margin: 0 0 6px; }

/* Pipeline board */
.mg-board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.mg-col { background: #eef1f5; border-radius: 12px; padding: 10px; min-height: 420px; }
.mg-col h4 { margin: 0 8px 10px; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: #475569; display: flex; justify-content: space-between; }
.mg-opp {
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 8px; cursor: grab;
}
.mg-opp:active { cursor: grabbing; }
.mg-opp b { display: block; }
.mg-opp .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.mg-opp .val { font-weight: 700; margin-top: 8px; }

/* Conversations */
.mg-inbox { display: grid; grid-template-columns: 280px 1fr 280px; gap: 0; min-height: calc(100vh - 120px); overflow: hidden; }
.mg-inbox > * { border-right: 1px solid var(--border); }
.mg-inbox > *:last-child { border-right: 0; }
.mg-conv-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.mg-conv-item.is-active { background: var(--accent-soft); }
.mg-thread { display: flex; flex-direction: column; min-height: 560px; }
.mg-msgs { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.mg-bubble { max-width: 75%; padding: 10px 12px; border-radius: 12px; background: #f1f5f9; }
.mg-bubble.team { margin-left: auto; background: var(--accent); color: #fff; }
.mg-composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }

/* Calendar */
.mg-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.mg-cal-cell { min-height: 110px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.mg-cal-cell.out { opacity: 0.45; }
.mg-event { font-size: 11px; background: var(--accent-soft); color: var(--info); border-radius: 6px; padding: 3px 6px; margin-top: 4px; }

/* Settings */
.mg-settings { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.mg-set-nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.mg-set-nav a.is-active, .mg-set-nav a:hover { background: #fff; border: 1px solid var(--border); }

/* Dropdowns / modal */
.mg-pop {
  position: absolute; right: 0; top: 42px; width: 340px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 40px rgba(15,23,42,.12); z-index: 40;
}
.mg-pop.user { width: 220px; }
.mg-pop-item { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.mg-pop-item:last-child { border-bottom: 0; }
.mg-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.4); display: grid; place-items: center; z-index: 50; padding: 20px;
}
.mg-modal {
  width: min(760px, 100%); max-height: 90vh; overflow: auto; background: #fff;
  border-radius: 14px; border: 1px solid var(--border); box-shadow: var(--shadow);
}
.mg-modal h2 { margin: 0; font-size: 18px; }
.mg-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mg-form-grid .full { grid-column: 1 / -1; }
.mg-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.mg-tabs button { background: none; border: 0; padding: 10px 12px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.mg-tabs button.is-active { color: var(--text); border-bottom-color: var(--accent); }
.mg-timeline { border-left: 2px solid var(--border); margin-left: 8px; padding-left: 16px; }
.mg-timeline li { margin: 0 0 14px; list-style: none; }
.mg-int-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mg-chart {
  height: 180px; display: flex; align-items: flex-end; gap: 8px; padding-top: 10px;
}
.mg-chart i { flex: 1; background: var(--accent); border-radius: 6px 6px 2px 2px; opacity: .9; }
.mg-hidden { display: none !important; }
.linkish { background: none; border: 0; color: inherit; cursor: pointer; font: inherit; text-align: left; width: 100%; padding: 0; }

@media (max-width: 1100px) {
  .mg-kpis, .mg-pipe-overview, .mg-int-grid { grid-template-columns: repeat(2, 1fr); }
  .mg-inbox { grid-template-columns: 240px 1fr; }
  .mg-inbox-right { display: none; }
  .mg-settings { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .mg-shell { grid-template-columns: 1fr; }
  .mg-sidebar {
    position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-105%);
    transition: transform .2s ease; width: min(86vw, 280px);
  }
  .mg-sidebar.open { transform: none; }
  .mg-menu-btn { display: grid; }
  .mg-search { display: none; }
  .mg-kpis, .mg-pipe-overview, .mg-form-grid, .mg-int-grid { grid-template-columns: 1fr; }
  .mg-table-wrap { overflow-x: auto; }
  .mg-top-user span { display: none; }
  .mg-content { padding: 16px; }
}
