/* Future Aero Lab — Workspace
   A small design system: tokens first, then layout, then components. */

:root {
  --bg:        #0f1216;
  --bg-raise:  #161a20;
  --bg-sunken: #0b0e12;
  --panel:     #1a1f26;
  --border:    #262d36;
  --border-soft:#1f252d;
  --text:      #e6eaf0;
  --text-dim:  #98a3b2;
  --text-faint:#697585;
  --accent:    #5aa9e6;
  --accent-dim:#2b4d68;

  --good:  #7fc29b;
  --info:  #5aa9e6;
  --warn:  #e0b45c;
  --muted: #6b7684;
  --neutral:#9aa6b5;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

:root[data-theme="light"] {
  --bg:        #f6f7f9;
  --bg-raise:  #ffffff;
  --bg-sunken: #eceef2;
  --panel:     #ffffff;
  --border:    #dde1e8;
  --border-soft:#e8ebf0;
  --text:      #1a1f27;
  --text-dim:  #5a6472;
  --text-faint:#8a94a3;
  --accent:    #2b7fc4;
  --accent-dim:#cfe3f4;
  --good:  #3f8f68;
  --info:  #2b7fc4;
  --warn:  #a97a1e;
  --muted: #8a94a3;
  --neutral:#5a6472;
  --shadow: 0 8px 28px rgba(20,30,50,.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

.app { display: flex; min-height: 100vh; }

/* ---------------- Sidebar ---------------- */

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #7fc29b);
  color: #07101a; font-weight: 700; font-size: 13px;
  display: grid; place-items: center; letter-spacing: .3px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 13.5px; }
.brand-text span { font-size: 11.5px; color: var(--text-faint); }

.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); text-decoration: none; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg-raise); color: var(--text); }
.nav-item.active { background: var(--panel); color: var(--text); }
.nav-item .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; }
.nav-item .count { margin-left: auto; font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 4px; }

.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); }
.staff-strip { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.avatar {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: #0d1319;
  cursor: default;
}
.foot-actions { display: flex; gap: 4px; }
.btn-ghost {
  flex: 1; padding: 5px 6px; font-size: 11.5px;
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }

/* ---------------- Main / topbar ---------------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg); position: sticky; top: 0; z-index: 20;
}

.search-wrap { position: relative; flex: 1; max-width: 520px; }
.search-wrap input {
  width: 100%; padding: 8px 12px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 60vh; overflow-y: auto; z-index: 40; padding: 4px;
}
.sr-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.sr-item:hover { background: var(--bg-raise); }
.sr-item .sr-type { font-size: 10.5px; color: var(--text-faint); margin-left: auto; text-transform: uppercase; letter-spacing: .4px; }
.sr-empty { padding: 14px; color: var(--text-faint); text-align: center; }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.btn {
  padding: 7px 13px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--accent); color: #07131d; border: 1px solid transparent; font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }
.btn-sec {
  background: var(--bg-raise); color: var(--text);
  border: 1px solid var(--border); font-weight: 500;
}
.btn-sec:hover { border-color: var(--text-faint); }
.btn-danger { background: transparent; color: #e08a7d; border: 1px solid #6b3d38; font-weight: 500; }
.btn-danger:hover { background: #2a1a18; }

.content { padding: 22px 24px 60px; flex: 1; }

/* ---------------- Headings ---------------- */

.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 20px; letter-spacing: -.2px; }
.page-head .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.page-head .spacer { flex: 1; }

h2.section { font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-faint); margin: 26px 0 10px; font-weight: 600; }

/* ---------------- Dashboard ---------------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; cursor: pointer;
  border-left: 3px solid var(--accent);
}
.stat:hover { border-color: var(--text-faint); }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--text-dim); font-size: 12.5px; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-head { padding: 11px 14px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; display:flex; align-items:center; gap:8px; }
.panel-body { padding: 6px; }
.panel-body.pad { padding: 14px; }

.row-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.row-item:hover { background: var(--bg-raise); }
.row-item .r-title { font-weight: 500; }
.row-item .r-sub { color: var(--text-faint); font-size: 12px; }
.row-item .r-right { margin-left: auto; font-size: 11.5px; color: var(--text-faint); white-space: nowrap; }

/* Pipeline funnel */
.funnel { display: flex; flex-direction: column; gap: 5px; padding: 12px 14px; }
.funnel-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; }
.funnel-row .fl { width: 150px; color: var(--text-dim); flex: 0 0 150px; }
.funnel-row .fbar { height: 16px; background: var(--accent-dim); border-radius: 3px; min-width: 2px; }
.funnel-row .fn { color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* ---------------- Filters / table ---------------- */

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters select, .filters input {
  padding: 6px 9px; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
  color: var(--text);
}
.filters select:focus, .filters input:focus { border-color: var(--accent); }
.filter-clear { margin-left: auto; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 9px 12px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-faint); border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none; font-weight: 600;
}
th:hover { color: var(--text); }
td { padding: 9px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg-raise); }
td.strong { font-weight: 500; }

.empty { padding: 40px; text-align: center; color: var(--text-faint); }

.th-actions { width: 64px; }
.row-actions { white-space: nowrap; text-align: right; padding-right: 10px; }
.icon-btn {
  background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-faint); cursor: pointer; padding: 3px 6px; font-size: 13px;
  line-height: 1; margin-left: 2px;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: #e08a7d; border-color: #6b3d38; }

