/* ─── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f0f2f5;
  --card:      #ffffff;
  --border:    #d9dde4;
  --primary:   #1a6fb5;
  --primary-h: #155d9c;
  --accent:    #27ae60;
  --accent-h:  #1e9150;
  --warn:      #e67e22;
  --danger:    #c0392b;
  --text:      #1c2333;
  --muted:     #6b7280;
  --badge-bg:  #e8f1fa;
  --tab-line:  #1a6fb5;
  --row-even:  #f7f9fc;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
header {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.header-inner { display: flex; align-items: baseline; gap: 12px; }
header h1 { font-size: 18px; font-weight: 600; letter-spacing: .3px; }
.build-tag { font-size: 11px; opacity: .75; }
.lang-switch {
  display: inline-flex;
  padding: 2px;
  border-radius: 6px;
  background: rgba(0,0,0,.18);
}
.lang-btn {
  background: none;
  border: 0;
  color: rgba(255,255,255,.8);
  min-width: 34px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  font-family: inherit;
  letter-spacing: .4px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.lang-btn:hover { color: #fff; }
.lang-btn.active { background: #fff; color: var(--primary); }
.lang-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* ─── Main layout ───────────────────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ─── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card h2 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--text);
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ─── Project Grid ──────────────────────────────────────────────────────── */
.project-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.project-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 500;
  font-size: 13px;
  color: var(--muted);
}
.project-grid input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: #fafbfc;
  transition: border-color .15s, box-shadow .15s;
}
.project-grid input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,111,181,.12);
}

/* ─── Upload drop zones ─────────────────────────────────────────────────── */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 28px 20px 22px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
}
.drop-zone.optional {
  border-style: dotted;
  background: #fafafa;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--badge-bg);
}
.drop-zone.loaded {
  border-color: var(--accent);
  background: #f0faf4;
}
.drop-icon { color: var(--primary); opacity: .8; margin-bottom: 6px; line-height: 0; }
.drop-label { font-weight: 600; font-size: 14px; }
.drop-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.drop-status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
  transition: color .15s;
}
.drop-zone.loaded .drop-status { color: var(--accent); font-weight: 500; }
/* CRM URL row, embedded inside the CRM drop zone */
.crm-url-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  align-items: center;
}
.crm-url-row a#btn-open-crm {
  flex: 1;
  display: inline-block;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: 5px;
  transition: background .15s;
}
.crm-url-row a#btn-open-crm:hover { background: var(--primary-h); }
#btn-crm-edit {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 7px;
  color: var(--muted);
  cursor: pointer;
  line-height: 0;
  transition: border-color .15s, color .15s;
}
#btn-crm-edit:hover { border-color: var(--primary); background: var(--badge-bg); color: var(--primary); }
/* required / optional inline badges */
.required-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.optional-badge {
  display: inline-block;
  background: #e8ecf0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.btn-download {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 7px 18px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-download:hover { background: var(--accent-h); }

.results-top-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.btn-dl-all {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 20px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  letter-spacing: .2px;
}
.btn-dl-all:hover { background: var(--primary-h); }

/* ─── Process log ───────────────────────────────────────────────────────── */
.process-log {
  margin-top: 14px;
  padding: 10px 14px;
  background: #f4f6f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.log-ok   { color: var(--accent); font-weight: 600; }
.log-err  { color: var(--danger); font-family: monospace; font-size: 12px; white-space: pre-wrap; }

/* ─── Tabs ──────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.tab {
  background: none;
  border: none;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--tab-line); font-weight: 600; }

.tab-panel { display: block; }
.tab-panel.hidden { display: none; }

/* ─── Panel actions bar ─────────────────────────────────────────────────── */
.panel-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.row-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--badge-bg);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
}

/* ─── Data tables ───────────────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
thead tr {
  background: #2c3e50;
  color: #ecf0f1;
  position: sticky;
  top: 0;
  z-index: 1;
}
thead th {
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
  font-weight: 500;
  font-size: 12px;
  letter-spacing: .3px;
}
tbody tr { border-bottom: 1px solid #eef0f3; }
tbody tr:nth-child(even) { background: var(--row-even); }
tbody tr:hover { background: #ebf2fb; }
tbody td {
  padding: 6px 10px;
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status badges in tables */
td.status-accepted { color: var(--accent); font-weight: 600; }
td.status-open     { color: var(--primary); font-weight: 600; }
td.status-denied   { color: var(--danger); }
td.status-hold     { color: var(--warn); }

