/* ============================================================
   DESIGN TOKENS — SAP FIORI (default)
   ============================================================ */
:root,
[data-theme="sap"] {
  --bg-page:          #f7f7f7;
  --bg-surface:       #ffffff;
  --bg-surface-alt:   #fafafa;
  --bg-topbar:        #0a6ed1;
  --bg-topbar-sub:    #0854a0;
  --bg-sidebar:       #ffffff;
  --bg-sidebar-hover: #f0f5fc;
  --bg-sidebar-active:#e8f2fd;
  --bg-row-hover:     #f0f5fc;
  --bg-table-head:    #f2f2f2;
  --bg-input:         #ffffff;

  --text-primary:     #1d2d3e;
  --text-secondary:   #6a6d70;
  --text-topbar:      #ffffff;
  --text-nav:         #1d2d3e;
  --text-nav-active:  #0a6ed1;
  --text-link:        #0a6ed1;
  --text-label:       #6a6d70;

  --border:           #e5e5e5;
  --border-input:     #89919a;
  --border-focus:     #0a6ed1;

  --accent:           #0a6ed1;
  --accent-hover:     #0854a0;
  --accent-danger:    #bb0000;

  --status-ok-bg:     #f1fdf6;
  --status-ok-text:   #107e3e;
  --status-ok-border: #107e3e;
  --status-warn-bg:   #fff8f6;
  --status-warn-text: #e9730c;
  --status-warn-border:#e9730c;
  --status-info-bg:   #ebf5ff;
  --status-info-text: #0a6ed1;
  --status-info-border:#0a6ed1;
  --status-gray-bg:   #f5f5f5;
  --status-gray-text: #6a6d70;
  --status-gray-border:#c2c2c2;

  --radius-sm:        4px;
  --radius-md:        4px;
  --radius-lg:        4px;
  --radius-pill:      4px;

  --font:             'Arial', 'Helvetica', sans-serif;
  --font-size:        13px;
  --font-size-sm:     11px;
  --font-size-xs:     10px;

  --topbar-height:    46px;
  --sidebar-width:    180px;
  --card-padding:     20px 24px;
  --nav-border-left:  none;
  --nav-border-bottom:3px solid transparent;
  --nav-active-border-bottom: 3px solid var(--accent);
  --table-head-case:  uppercase;
  --table-head-track: 0.3px;

  --btn-radius:       4px;
  --btn-font-size:    12px;
  --btn-padding:      5px 14px;

  --topbar-brand-size:   16px;
  --topbar-brand-weight: 700;
  --topbar-brand-track:  1px;
  --breadcrumb-show:  block;
  --sidebar-icon-show:none;
  --kpi-border-left:  none;
  --kpi-border-radius:4px;
}

/* ============================================================
   DESIGN TOKENS — INFOR MING.LE
   ============================================================ */
[data-theme="infor"] {
  --bg-page:          #1b1f2a;
  --bg-surface:       #252a38;
  --bg-surface-alt:   #1f2434;
  --bg-topbar:        #ce1126;
  --bg-topbar-sub:    #a50d1e;
  --bg-sidebar:       #141820;
  --bg-sidebar-hover: rgba(255,255,255,0.05);
  --bg-sidebar-active:#ce1126;
  --bg-row-hover:     rgba(206,17,38,0.07);
  --bg-table-head:    transparent;
  --bg-input:         #1b1f2a;

  --text-primary:     rgba(255,255,255,0.87);
  --text-secondary:   rgba(255,255,255,0.45);
  --text-topbar:      #ffffff;
  --text-nav:         rgba(255,255,255,0.55);
  --text-nav-active:  #ffffff;
  --text-link:        #6aabde;
  --text-label:       rgba(255,255,255,0.45);

  --border:           rgba(255,255,255,0.08);
  --border-input:     rgba(255,255,255,0.2);
  --border-focus:     #ce1126;

  --accent:           #ce1126;
  --accent-hover:     #a50d1e;
  --accent-danger:    #e74c3c;

  --status-ok-bg:     transparent;
  --status-ok-text:   #1abc9c;
  --status-ok-border: transparent;
  --status-warn-bg:   transparent;
  --status-warn-text: #f39c12;
  --status-warn-border:transparent;
  --status-info-bg:   transparent;
  --status-info-text: #6aabde;
  --status-info-border:transparent;
  --status-gray-bg:   transparent;
  --status-gray-text: rgba(255,255,255,0.35);
  --status-gray-border:transparent;

  --radius-sm:        3px;
  --radius-md:        6px;
  --radius-lg:        8px;
  --radius-pill:      50px;

  --font:             'Arial', 'Helvetica', sans-serif;
  --font-size:        12px;
  --font-size-sm:     10px;
  --font-size-xs:     9px;

  --topbar-height:    42px;
  --sidebar-width:    44px;
  --card-padding:     16px 18px;
  --nav-border-left:  3px solid transparent;
  --nav-border-bottom:none;
  --nav-active-border-bottom: none;
  --table-head-case:  uppercase;
  --table-head-track: 0.5px;

  --btn-radius:       6px;
  --btn-font-size:    11px;
  --btn-padding:      4px 12px;

  --topbar-brand-size:   15px;
  --topbar-brand-weight: 400;
  --topbar-brand-track:  2px;
  --breadcrumb-show:  none;
  --sidebar-icon-show:flex;
  --kpi-border-left:  3px solid #ce1126;
  --kpi-border-radius:6px;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: var(--font-size);
  background: var(--bg-page);
  color: var(--text-primary);
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height);
  background: var(--bg-topbar);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  transition: background 0.2s, height 0.2s;
}

