*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #dde1e7;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #4b5563;
  --secondary-hover: #374151;
  --success: #16a34a;
  --warning-bg: #fff3cd;
  --warning-strong: #ffcf40;
  --error: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

header { margin-bottom: 2rem; }
header h1 { font-size: 1.75rem; font-weight: 700; }
header .subtitle { color: var(--text-muted); margin-top: .25rem; }

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}

.card h3 {
  font-size: .95rem;
  font-weight: 600;
  margin: 1.5rem 0 .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.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: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Form */
.form-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: start;
  gap: .5rem 1rem;
  margin-bottom: 1rem;
}

.form-row label { font-weight: 500; padding-top: .55rem; }

input[type="text"] {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
input[type="text"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  user-select: none;
}
.dropzone:hover, .dropzone:focus { border-color: var(--primary); color: var(--primary); outline: none; }
.dropzone.drag-over { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.dropzone.has-file { border-color: var(--success); color: var(--success); background: #f0fdf4; }
.dropzone svg { opacity: .6; }

/* Buttons */
.btn-row {
  display: flex;
  gap: .75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.btn {
  padding: .55rem 1.2rem;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { background: #e5e7eb; color: var(--secondary); }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }

/* File list */
.file-list {
  list-style: none;
  margin-top: .75rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem .75rem;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
}
.file-list .file-name { font-weight: 500; }
.file-list .file-size { color: var(--text-muted); margin-left: .5rem; }
.file-list .btn-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 .25rem;
  transition: color .15s;
}
.file-list .btn-remove:hover { color: var(--error); }

/* Status box */
.status-box {
  margin-top: 1rem;
  padding: .7rem 1rem;
  border-radius: 6px;
  font-size: .9rem;
}
.status-box.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--success); }
.status-box.error   { background: #fef2f2; border: 1px solid #fecaca; color: var(--error); }

/* Results meta */
.results-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .5rem;
}
.meta-chip {
  padding: .3rem .75rem;
  border-radius: 20px;
  font-size: .85rem;
  font-weight: 500;
}
.meta-chip.total  { background: #eff6ff; color: var(--primary); }
.meta-chip.warn   { background: var(--warning-bg); color: #92400e; }
.meta-chip.ok     { background: #f0fdf4; color: var(--success); }

/* Tables */
.table-wrapper { overflow-x: auto; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: .875rem;
}
th, td {
  border: 1px solid var(--border);
  padding: .45rem .75rem;
  text-align: left;
  white-space: nowrap;
}
thead th {
  background: #f9fafb;
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
thead th:hover { background: #f3f4f6; }
thead th.sort-asc::after  { content: " ▲"; font-size: .7em; }
thead th.sort-desc::after { content: " ▼"; font-size: .7em; }

tbody tr:hover td { background: #f9fafb; }

/* Unmatched rows */
tr.row--unmatched td { background: var(--warning-bg); }
tr.row--unmatched:hover td { background: #fde68a; }
td.cell--unmatched { background: var(--warning-strong) !important; font-weight: 600; }

.export-row { margin-top: 1.5rem; }

/* Foreman section */
#foreman-summary-table td.cost-eur { color: #065f46; font-weight: 600; }
#foreman-summary-table td.cost-usd { color: #1e40af; font-weight: 600; }
#foreman-summary-table tfoot td    { font-weight: 700; background: #f9fafb; border-top: 2px solid var(--border); }

.foreman-error-item {
  padding: .5rem .75rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  color: var(--error);
  font-size: .875rem;
  margin-bottom: .4rem;
}

/* Unmatched debug */
.warn-heading { color: #92400e; }

#unmatched-debug-table td.hint-spaces  { color: #b45309; }
#unmatched-debug-table td.hint-case    { color: #6d28d9; }
#unmatched-debug-table td.hint-fuzzy   { color: #0369a1; }
#unmatched-debug-table td.hint-missing { color: var(--error); }

#unmatched-debug-table td.suggestion { font-family: monospace; font-weight: 600; }
#unmatched-debug-table td.serial-csv { font-family: monospace; }

/* Customer cost table */
#customer-cost-table .col-expand { width: 32px; text-align: center; }

tr.customer-row { cursor: pointer; }
tr.customer-row:hover td { background: #eff6ff; }
tr.customer-row td.col-expand { color: var(--primary); font-size: .8rem; transition: transform .2s; }
tr.customer-row.open td.col-expand { transform: rotate(90deg); display: inline-block; }

tr.location-sub-row td { background: #f9fafb; font-size: .85rem; }
tr.location-sub-row td:first-child { border-left: 3px solid var(--primary); }
tr.location-sub-row:hover td { background: #f0f7ff; }
tr.location-sub-row.hidden { display: none; }

tr.customer-row td.total-eur,
tr.location-sub-row td.total-eur { color: #065f46; font-weight: 600; }
tr.customer-row td.total-usd,
tr.location-sub-row td.total-usd { color: #1e40af; font-weight: 600; }
tr.customer-row td.no-price { color: var(--text-muted); font-style: italic; font-weight: 400; }

#customer-cost-table tfoot td { font-weight: 700; background: #f9fafb; border-top: 2px solid var(--border); }

/* Price editor */
.price-editor {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.price-editor > summary {
  padding: .65rem 1rem;
  font-weight: 500;
  font-size: .9rem;
  cursor: pointer;
  background: #f9fafb;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.price-editor > summary::before {
  content: '▶';
  font-size: .7rem;
  transition: transform .2s;
  color: var(--text-muted);
}
.price-editor[open] > summary::before { transform: rotate(90deg); }
.price-editor-body { padding: .75rem 1rem 1rem; }

#price-table input[type="text"],
#price-table input[type="number"] {
  width: 100%;
  padding: .3rem .5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: .875rem;
}
#price-table input:focus { border-color: var(--primary); outline: none; }

.btn-remove-row {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 0 .25rem;
  transition: color .15s;
}
.btn-remove-row:hover { color: var(--error); }

/* Location table cost highlight */
#location-table td.cost-eur { color: #065f46; font-weight: 600; }
#location-table td.cost-usd { color: #1e40af; font-weight: 600; }
#location-table tfoot td { font-weight: 700; background: #f9fafb; border-top: 2px solid var(--border); }

/* Spinner */
.spinner {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.spinner p { color: var(--text-muted); font-size: .95rem; }
.spinner-inner {
  width: 48px;
  height: 48px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%; max-width: 640px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.modal-serial   { font-family: monospace; font-size: 1.1rem; font-weight: 700; }
.modal-subtitle { color: var(--text-muted); font-size: .875rem; margin-top: .2rem; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.5rem; line-height: 1; color: var(--text-muted);
  padding: 0 .25rem; flex-shrink: 0;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow-y: auto;
}

/* Bar chart */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 100px;
  padding: 0 2px 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: .5rem;
}
.bar-chart .bar-col {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  height: 100%;
  justify-content: flex-end;
  cursor: default;
  position: relative;
}
.bar-chart .bar {
  width: 100%;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  opacity: .8;
  transition: opacity .15s;
  min-height: 2px;
}
.bar-col:hover .bar { opacity: 1; }
.bar-col .bar-label {
  font-size: .6rem;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  max-width: 100%;
  text-align: center;
}
.bar-col .bar-tooltip {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%; transform: translateX(-50%);
  background: #1a1d23; color: #fff;
  padding: .3rem .5rem;
  border-radius: 4px; font-size: .75rem;
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity .15s;
  z-index: 10;
}
.bar-col:hover .bar-tooltip { opacity: 1; }

/* Clickable miner rows */
#foreman-miner-table tbody tr { cursor: pointer; }
#foreman-miner-table tbody tr:hover td { background: #eff6ff; }

/* Console log panel */
.clog-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 300;
  font-family: "SF Mono", "Fira Mono", "Cascadia Code", monospace;
  font-size: .8rem;
  background: #0f1117;
  border-top: 2px solid #2d2f3a;
  box-shadow: 0 -4px 20px rgba(0,0,0,.35);
  transition: transform .2s ease;
}
.clog-panel.clog-minimized { transform: translateY(calc(100% - 36px)); }

.clog-header {
  height: 36px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 .75rem;
  cursor: pointer;
  user-select: none;
  background: #161820;
  border-bottom: 1px solid #2d2f3a;
}
.clog-title {
  display: flex; align-items: center; gap: 0;
  color: #9ca3af; font-size: .8rem; font-weight: 600;
  letter-spacing: .04em;
}
.clog-dot {
  width: 11px; height: 11px; border-radius: 50%; margin-right: 5px;
}
.clog-dot-red    { background: #ff5f57; }
.clog-dot-yellow { background: #febc2e; }
.clog-dot-green  { background: #28c840; }
.clog-badge {
  margin-left: .5rem;
  background: var(--primary);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: .05rem .4rem;
  border-radius: 10px;
  line-height: 1.4;
}
.clog-btn {
  background: none; border: none; cursor: pointer;
  color: #6b7280; font-size: .85rem; padding: .2rem .35rem;
  border-radius: 3px; transition: background .15s, color .15s;
}
.clog-btn:hover { background: #2d2f3a; color: #e5e7eb; }

.clog-body {
  height: 220px;
  overflow-y: auto;
  padding: .5rem .75rem .75rem;
  scroll-behavior: smooth;
}
.clog-body::-webkit-scrollbar { width: 6px; }
.clog-body::-webkit-scrollbar-track { background: transparent; }
.clog-body::-webkit-scrollbar-thumb { background: #2d2f3a; border-radius: 3px; }

#clog-lines { display: flex; flex-direction: column; gap: 2px; }

.clog-line {
  display: flex; gap: .6rem; align-items: baseline;
  padding: .15rem 0;
  border-bottom: 1px solid #1a1d25;
  animation: clog-in .15s ease;
}
@keyframes clog-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.clog-time { color: #4b5563; flex-shrink: 0; font-size: .72rem; }
.clog-icon { flex-shrink: 0; width: 1rem; text-align: center; }
.clog-msg  { color: #d1d5db; flex: 1; white-space: pre-wrap; word-break: break-all; }

.clog-line.info    .clog-msg { color: #d1d5db; }
.clog-line.success .clog-msg { color: #34d399; }
.clog-line.warn    .clog-msg { color: #fbbf24; }
.clog-line.error   .clog-msg { color: #f87171; }
.clog-line.request .clog-msg { color: #60a5fa; }
.clog-line.dim     .clog-msg { color: #4b5563; font-size: .75rem; }
.clog-line.sep     { border-bottom: 1px solid #2d2f3a; padding: .05rem 0; }
.clog-line.sep     .clog-msg { color: #2d2f3a; font-size: .7rem; letter-spacing: .15em; }

/* Utility */
.hidden { display: none !important; }

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
  .form-row label { padding-top: 0; }
}