/* Status badge spans (status overview tab) */
span.status-accepted { color: var(--accent); font-weight: 700; }
span.status-open     { color: var(--primary); font-weight: 700; }
span.status-denied   { color: var(--danger); font-weight: 700; }
span.status-hold     { color: var(--warn); font-weight: 700; }
span.status-completed{ color: #27ae60; font-weight: 700; }
span.status-planned  { color: #8e44ad; font-weight: 700; }

/* ─── Validation report ─────────────────────────────────────────────────── */
#validation-report { display: flex; flex-direction: column; gap: 18px; }

.val-section {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.val-section-title {
  background: #2c3e50;
  color: #ecf0f1;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
}
.val-section-body { padding: 12px 14px; font-size: 13px; }

.val-counts-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 20px;
  align-items: center;
}
.val-counts-grid .lbl { color: var(--muted); font-size: 12px; }
.val-counts-grid .val { font-weight: 600; }
.val-counts-grid .val.ok   { color: var(--accent); }
.val-counts-grid .val.warn { color: var(--warn); }
.val-counts-grid .val.bad  { color: var(--danger); }

.val-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.val-list li { font-size: 12.5px; }
.val-list li::before { content: "• "; color: var(--danger); }
.val-none { color: var(--accent); font-size: 13px; font-style: italic; }

.val-ok-banner {
  background: #eafaf1;
  border: 1px solid #a9dfbf;
  color: var(--accent);
  padding: 12px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
}

/* CRM cross-check sections */
.val-crm-section .val-section-title { background: #2d4a6e; color: #dde8f5; }
.val-crm-new     .val-section-title { background: #1a5c38; color: #d5f5e3; }
.val-crm-overlap .val-section-title { background: #7d4e00; color: #fdebd0; }
.val-crm-only    .val-section-title { background: #4a4a5a; color: #e8e8f0; }
.val-crm-section .val-section-body p { margin: 0 0 8px; font-size: 13px; }
.val-crm-section code { background: #e8ecf0; padding: 1px 4px; border-radius: 3px; font-size: 12px; }

/* ─── Notes table ───────────────────────────────────────────────────────── */
.notes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 12px;
}
.notes-table th, .notes-table td {
  padding: 7px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.notes-table thead tr { background: #f4f6f9; }
.notes-table th { font-weight: 600; font-size: 12px; color: var(--muted); }

.note-warn {
  background: #fef9e7;
  border: 1px solid #f9e79f;
  border-radius: 5px;
  padding: 10px 14px;
  font-size: 13px;
  color: #7d6608;
}

/* ─── Collapsible ───────────────────────────────────────────────────────── */
.collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.collapsible-header .caret { transition: transform .2s; font-style: normal; }
.collapsible-header.collapsed .caret { transform: rotate(-90deg); }
.collapsible-body { margin-top: 14px; }
.collapsible-body.hidden { display: none; }

/* ─── Footer ─────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 16px;
  font-size: 11px;
  color: var(--muted);
}

/* ─── Utility ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Project Selector Table ─────────────────────────────────────────────── */
.selector-hint {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

#project-tiles {
  overflow-x: auto;
}

.project-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.project-table thead th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 6px 10px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  background: #f5f6f8;
}
.project-table thead th.num-col { text-align: right; }

.project-row {
  cursor: pointer;
  transition: background .1s;
}
.project-row:hover td {
  background: var(--badge-bg);
}
.project-row.selected td {
  background: #e8f7ef;
  font-weight: 600;
}
.project-row.selected .proj-col-code {
  color: var(--accent);
}

.project-row td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.proj-col-code {
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  width: 90px;
}
.proj-col-name {
  min-width: 160px;
}
.proj-col-city {
  color: var(--muted);
  white-space: nowrap;
}
.num-col {
  text-align: right;
  white-space: nowrap;
  width: 70px;
}
.proj-col-btn {
  width: 36px;
  text-align: center;
}
.proj-details-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 12px;
  color: var(--primary);
  transition: background .1s;
}
.proj-details-btn:hover { background: var(--badge-bg); }

.proj-details-subrow td {
  padding: 0 10px 10px 32px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
}
.tile-details-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 4px;
}
.tile-details-tbl th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 2px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tile-details-tbl td {
  padding: 2px 6px;
  color: var(--text);
  border-bottom: 1px dotted #e8e8e8;
}
.proj-detail-more td {
  color: var(--muted);
  font-style: italic;
}

/* ─── Status Filter Bar ──────────────────────────────────────────────────── */
.status-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 0 14px;
}

.status-filter-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.status-filter-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.status-filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .project-grid { grid-template-columns: 1fr; }
  .upload-grid  { grid-template-columns: 1fr; }
  .upload-grid .drop-zone:nth-child(3),
  .upload-grid .drop-zone:nth-child(4) { grid-column: 1; }
  .tabs { gap: 2px; }
  .tab  { padding: 7px 10px; font-size: 12px; }
}

/* ─── v4: automatic download via API ───────────────────────────────────── */
.api-fetch-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.btn-api {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-api:hover:not(:disabled) { background: var(--accent-h); }
.btn-api:disabled { opacity: .55; cursor: wait; }
.btn-api-key {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.btn-api-key:hover { border-color: var(--primary); color: var(--primary); }
.api-hint { font-size: 12px; color: var(--muted); flex: 1 1 260px; }
.api-status { font-size: 13px; margin-bottom: 12px; min-height: 0; }
.api-status:empty { display: none; }
.api-status.api-busy { color: var(--primary); }
.api-status.api-ok   { color: var(--accent); font-weight: 500; }
.api-status.api-warn { color: var(--warn); }
.api-status.api-err  { color: var(--danger); }

/* ─── Sugar i Cocon (enrich.js) ─────────────────────────────────────────── */
.enrich-block { margin-bottom: 26px; }
.enrich-block + .enrich-block { border-top: 1px solid var(--border); padding-top: 18px; }
.enrich-block h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.enrich-hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; max-width: 900px; }
.enrich-actions { flex-wrap: wrap; gap: 8px; justify-content: flex-start; }
.enrich-scope { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.enrich-scope select { font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px; background: #fff; color: var(--text); }
.status-summary { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.st-chip { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 10px; background: #eef1f5; }
.st-new       { background: #e6f5ec; color: #1e7a45; font-weight: 600; }
.st-reopened  { background: #fff4e0; color: #9a5b00; font-weight: 600; }
.st-cancelled { background: #fdecea; color: #a93226; font-weight: 600; }
.st-exists    { color: var(--muted); }
.cell-pre { white-space: pre; font-family: Consolas, 'Courier New', monospace; font-size: 11px; }
#tbl-sugar-status a, #tbl-cocon a { color: var(--primary); }
.st-review { background: #fff59d; color: #6b5a00; }
#tbl-sugar-status tbody tr.row-review td { background: #fff8c4; }
.review-hint { background: #fff8c4; border-left: 3px solid #e6c200; padding: 6px 10px; color: #5c4d00; }