.eyebrow {
  font-size: var(--font-size-xs);
  color: rgba(255,255,255,0.65);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
  margin-bottom: 1px;
}
[data-theme="infor"] .eyebrow { display: none; }

.topbar h1 {
  font-size: var(--topbar-brand-size);
  font-weight: var(--topbar-brand-weight);
  color: var(--text-topbar);
  letter-spacing: var(--topbar-brand-track);
  line-height: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.topbar-actions label {
  font-size: var(--font-size-sm);
  color: rgba(255,255,255,0.7);
}

.topbar-actions input[type="text"] {
  height: 28px;
  padding: 0 8px;
  font-size: var(--font-size-sm);
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-sm);
  color: #fff;
  width: 220px;
  outline: none;
  font-family: var(--font);
  transition: border-color 0.15s;
}
.topbar-actions input[type="text"]:focus {
  border-color: rgba(255,255,255,0.6);
}
.topbar-actions input[type="text"]::placeholder {
  color: rgba(255,255,255,0.4);
}

/* Topbar buttons */
#saveApiBase, #langToggle {
  height: 28px;
  padding: 0 12px;
  font-size: var(--font-size-sm);
  font-family: var(--font);
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
#saveApiBase:hover, #langToggle:hover {
  background: rgba(255,255,255,0.25);
}

/* Theme switcher */
.switcher-wrap {
  display: flex;
  align-items: center;
  background: rgba(0,0,0,0.15);
  border-radius: 50px;
  padding: 3px;
  gap: 0;
}

.switcher-btn {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 12px;
  border-radius: 50px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.5);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.switcher-btn.active {
  background: rgba(255,255,255,0.22);
  color: #fff;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.2s, background 0.2s;
}

[data-theme="sap"] .sidebar { padding: 0; }

.nav-btn {
  font-family: var(--font);
  font-size: var(--font-size-sm);
  text-align: left;
  background: transparent;
  border: none;
  border-left: var(--nav-border-left);
  color: var(--text-nav);
  cursor: pointer;
  padding: 10px 16px;
  width: 100%;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn::before {
  content: attr(data-icon);
  font-size: 14px;
  flex-shrink: 0;
  display: var(--sidebar-icon-show);
}

[data-theme="sap"] .nav-btn {
  border-bottom: var(--nav-border-bottom);
  border-left: none;
  font-size: 13px;
  padding: 12px 16px;
}

.nav-btn:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-nav-active);
}

.nav-btn.active {
  background: var(--bg-sidebar-active);
  color: var(--text-nav-active);
  font-weight: 500;
}

[data-theme="sap"] .nav-btn.active {
  color: var(--accent);
  background: var(--bg-sidebar-active);
  border-left: 3px solid var(--accent);
}

[data-theme="infor"] .nav-btn.active {
  border-left-color: var(--accent);
  color: #fff;
}

/* ============================================================
   CONTENT AREA
   ============================================================ */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view { display: flex; flex-direction: column; gap: 14px; }
.view.hidden { display: none; }

/* ============================================================
   BREADCRUMB (SAP only)
   ============================================================ */
.breadcrumb {
  display: var(--breadcrumb-show);
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  padding: 0 0 4px;
}
.breadcrumb a { color: var(--text-link); text-decoration: none; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--card-padding);
  transition: background 0.2s, border-color 0.2s;
}

.card h2 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

[data-theme="infor"] .card h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ============================================================
   FORMS
   ============================================================ */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

label span, label > :first-child:not(input):not(select) {
  font-size: var(--font-size-xs);
  color: var(--text-label);
  font-weight: 500;
  text-transform: var(--table-head-case);
  letter-spacing: var(--table-head-track);
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  height: 32px;
  padding: 0 10px;
  font-size: var(--font-size);
  font-family: var(--font);
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(10, 110, 209, 0.1);
}
[data-theme="infor"] input:focus,
[data-theme="infor"] select:focus {
  box-shadow: 0 0 0 2px rgba(206, 17, 38, 0.15);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236a6d70'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
[data-theme="infor"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(255,255,255,0.4)'/%3E%3C/svg%3E");
}

.form-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
  grid-column: 1 / -1;
  padding-top: 4px;
}

