:root {
  --bg: #1A1D23;
  --surface: #22262E;
  --surface-raised: #2A2F38;
  --border: #363C47;
  --text: #ECEEF1;
  --text-muted: #8A919E;
  --accent: #FFB020;
  --accent-text: #1A1D23;
  --ok: #3DDC84;
  --diff: #FF8A3D;
  --danger: #FF5C5C;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.screen { min-height: 100%; }
[hidden] { display: none !important; }

/* ---------- ecrã de upload ---------- */
#screen-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.upload-card {
  width: 100%;
  max-width: 420px;
}

h1 {
  font-size: 28px;
  margin: 0 0 2px;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 28px;
  font-size: 15px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin: 20px 0 8px;
}

.toggle-group {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
}

.toggle-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 12px 8px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.toggle-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 90px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

.file-drop.has-file {
  border-color: var(--ok);
  color: var(--text);
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 10px 2px 0;
}

.warning-banner {
  font-size: 13px;
  color: var(--diff);
  background: rgba(255, 138, 61, 0.1);
  border: 1px solid var(--diff);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 14px 0 0;
  line-height: 1.4;
}

.btn-primary {
  width: 100%;
  margin-top: 28px;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:disabled {
  background: var(--surface-raised);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-secondary {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.restore-row {
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- ecrã de contagem ---------- */
#screen-count { display: flex; flex-direction: column; height: 100%; }

.count-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 14px 0;
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
}

.header-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.header-title strong { font-size: 15px; }
.header-title span { font-size: 12px; color: var(--text-muted); }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.search-row { padding-bottom: 10px; }

#search-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}

#search-input::placeholder { color: var(--text-muted); }

.filter-row {
  display: flex;
  gap: 8px;
  padding-bottom: 10px;
  overflow-x: auto;
}

.filter-chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--text-muted);
}

/* ---------- lista de materiais ---------- */
.list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 100px;
}

.row {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.row.counted { border-color: var(--ok); }
.row.diff { border-color: var(--diff); }

.row.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.list.has-selection .row:not(.selected) {
  opacity: 0.35;
}

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.row-model {
  font-size: 15px;
  font-weight: 700;
}

.row-loc {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.row-sap {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.row-inputs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.qty-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.qty-field label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.qty-field input {
  width: 100%;
  padding: 12px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.qty-field input.filled {
  border-color: var(--ok);
  background: rgba(61, 220, 132, 0.08);
}

.qty-field input.filled.diff {
  border-color: var(--diff);
  background: rgba(255, 138, 61, 0.1);
}

.mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 18px;
  flex-shrink: 0;
  cursor: pointer;
  align-self: flex-end;
}

.mic-btn.listening {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.row-meta {
  margin-top: 7px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.row-meta .prev-value { color: var(--diff); }

.row-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.row-action-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-muted);
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}

.row-action-btn.has-note {
  color: var(--accent);
  border-color: var(--accent);
}

.history-list {
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 4px;
}

.history-entry {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.history-entry:last-child { border-bottom: none; }
.history-entry .field-name { color: var(--text-muted); }
.history-entry .change { font-variant-numeric: tabular-nums; }
.history-entry .when { color: var(--text-muted); font-size: 11px; white-space: nowrap; }

.note-textarea {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  margin-bottom: 16px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 60px;
  font-size: 14px;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(22px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  cursor: pointer;
  z-index: 6;
}

.modal-field {
  margin-bottom: 14px;
}

.modal-field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.modal-field input {
  width: 100%;
  padding: 12px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 15px;
}

.extra-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent-text);
  background: var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

.modal-card {
  background: var(--surface);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: 22px 20px calc(20px + var(--safe-bottom));
  width: 100%;
}

.modal-title { font-size: 16px; font-weight: 700; margin: 0 0 6px; }
.modal-detail { font-size: 14px; color: var(--text-muted); margin: 0 0 18px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn-primary { margin-top: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 30;
}
