:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #697586;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-dark: #0d6b63;
  --soft: #f0fdfa;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  min-height: 34px;
  padding: 0 12px;
}

button:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }

.sso-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.sso-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: #ddd; }
.sso-name { font-weight: 600; font-size: 14px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-wrap: wrap;
}

.eyebrow { margin: 0 0 2px; color: var(--accent-dark); font-size: 12px; font-weight: 700; text-transform: uppercase; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; font-weight: 700; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions button:nth-child(2) { background: var(--accent); border-color: var(--accent); color: #fff; }

.workspace { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.status-bar { color: var(--muted); font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 14px;
  align-items: start;
}

.order-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}

.order-row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s;
}

.order-row:hover { background: var(--soft); }
.order-row.active { background: var(--soft); border-left: 3px solid var(--accent); }
.order-row:last-child { border-bottom: 0; }

.order-row-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.order-row-customer { font-size: 13px; }
.order-row-sub { font-size: 12px; color: var(--muted); }

.status-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; }

.order-editor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
}

.editor-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.editor-header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#editorStatus { font-size: 12px; color: var(--muted); }

.grid { display: grid; gap: 10px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 6px 10px;
  text-transform: none;
  font-size: 14px;
}

textarea { resize: vertical; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.item-head {
  display: grid;
  grid-template-columns: 1fr 64px 92px 80px 36px;
  gap: 6px;
  padding: 4px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.item-line {
  display: grid;
  grid-template-columns: 1fr 64px 92px 80px 36px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.il-total { font-size: 13px; text-align: right; }
.il-remove { padding: 0; min-width: 36px; font-size: 16px; }

.po-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.po-total-row { display: flex; gap: 24px; font-size: 13px; color: var(--muted); }
.po-total-row span:last-child { min-width: 90px; text-align: right; }
.po-total-row.grand { font-size: 15px; font-weight: 700; color: var(--ink); }

#emptyOrders { text-align: center; color: var(--muted); padding: 32px 16px; }

[hidden] { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .order-list { max-height: 300px; }
  .order-editor { max-height: none; }
  .grid.two { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
  .item-head { display: none; }
  .item-line { grid-template-columns: 1fr 56px 80px 64px 36px; }
}
