:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1c202b;
  --border: #262b38;
  --text: #e4e6eb;
  --text-dim: #8b93a7;
  --accent: #4a9de0;
  --mono: 'SF Mono', 'Consolas', 'Menlo', monospace;

  --c-matched: #8b93a7;
  --c-awaiting_bill: #d9a441;
  --c-bill_fetched: #4a9de0;
  --c-attached_to_odoo: #3ecf8e;
  --c-failed: #e0574a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
.mono { font-family: var(--mono); }

/* ---- Topbar ---- */
.topbar { border-bottom: 1px solid var(--border); background: var(--panel); }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.brand { font-weight: 700; font-size: 15px; color: var(--text); }
.topbar nav { display: flex; gap: 20px; flex: 1; margin-left: 32px; }
.topbar nav a { color: var(--text-dim); font-size: 14px; }
.topbar nav a:hover { color: var(--text); }
.user-menu { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--text-dim); }
.role-badge {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 20px;
  padding: 2px 9px; font-size: 11px; text-transform: capitalize; margin-left: 6px;
}
.logout-link { color: var(--text-dim); }
.logout-link:hover { color: var(--c-failed); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
main.auth-page { max-width: 420px; margin: 80px auto; padding: 0; }

/* ---- Flash messages ---- */
.flash-messages { margin-bottom: 16px; }
.flash { padding: 10px 16px; border-radius: 8px; font-size: 13.5px; margin-bottom: 8px; }
.flash-error { background: rgba(224,87,74,0.12); color: var(--c-failed); border: 1px solid rgba(224,87,74,0.3); }
.flash-success { background: rgba(62,207,142,0.12); color: var(--c-attached_to_odoo); border: 1px solid rgba(62,207,142,0.3); }

/* ---- Cards / forms ---- */
.auth-card, .form-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px;
}
.auth-card h1, .form-card h1 { margin: 0 0 6px 0; font-size: 20px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 20px 0; }
label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 14px; }
input, select {
  display: block; width: 100%; margin-top: 6px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
  color: var(--text); font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.btn {
  border: none; border-radius: 8px; padding: 10px 18px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: #08111c; }
.btn-full { width: 100%; }
.btn-link { background: none; border: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 0; }
.fetch-btn {
  background: var(--accent); color: #08111c; border: none; border-radius: 6px;
  padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: opacity .15s, transform .1s;
}
.fetch-btn:hover { opacity: .85; transform: scale(1.03); }
.fetch-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { font-size: 20px; margin: 0; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { margin-top: 0; }

/* ---- Tables ---- */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 1100px; }
thead th {
  text-align: left; padding: 12px 16px; color: var(--text-dim); font-weight: 500;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.empty { text-align: center; color: var(--text-dim); padding: 40px 16px; }
.notes {
  color: var(--c-failed); font-size: 12px; max-width: 130px;
  word-wrap: break-word; overflow-wrap: break-word;
  line-height: 1.5;
}

.status-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.status-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-matched { color: var(--c-matched); background: rgba(139,147,167,0.12); }
.status-awaiting_bill { color: var(--c-awaiting_bill); background: rgba(217,164,65,0.12); }
.status-bill_fetched { color: var(--c-bill_fetched); background: rgba(74,157,224,0.12); }
.status-attached_to_odoo { color: var(--c-attached_to_odoo); background: rgba(62,207,142,0.12); }
.status-failed { color: var(--c-failed); background: rgba(224,87,74,0.12); }

/* ---- Filters ---- */
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
  padding: 6px 14px; border-radius: 20px; font-size: 13px; cursor: pointer;
}
.filter-btn:hover { color: var(--text); }
.filter-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }
.hint-inline { color: var(--text-dim); font-size: 12px; font-weight: 400; }

/* ---- Toast Notification ---- */
.toast {
  position: fixed; top: 20px; right: 20px; width: 380px; max-width: calc(100vw - 40px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35); z-index: 9999; overflow: hidden;
  animation: toastIn .3s cubic-bezier(.4,0,.2,1);
}
.toast-success { border-left: 4px solid #48BB78; }
.toast-error { border-left: 4px solid #E53E3E; }
.toast-hide { animation: toastOut .4s ease forwards; }

@keyframes toastIn { from{opacity:0;transform:translateX(60px)} to{opacity:1;transform:translateX(0)} }
@keyframes toastOut { from{opacity:1;transform:translateX(0)} to{opacity:0;transform:translateX(60px)} }

.toast-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--border); background: var(--panel-2);
}
.toast-icon { font-size: 22px; }
.toast-title { font-weight: 700; font-size: 15px; color: var(--text); flex: 1; }
.toast-close {
  background: none; border: none; color: var(--text-dim); font-size: 16px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.toast-close:hover { background: var(--border); color: var(--text); }

.toast-body { padding: 14px 16px; }
.toast-section { margin-bottom: 12px; }
.toast-section:last-child { margin-bottom: 0; }
.toast-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-dim); margin-bottom: 6px; font-weight: 600;
}
.toast-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 0; font-size: 13px;
}
.toast-label { color: var(--text-dim); font-size: 12px; }
.toast-docs {
  display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px;
}
.toast-warning {
  background: rgba(217,164,65,.12); border: 1px solid rgba(217,164,65,.25);
  border-radius: 8px; padding: 8px 12px; font-size: 12px; color: var(--c-awaiting_bill);
  margin-top: 10px;
}
.toast-error-msg {
  color: var(--c-failed); font-size: 13px; line-height: 1.5;
}

