:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #697586;
  --line: #d9dee7;
  --accent: #059669;
  --accent-dark: #047857;
  --soft: #f0fdf4;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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); }
.btn-schedule { color: var(--accent); border-color: var(--accent); }
.btn-schedule:hover { background: var(--accent); color: #fff; }

.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: 1; min-height: 0; flex-direction: column; gap: 12px; overflow: hidden; }
.status-bar { color: var(--muted); font-size: 13px; }

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

.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; }

.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }

.customer-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 10px 12px;
  min-height: 52px;
  color: var(--muted);
}
.customer-card strong { display: block; color: var(--ink); }

#emptyBookings { 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; }
}

/* SSO banner actions */
.sso-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.btn-link { color: var(--muted); font-size: 12px; text-decoration: none; padding: 4px 8px; border-radius: 4px; }
.btn-link:hover { color: var(--accent-dark); background: var(--soft); }
.btn-sm { font-size: 12px; min-height: 28px; padding: 0 10px; }
.crm-pick-btn { font-size: 12px; min-height: 28px; padding: 0 10px; color: var(--accent); border-color: var(--accent); }
.btn-service { color: var(--accent); border-color: var(--accent); }
.btn-service:hover { background: var(--accent); color: #fff; }

/* CRM Picker Modal */
.modal-overlay { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-panel { background: var(--panel); border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.18); width: 100%; max-width: 520px; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-header h3 { font-size: 15px; font-weight: 700; color: var(--ink); }
.modal-close { min-height: 28px; padding: 0 10px; font-size: 18px; line-height: 1; }
.modal-search { margin: 10px 16px 6px; width: calc(100% - 32px); }
.crm-results { flex: 1; overflow-y: auto; padding: 6px 8px 10px; }
.crm-result-row { padding: 10px; border-radius: 6px; cursor: pointer; }
.crm-result-row:hover { background: var(--soft); }
.crm-result-row strong { display: block; color: var(--ink); font-size: 14px; }
.crm-result-row span { display: block; color: var(--muted); font-size: 12px; }
.crm-no-results { text-align: center; color: var(--muted); padding: 24px; }
.field-row { display: flex; gap: 8px; align-items: center; }
.field-row input { flex: 1; }
