/* ==========================================================================
   ai.csiis.05 - SAM.gov Opportunity Explorer
   ========================================================================== */

:root {
  --navy: #102a43;
  --navy-2: #243b53;
  --ink: #1b2430;
  --muted: #627d98;
  --line: #d9e2ec;
  --line-soft: #e9eff5;
  --bg: #f2f5f8;
  --panel: #ffffff;
  --teal: #0b7285;
  --teal-dark: #075e6e;
  --teal-soft: #e6f6f9;
  --green: #067647;
  --green-soft: #e7f6ee;
  --amber: #9a6700;
  --amber-soft: #fff7e0;
  --red: #b42318;
  --red-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 42, 67, 0.06), 0 8px 24px rgba(16, 42, 67, 0.06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3 { color: var(--navy); line-height: 1.2; }
h2 { font-size: 1.18rem; margin: 0 0 0.6rem; }
h3 { font-size: 1rem; margin: 0 0 0.35rem; }
p { margin: 0 0 0.8rem; }
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.86em; background: #eef3f7; padding: 0.1em 0.35em; border-radius: 4px; }
pre { background: #0f1c2b; color: #d9e2ec; padding: 12px 14px; border-radius: 8px; overflow: auto; }
pre code { background: none; padding: 0; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 0.84rem; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: #fff; color: var(--navy); padding: 10px 14px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 18px 28px;
  background: linear-gradient(120deg, #0b2239 0%, #102a43 55%, #143a55 100%);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 11px;
  font-weight: 700; letter-spacing: 0.04em; font-size: 0.95rem;
  color: #7ee3f2;
}
.brand-text h1 { color: #fff; font-size: 1.28rem; margin: 0; letter-spacing: 0.01em; }
.brand-text p { color: #a9c1d6; margin: 2px 0 0; font-size: 0.84rem; }
.status-cluster { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em;
  background: rgba(255, 255, 255, 0.12); color: #e6f0f7;
  border: 1px solid rgba(255, 255, 255, 0.18);
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #9fb3c8; }
.pill.ok::before { background: #3ddc97; }
.pill.error::before { background: #ff8b7e; }
.pill.warn::before { background: #f5c26b; }
.pill.subtle { background: rgba(255, 255, 255, 0.07); font-weight: 500; color: #c4d5e4; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 0 28px;
  background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  overflow-x: auto;
}
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 13px 16px 12px; font: inherit; font-weight: 600; font-size: 0.9rem;
  color: var(--muted); border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--navy); }
.tab.is-active { color: var(--navy); border-bottom-color: var(--teal); }

/* ---------- Layout ---------- */
main { max-width: 1560px; margin: 0 auto; padding: 20px 28px 48px; }
.view { display: none; }
.view.is-active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0.4; } to { opacity: 1; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; }
.grid-2 > .panel { margin-bottom: 16px; }

.banner {
  border-radius: var(--radius); padding: 12px 15px; margin-bottom: 14px;
  border: 1px solid #b9d8e8; background: #eef8fc; color: #0b4f62;
  font-size: 0.9rem;
}
.banner.warn { background: var(--amber-soft); border-color: #f0d48a; color: #6b4a00; }
.banner.error { background: var(--red-soft); border-color: #f3b5ae; color: #7a1a12; }
.banner ul { margin: 0; padding-left: 18px; }
.banner li + li { margin-top: 4px; }

/* ---------- Filters ---------- */
.filters { padding: 16px 18px; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 14px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 0.78rem; font-weight: 700; color: var(--navy-2); letter-spacing: 0.02em; text-transform: uppercase; }
.field > span small { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid #c7d4e0; border-radius: 7px;
  background: #fff; color: var(--ink); font: inherit; font-size: 0.9rem;
}
.field textarea { resize: vertical; min-height: 70px; }
.field select[multiple] { padding: 4px; min-height: 96px; }
.field select[multiple] option { padding: 4px 6px; border-radius: 4px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(11, 114, 133, 0.25); border-color: var(--teal);
}
.span-2 { grid-column: span 2; }
.filter-actions { display: flex; gap: 8px; align-items: center; padding-bottom: 1px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; cursor: pointer;
  border: 1px solid #c7d4e0; background: #fff; color: var(--navy);
  border-radius: 7px; padding: 8px 13px;
  font: inherit; font-size: 0.87rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: #f5f8fa; border-color: #aebfce; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef3f7; color: var(--navy); }
.btn.danger { border-color: #e7a9a2; color: var(--red); background: #fff; }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 5px 9px; font-size: 0.8rem; }
.icon-btn {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-size: 1.4rem; line-height: 1; color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px;
}
.icon-btn:hover { background: #eef3f7; color: var(--navy); }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 14px; min-height: 0; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--teal-soft); color: #07505d;
  border: 1px solid #b7e0e8; border-radius: 999px;
  padding: 4px 6px 4px 11px; font-size: 0.78rem; font-weight: 600;
}
.chip button {
  appearance: none; border: 0; background: rgba(7, 80, 93, 0.1); cursor: pointer;
  width: 18px; height: 18px; border-radius: 50%; line-height: 1;
  color: #07505d; font-size: 0.9rem; display: grid; place-items: center;
}
.chip button:hover { background: rgba(7, 80, 93, 0.2); }
.chip.clear { background: #fff; border-color: var(--line); color: var(--muted); padding: 4px 11px; cursor: pointer; }
.chip.clear:hover { background: #f5f8fa; }

/* ---------- Table toolbar ---------- */
.table-panel { padding: 0; overflow: hidden; }
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 18px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap;
}
.result-meta { font-size: 0.9rem; color: var(--muted); }
.result-meta strong { color: var(--navy); font-size: 1.05rem; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rows-control { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.rows-control select { padding: 6px 8px; border: 1px solid #c7d4e0; border-radius: 7px; font: inherit; font-size: 0.84rem; background: #fff; }

/* ---------- Table ---------- */
.table-wrap { overflow: auto; max-height: calc(100vh - 330px); min-height: 260px; }
.table-panel .table-wrap { max-height: calc(100vh - 345px); }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f4f7fa; color: var(--navy-2);
  text-align: left; font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #eaf0f5; }
th.sortable::after { content: "↕"; margin-left: 5px; color: #9fb3c8; font-size: 0.72rem; }
th.sortable[data-dir="asc"]::after { content: "↑"; color: var(--teal); }
th.sortable[data-dir="desc"]::after { content: "↓"; color: var(--teal); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7fafc; }
tbody tr:last-child td { border-bottom: 0; }
.title-cell { min-width: 260px; max-width: 480px; }
.title-cell .title-link {
  appearance: none; border: 0; background: none; padding: 0; margin: 0;
  font: inherit; font-weight: 600; color: var(--navy); text-align: left; cursor: pointer;
  line-height: 1.35;
}
.title-cell .title-link:hover { color: var(--teal); text-decoration: underline; }
.title-cell .sub { margin-top: 4px; color: var(--muted); font-size: 0.76rem; display: flex; gap: 8px; flex-wrap: wrap; }
.title-cell .sub .sep { color: #bcccdc; }
.ext-link { color: var(--teal); font-weight: 600; }
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap;
  background: #eef3f7; color: #334e68;
}
.badge.type-o, .badge.type-k { background: #e6f6f9; color: #07505d; }
.badge.type-p, .badge.type-r { background: #fff4e0; color: #7a4d00; }
.badge.type-a { background: var(--green-soft); color: #05603a; }
.badge.type-s, .badge.type-i, .badge.type-g, .badge.type-u { background: #f0edf9; color: #4b3b8f; }
.badge.status-success, .badge.status-sent, .badge.status-ok { background: var(--green-soft); color: #05603a; }
.badge.status-partial, .badge.status-queued, .badge.status-running { background: var(--amber-soft); color: #7a4d00; }
.badge.status-failed, .badge.status-cancelled { background: var(--red-soft); color: #8f1d14; }
.badge.status-archived { background: #eef3f7; color: #52606d; }
.due-soon { color: #8a5300; font-weight: 700; }
.due-closed { color: #9aa8b6; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty h3 { margin-bottom: 6px; }
.empty p { max-width: 520px; margin: 0 auto 14px; }
.empty.hidden { display: none; }
.table-wrap[aria-busy="true"] { opacity: 0.55; pointer-events: none; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 18px; border-top: 1px solid var(--line-soft);
  flex-wrap: wrap; background: #fbfcfd;
}
.page-buttons { display: flex; gap: 6px; }
.page-info { font-size: 0.84rem; color: var(--muted); }
.page-jump { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.page-jump input { width: 76px; padding: 5px 7px; border: 1px solid #c7d4e0; border-radius: 6px; font: inherit; }

/* ---------- Sync ---------- */
.quota-card { border: 1px solid var(--line-soft); border-radius: 8px; padding: 13px 14px; background: #fbfcfd; }
.quota-line { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 0.86rem; color: var(--muted); }
.quota-line strong { color: var(--navy); }
.meter { height: 7px; background: #e6edf3; border-radius: 999px; overflow: hidden; margin: 10px 0; }
.meter-fill { height: 100%; width: 0; background: var(--teal); border-radius: 999px; transition: width 0.25s ease; }
.meter-fill.warn { background: #d69e2e; }
.meter-fill.danger { background: var(--red); }
.run-card { border: 1px solid var(--line-soft); border-radius: 8px; padding: 14px; margin-top: 14px; }
.run-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.run-head h3 { text-transform: capitalize; margin: 2px 0 0; }
.run-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.run-stats > div { background: #f4f7fa; border-radius: 7px; padding: 8px; text-align: center; }
.run-stats span { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.run-stats strong { font-size: 1rem; color: var(--navy); }
.eyebrow { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.inline-controls { display: flex; gap: 8px; align-items: center; }
.inline-controls select { padding: 6px 8px; border: 1px solid #c7d4e0; border-radius: 7px; font: inherit; font-size: 0.84rem; background: #fff; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Activity / help ---------- */
.help h3 { margin-top: 22px; }
.help ol, .help ul { padding-left: 20px; }
.help li { margin-bottom: 6px; }
.config-table td:first-child { white-space: nowrap; }
.config-table td { font-size: 0.84rem; }
.table-wrap table td.muted { font-style: italic; }

/* ---------- Dialog ---------- */
.dialog {
  width: min(640px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 12px; padding: 0;
  box-shadow: 0 24px 80px rgba(16, 42, 67, 0.28);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(11, 34, 57, 0.45); backdrop-filter: blur(2px); }
.dialog form { padding: 20px 22px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.dialog-head h2 { margin: 2px 0 0; }
.dialog .field { margin-bottom: 12px; }
.dialog .attach { border: 1px solid var(--line-soft); border-radius: 8px; padding: 10px 12px; margin: 4px 0 14px; }
.dialog .attach legend { font-size: 0.78rem; font-weight: 700; color: var(--navy-2); padding: 0 4px; }
.dialog .attach label { display: flex; gap: 8px; align-items: center; font-size: 0.86rem; margin: 4px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.form-status { min-height: 20px; font-size: 0.85rem; margin-bottom: 8px; }
.form-status.error { color: var(--red); }
.form-status.ok { color: var(--green); }

/* ---------- Drawer ---------- */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(11, 34, 57, 0.35);
  z-index: 40; opacity: 1; transition: opacity 0.2s;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(620px, 100vw);
  background: #fff; box-shadow: -18px 0 50px rgba(16, 42, 67, 0.2);
  transform: translateX(102%); transition: transform 0.22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  padding: 18px 20px; border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}
.drawer-head h2 { margin: 3px 0 0; font-size: 1.12rem; }
.drawer-body { padding: 18px 20px 40px; overflow: auto; }
.detail-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-grid { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 14px; margin: 12px 0 18px; }
.detail-grid dt { color: var(--muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding-top: 2px; }
.detail-grid dd { margin: 0; font-size: 0.9rem; overflow-wrap: anywhere; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 18px; }
.detail-section { margin-top: 20px; }
.detail-section h3 { border-bottom: 1px solid var(--line-soft); padding-bottom: 6px; }
.contact-card { border: 1px solid var(--line-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: #fbfcfd; font-size: 0.87rem; }
.contact-card strong { color: var(--navy); }
.contact-card div { color: var(--muted); }
.raw-json { max-height: 340px; }
.loading-block { padding: 40px 0; text-align: center; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #102a43; color: #fff; padding: 10px 16px; border-radius: 9px;
  box-shadow: 0 10px 30px rgba(16, 42, 67, 0.3);
  font-size: 0.88rem; opacity: 0; pointer-events: none;
  transition: opacity 0.18s, transform 0.18s; z-index: 80; max-width: min(560px, 90vw);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f1d14; }
.toast.ok { background: #05603a; }

/* ---------- Responsive ---------- */
@media (max-width: 1050px) {
  .grid-2 { grid-template-columns: 1fr; }
  .table-wrap, .table-panel .table-wrap { max-height: none; }
}
@media (max-width: 760px) {
  .topbar { padding: 14px 16px; align-items: flex-start; flex-direction: column; }
  .tabs { padding: 0 12px; }
  main { padding: 14px 12px 40px; }
  .panel { padding: 14px; }
  .filter-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .table-toolbar { align-items: flex-start; flex-direction: column; }
  .pagination { justify-content: center; }
  .detail-grid { grid-template-columns: 1fr; gap: 2px 0; }
  .detail-grid dt { margin-top: 8px; }
  .run-stats { grid-template-columns: repeat(2, 1fr); }
  .brand-text p { display: none; }
}

@media print {
  .topbar, .tabs, .filters, .chips, .table-toolbar, .pagination, .drawer, .drawer-overlay, .dialog, .toast { display: none !important; }
  main { padding: 0; }
  .panel { box-shadow: none; border: 0; }
  .table-wrap { max-height: none; overflow: visible; }
}