@media (max-width: 480px) {
  .toast { top: 10px; right: 10px; width: calc(100vw - 20px); }
  .toast-header { padding: 10px 12px; }
  .toast-body { padding: 10px 12px; }
  .toast-docs { gap: 8px; font-size: 12px; }
}

/* ---- Setup wizard ---- */
.wizard-steps { display: flex; gap: 10px; margin-bottom: 24px; flex-wrap: wrap; }
.step-pill {
  padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border);
  color: var(--text-dim); font-size: 13px;
}
.step-pill.unlocked { color: var(--text); border-color: var(--accent); }
.step-pill.done { color: var(--c-attached_to_odoo); border-color: var(--c-attached_to_odoo); }

.wizard-panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; margin-bottom: 18px; position: relative;
}
.wizard-panel h2 { margin-top: 0; font-size: 16px; }
.wizard-panel.locked { opacity: 0.4; pointer-events: none; }
.wizard-panel.locked::after {
  content: 'Complete the previous step to unlock'; position: absolute; top: 24px; right: 24px;
  font-size: 12px; color: var(--text-dim); font-style: italic;
}
.hint { color: var(--text-dim); font-size: 13px; margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* ================================================================
   RESPONSIVE — covers header, table, filters, wizard on all devices
   ================================================================ */

/* ---- Tablet (≤ 900px) ---- */
@media (max-width: 900px) {
  .topbar-inner { padding: 12px 16px; gap: 12px; }
  .topbar nav { margin-left: 16px; gap: 14px; }
  main { padding: 16px; }
  thead th, tbody td { padding: 10px 10px; font-size: 12.5px; }
  .notes { max-width: 180px; }
}

/* ---- Mobile (≤ 768px) ---- */
@media (max-width: 768px) {
  .topbar-inner {
    flex-wrap: wrap; padding: 10px 14px; gap: 8px;
  }
  .brand { font-size: 14px; }
  .topbar nav {
    order: 3; width: 100%; margin-left: 0; gap: 16px;
    border-top: 1px solid var(--border); padding-top: 8px;
  }
  .user-menu { font-size: 12px; gap: 8px; }
  .user-menu .user-email { display: none; }

  main { padding: 12px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .page-header h1 { font-size: 18px; }

  .filters { gap: 6px; }
  .filter-btn { padding: 5px 10px; font-size: 12px; }
  select { font-size: 13px; }

  /* Table → scrollable horizontally */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
  table { min-width: 800px; font-size: 12px; }
  thead th { padding: 8px; font-size: 10.5px; white-space: nowrap; }
  tbody td { padding: 8px; }
  .notes { max-width: 140px; font-size: 11px; }
  .status-badge { font-size: 11px; padding: 2px 8px; }

  /* Wizard */
  .wizard-steps { gap: 6px; }
  .step-pill { font-size: 11px; padding: 4px 8px; }
}

/* ---- Small mobile (≤ 480px) ---- */
@media (max-width: 480px) {
  .topbar-inner { padding: 8px 10px; }
  .brand { font-size: 13px; }
  .topbar nav { gap: 12px; }
  .topbar nav a { font-size: 13px; }
  .role-badge { font-size: 10px; padding: 1px 6px; }

  main { padding: 8px; }
  .page-header h1 { font-size: 16px; }

  .filters { flex-direction: column; align-items: stretch; }
  .filters select { width: 100%; }
  .filter-btn { font-size: 11px; padding: 4px 8px; }

  table { min-width: 700px; font-size: 11px; }
  thead th { padding: 6px; font-size: 10px; }
  tbody td { padding: 6px; }

  .auth-card, .form-card { padding: 16px; }
  .btn { padding: 8px 14px; font-size: 13px; }

  .wizard-panel { padding: 14px; }
  .wizard-panel h2 { font-size: 14px; }
  .condition-row { flex-direction: column; gap: 6px; }
  .condition-row input, .condition-row select { width: 100%; }
}

.condition-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.condition-row input { margin-top: 0; }
.condition-row .cond-field, .condition-row .cond-value { flex: 1; }
.condition-row .cond-op { width: 110px; margin-top: 0; }

.test-result { margin-left: 12px; font-size: 13px; }
.test-ok { color: var(--c-attached_to_odoo); }
.test-fail { color: var(--c-failed); }

.discover-output {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; font-family: var(--mono); font-size: 12px; color: var(--text-dim);
  white-space: pre-wrap; max-height: 300px; overflow-y: auto; margin-top: 10px;
}

.error-page { text-align: center; padding: 80px 0; }
.error-page h1 { font-size: 48px; margin: 0; color: var(--text-dim); }