.group-panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); margin-bottom: 14px; overflow: hidden; }
.group-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: var(--bg-sunken); font-weight: 600; font-size: 13.5px; border-bottom: 1px solid var(--border);
}
.group-head:hover { color: var(--accent); }
.group-count {
  margin-left: auto; font-weight: 400; font-size: 11.5px; color: var(--text-faint);
  background: var(--bg-raise); border-radius: 20px; padding: 1px 9px;
}
.group-panel table { margin: 0; }
.group-panel th { cursor: default; }

.pager {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 12px; border-top: 1px solid var(--border);
}
.pager button:disabled { opacity: .4; cursor: default; }
.pager-info { color: var(--text-faint); font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ---------------- Badges / chips ---------------- */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge.good    { color: var(--good);    background: color-mix(in srgb, var(--good) 14%, transparent);    border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.badge.info    { color: var(--info);    background: color-mix(in srgb, var(--info) 14%, transparent);    border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.badge.warn    { color: var(--warn);    background: color-mix(in srgb, var(--warn) 14%, transparent);    border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge.muted   { color: var(--muted);   background: color-mix(in srgb, var(--muted) 14%, transparent);   border-color: color-mix(in srgb, var(--muted) 30%, transparent); }
.badge.neutral { color: var(--neutral); background: color-mix(in srgb, var(--neutral) 14%, transparent); border-color: color-mix(in srgb, var(--neutral) 30%, transparent); }

.chip {
  display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11px;
  background: var(--bg-sunken); border: 1px solid var(--border); color: var(--text-dim);
  margin-right: 4px;
}
.chip.link { cursor: pointer; }
.chip.link:hover { border-color: var(--accent); color: var(--text); }

/* ---------------- Detail page ---------------- */

.detail-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 4px; }
.detail-head h1 { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.detail-meta { color: var(--text-dim); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }

.detail-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; align-items: start; margin-top: 18px; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }

.field-group { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); }
.field-group:last-child { border-bottom: none; }
.field-group h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); margin: 0 0 8px; font-weight: 600; }
.field { display: grid; grid-template-columns: 130px 1fr; gap: 10px; padding: 4px 0; align-items: baseline; }
.field .k { color: var(--text-faint); font-size: 12.5px; }
.field .v { word-break: break-word; }
.field .v.empty-v { color: var(--text-faint); font-style: italic; }
.field .v a { color: var(--accent); text-decoration: none; }
.field .v a:hover { text-decoration: underline; }

/* ---------------- Modal / form ---------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4,7,11,.66);
  display: grid; place-items: center; z-index: 100; padding: 20px;
  backdrop-filter: blur(2px);
}
/* `display:grid` above outranks the [hidden] attribute's UA `display:none`,
   so the overlay must be hidden explicitly or it covers the whole page. */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 620px; max-height: 88vh; display: flex; flex-direction: column;
}
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.form-row .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 7px 10px; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--accent); }
.form-row textarea { min-height: 76px; resize: vertical; font-family: inherit; }
.form-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .form-cols { grid-template-columns: 1fr; } }
.form-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); margin: 18px 0 8px; font-weight: 600; }
.form-sec:first-child { margin-top: 0; }

.multi-select { max-height: 150px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; background: var(--bg-sunken); }
.multi-select label { display: flex; align-items: center; gap: 8px; padding: 3px 4px; font-size: 13px; color: var(--text); cursor: pointer; margin: 0; }
.multi-select label:hover { background: var(--bg-raise); border-radius: 4px; }
.multi-select input[type=checkbox] { width: auto; }

/* ---------------- Analysis ---------------- */

/* min() keeps the track from exceeding the container on narrow panes —
   a plain minmax(360px, 1fr) overflows horizontally instead of shrinking. */
.a-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
  gap: 16px; align-items: start;
}
.a-panel { display: flex; flex-direction: column; }
.a-sub { padding: 8px 14px 0; color: var(--text-dim); font-size: 12.5px; line-height: 1.45; }
.a-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.a-scroll { max-height: 340px; overflow-y: auto; }

.a-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; border-radius: 4px; padding: 1px 2px; }
.a-row:hover { background: var(--bg-raise); }
.a-label {
  width: 132px; flex: 0 0 132px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.a-track { flex: 1; height: 15px; background: var(--bg-sunken); border-radius: 3px; overflow: hidden; }
.a-bar { display: block; height: 100%; border-radius: 3px; }
.a-val {
  width: 62px; flex: 0 0 62px; text-align: right;
  color: var(--text); font-variant-numeric: tabular-nums; font-size: 12px;
}

.a-finding {
  margin-top: 8px; padding: 9px 11px; border-radius: var(--radius-sm);
  font-size: 12.5px; line-height: 1.5; border-left: 3px solid var(--info);
  background: var(--bg-sunken); color: var(--text-dim);
}
.a-finding.good  { border-left-color: var(--good); }
.a-finding.warn  { border-left-color: var(--warn); }
.a-finding.muted { border-left-color: var(--muted); }
.a-finding.info  { border-left-color: var(--info); }

.a-list { margin-top: 10px; max-height: 240px; overflow-y: auto; }

/* Narrow panes: stack the sidebar and give the bars room to breathe. */
@media (max-width: 780px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav-item { width: auto; }
  .nav-sep { display: none; }
  .content { padding: 16px 14px 48px; }
  .a-label { width: 92px; flex-basis: 92px; }
  .a-val { width: 54px; flex-basis: 54px; }
  .field { grid-template-columns: 110px 1fr; }
  .detail-grid, .grid-2 { grid-template-columns: 1fr; }
}

.note {
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 28%, transparent);
  color: var(--text); padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 12.5px; margin-bottom: 14px;
}
