:root {
  --bg: #f3f1eb;
  --ink: #1c1a16;
  --muted: #5c574e;
  --card: #fffdf8;
  --line: #d9d2c4;
  --accent: #1f5c45;
  --accent-ink: #f4fff9;
  --warn: #8a4b12;
  --danger: #8f1d1d;
  --radius: 10px;
  --shadow: 0 4px 14px rgba(28, 26, 22, 0.05);
  --font: "Segoe UI", "Helvetica Neue", sans-serif;
  --control-h: 44px;
  --control-pad-x: 0.8rem;
  --control-pad-y: 0.65rem;
  --control-radius: 8px;
  --control-border: 1px solid var(--line);
  --label-size: 0.875rem;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { width: min(1180px, calc(100% - 1.5rem)); margin: 0 auto; }
.topnav {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(243,241,235,.92);
  border-bottom: 1px solid var(--line);
}
.topnav-inner { display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: .75rem 0; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .02em; color: var(--ink); font-size: 1.1rem; }
.navlinks { display: flex; gap: .45rem; flex-wrap: wrap; }
.navlinks a {
  padding: .45rem .7rem; border-radius: 999px; color: var(--muted); font-size: .92rem;
  min-height: 40px; display: inline-flex; align-items: center;
}
.navlinks a.active, .navlinks a:hover { background: #e8e2d6; color: var(--ink); text-decoration: none; }
.userchip { font-size: .85rem; color: var(--muted); }
main { padding: 1rem 0 2.5rem; }
h1 { font-size: clamp(1.25rem, 2.4vw, 1.65rem); margin: 0 0 .35rem; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 1.1rem 0 .5rem; }
.lead { color: var(--muted); margin: 0 0 .85rem; max-width: 48rem; font-size: .95rem; }

/* Sub-navigation for Opportunities workspace */
.subnav {
  display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1rem;
  padding: .35rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.subnav a {
  padding: .55rem .9rem; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: .92rem;
  min-height: 40px; display: inline-flex; align-items: center;
}
.subnav a.active, .subnav a:hover { background: var(--accent); color: var(--accent-ink); text-decoration: none; }

/* Global form standard */
.form-grid {
  display: grid;
  gap: .75rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-span-2 { grid-column: span 2; }
.form-span-all { grid-column: 1 / -1; }
.form-actions {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .25rem;
}
label.field {
  display: grid; gap: .3rem; font-size: var(--label-size); color: var(--muted); min-width: 0;
}
label.field > span, .field-label { font-size: var(--label-size); color: var(--muted); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=url], input[type=tel], input[type=search],
select, textarea {
  width: 100%;
  min-width: 0;
  padding: var(--control-pad-y) var(--control-pad-x);
  border-radius: var(--control-radius);
  border: var(--control-border);
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.3;
  min-height: var(--control-h);
}
textarea {
  min-height: 96px;
  resize: vertical;
  padding-top: .7rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(31, 92, 69, 0.35);
  outline-offset: 1px;
  border-color: var(--accent);
}
.btn, button, input[type=submit] {
  appearance: none; border: 0; background: var(--accent); color: var(--accent-ink);
  border-radius: 8px; padding: .65rem 1rem; font-weight: 600; cursor: pointer;
  font-size: .95rem; min-height: var(--control-h); display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
a.btn:hover { text-decoration: none; }
.btn.secondary, button.secondary { background: #e8e2d6; color: var(--ink); }
.btn.danger { background: var(--danger); }
.btn.small, button.small { min-height: 36px; padding: .4rem .7rem; font-size: .85rem; }
.btn:disabled, button:disabled { opacity: .5; cursor: not-allowed; }

.stack { display: grid; gap: .75rem; }
.filters { display: grid; gap: .75rem; }
.filters fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: .75rem;
}
.filters legend { padding: 0 .35rem; font-weight: 600; }
.checks { display: flex; flex-wrap: wrap; gap: .35rem .75rem; }
.checks label { display: inline-flex; gap: .35rem; align-items: center; min-height: 40px; font-size: .92rem; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem 1rem; box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 .45rem; font-size: .95rem; }
.muted { color: var(--muted); font-size: .88rem; }
.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: .85rem; }
.flash.ok { background: #e5f5ec; color: #184b34; }
.flash.err { background: #fde8e8; color: var(--danger); }
.flash.warn { background: #fff1e0; color: var(--warn); }

/* Compact dashboard */
.dash-grid {
  display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.dash-section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .85rem; }
.dash-section h2 { margin: 0 0 .55rem; font-size: .95rem; display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.dash-section .count { color: var(--muted); font-weight: 600; font-size: .85rem; }
.dash-row {
  display: flex; gap: .5rem; justify-content: space-between; align-items: flex-start;
  padding: .45rem 0; border-top: 1px solid var(--line); font-size: .9rem;
}
.dash-row:first-of-type { border-top: 0; padding-top: 0; }
.dash-row .meta { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.stat-strip {
  display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin-bottom: .85rem;
}
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .55rem .7rem; color: inherit; text-decoration: none; display: block;
}
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat .n { font-size: 1.25rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .78rem; margin-top: .15rem; }
.dash-wide { grid-column: 1 / -1; width: 100%; }
.subnav .count {
  margin-left: .35rem; background: rgba(255,255,255,.22); border-radius: 999px;
  padding: .05rem .4rem; font-size: .75rem; font-weight: 700;
}
.subnav a:not(.active) .count { background: #e8e2d6; color: var(--muted); }
.supplier-header .meta { display: grid; gap: .2rem; }

/* Compact opportunity results */
.result-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.result-table th, .result-table td { text-align: left; padding: .55rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: .86rem; }
.result-table th { font-size: .75rem; color: var(--muted); background: #f7f3ea; font-weight: 600; }
.result-table tr:last-child td { border-bottom: 0; }
.result-table .title { font-weight: 650; font-size: .92rem; color: var(--ink); }
.result-table .actions-cell { white-space: nowrap; }
.result-table .actions-cell form { display: inline; }
.result-cards { display: none; gap: .55rem; }
.result-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .8rem;
}
.result-card h3 { margin: 0 0 .35rem; font-size: .95rem; font-weight: 650; }
.kv { display: grid; grid-template-columns: 7.5rem 1fr; gap: .2rem .55rem; font-size: .84rem; margin: .35rem 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.badge {
  display: inline-block; padding: .12rem .45rem; border-radius: 999px; background: #e8e2d6;
  color: var(--ink); font-size: .72rem; font-weight: 600;
}
.badge.saved { background: #d7eee1; color: #184b34; }
.badge.warn { background: #ffe6c7; color: var(--warn); }
.detail-sections { display: grid; gap: .75rem; }
.detail-sections section {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem;
}
.detail-sections h2 { margin: 0 0 .5rem; }
.list { display: grid; gap: .55rem; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .85rem;
}
.item h3 { margin: 0 0 .25rem; font-size: .98rem; }
.meta { display: flex; flex-wrap: wrap; gap: .35rem .65rem; color: var(--muted); font-size: .82rem; margin: .25rem 0; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .45rem; align-items: center; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: .55rem .45rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; color: var(--muted); }
.actions-cell { white-space: nowrap; }
.actions-cell form { display: inline; }
.actions-cell .btn, .actions-cell button { margin: .1rem .15rem .1rem 0; }
.empty { padding: .9rem; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); font-size: .9rem; }
.login-box { width: min(420px, 100%); margin: 8vh auto; }
.footer { color: var(--muted); font-size: .78rem; padding: 1rem 0 2rem; }
.back-link { display: inline-block; margin-bottom: .65rem; font-size: .9rem; }

@media (max-width: 1023px) {
  .form-grid.cols-4, .form-grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-table { display: none; }
  .result-cards { display: grid; }
}
@media (max-width: 767px) {
  .hide-mobile { display: none !important; }
  .navlinks { width: 100%; }
  .navlinks a { flex: 1 1 auto; text-align: center; justify-content: center; }
  .wrap { width: min(1180px, calc(100% - 1rem)); }
  .form-grid, .form-grid.cols-2, .form-grid.cols-3, .form-grid.cols-4 {
    grid-template-columns: 1fr;
  }
  .form-span-2, .form-span-all { grid-column: auto; }
  .filters .checks label { width: 100%; }
  .subnav a { flex: 1 1 auto; justify-content: center; }
  .kv { grid-template-columns: 6.5rem 1fr; }
  .actions .btn, .actions button { flex: 1 1 auto; }
}
@media (max-width: 390px) {
  .brand { font-size: 1rem; }
  .navlinks a { font-size: .8rem; padding: .4rem .4rem; }
  .kv { grid-template-columns: 1fr; }
}
@media (min-width: 1024px) {
  .wrap { width: min(1180px, calc(100% - 2rem)); }
}