/* ============================================================
   BUTTONS
   ============================================================ */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: var(--btn-font-size);
  font-weight: 500;
  padding: var(--btn-padding);
  border-radius: var(--btn-radius);
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}

button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:active { opacity: 0.85; }

/* Ghost / secondary buttons */
#refreshWo,
#detailViewBtn,
#detailTreeBtn,
#detailSyncBtn,
#refreshRecipes,
#dedupeLinesBtn,
#exportMappingsBtn,
#demoRunBtn {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
#refreshWo:hover,
#detailViewBtn:hover,
#detailTreeBtn:hover,
#detailSyncBtn:hover,
#refreshRecipes:hover,
#dedupeLinesBtn:hover,
#exportMappingsBtn:hover,
#demoRunBtn:hover { background: var(--bg-row-hover); }

/* Danger buttons */
#demoResetBtn,
#detailSubmitBtn {
  background: transparent;
  color: var(--accent-danger);
  border-color: var(--accent-danger);
}
#demoResetBtn:hover, #detailSubmitBtn:hover {
  background: #fff0f0;
}
[data-theme="infor"] #demoResetBtn:hover,
[data-theme="infor"] #detailSubmitBtn:hover {
  background: rgba(231, 76, 60, 0.1);
}

/* Inline table action buttons */
.btn-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.btn-row button {
  font-size: 10px;
  padding: 2px 8px;
}
.btn-row .btn-ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-row .btn-ghost:hover { background: var(--bg-row-hover); }
.btn-row .btn-danger {
  background: transparent;
  color: var(--accent-danger);
  border-color: var(--accent-danger);
}

/* ============================================================
   TABLES
   ============================================================ */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size);
  margin-top: 10px;
}

thead tr {
  background: var(--bg-table-head);
  border-bottom: 1px solid var(--border);
}

thead th {
  padding: 7px 10px;
  text-align: left;
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: var(--table-head-case);
  letter-spacing: var(--table-head-track);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-row-hover); }
tbody tr.selected { background: var(--bg-row-hover); }

tbody td {
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: var(--font-size);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.td-secondary {
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
}

td.td-mono {
  font-family: monospace;
  font-size: 10px;
  color: var(--text-secondary);
  max-width: 130px;
}

/* ============================================================
   STATUS BADGES
   ============================================================ */
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}
[data-theme="sap"] .status-dot { display: none; }

.status-ok    { background: var(--status-ok-bg);   color: var(--status-ok-text);   border-color: var(--status-ok-border); }
.status-warn  { background: var(--status-warn-bg);  color: var(--status-warn-text);  border-color: var(--status-warn-border); }
.status-info  { background: var(--status-info-bg);  color: var(--status-info-text);  border-color: var(--status-info-border); }
.status-gray  { background: var(--status-gray-bg);  color: var(--status-gray-text);  border-color: var(--status-gray-border); }

[data-theme="infor"] .status-ok   .status-dot { background: #1abc9c; }
[data-theme="infor"] .status-warn .status-dot { background: #f39c12; }
[data-theme="infor"] .status-info .status-dot { background: #6aabde; }
[data-theme="infor"] .status-gray .status-dot { background: rgba(255,255,255,0.25); }

/* Helper: map work order status strings to badge classes */
.status[data-status="completed"]  { background: var(--status-ok-bg);   color: var(--status-ok-text);   border-color: var(--status-ok-border); }
.status[data-status="prefilled"]  { background: var(--status-ok-bg);   color: var(--status-ok-text);   border-color: var(--status-ok-border); }
.status[data-status="synced"]     { background: var(--status-info-bg);  color: var(--status-info-text);  border-color: var(--status-info-border); }
.status[data-status="created"]    { background: var(--status-info-bg);  color: var(--status-info-text);  border-color: var(--status-info-border); }
.status[data-status="mock"]       { background: var(--status-gray-bg);  color: var(--status-gray-text);  border-color: var(--status-gray-border); }

/* ============================================================
   DETAIL ACTIONS BAR
   ============================================================ */
.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* ============================================================
   PRE / CODE DUMP
   ============================================================ */
pre {
  font-family: monospace;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 8px;
  line-height: 1.5;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: #fff;
  background: #1d2d3e;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: 360px;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }
.toast.error  { background: var(--accent-danger); }
.toast.success{ background: #107e3e; }
[data-theme="infor"] .toast { background: #252a38; border: 1px solid rgba(255,255,255,0.1); }

/* ============================================================
   SCROLLBARS
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-input); }

/* ============================================================
   TRANSITIONS (theme switch)
   ============================================================ */
.theme-transitioning * {
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease !important;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-actions input[type="text"] { width: 140px; }
  [data-theme="sap"] .sidebar { width: 44px; }
  [data-theme="sap"] .nav-btn { padding: 12px; font-size: 0; }
}
