*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3345;
  --text: #e4e6ed;
  --text-dim: #8b8fa3;
  --primary: #4a7cff;
  --primary-hover: #3a6af0;
  --success: #34c759;
  --danger: #ff453a;
  --warning: #ff9f0a;
  --radius: 12px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 1rem; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.5rem 2rem; text-align: center; width: 100%; max-width: 380px;
}
.login-card h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-subtitle { color: var(--text-dim); margin-bottom: 2rem; }
.btn-microsoft {
  display: inline-flex; align-items: center; gap: 0.75rem; background: #fff; color: #1a1a1a;
  font-size: 1rem; font-weight: 600; padding: 0.75rem 1.5rem; border-radius: 8px;
  text-decoration: none; transition: box-shadow 0.15s;
}
.btn-microsoft:hover { box-shadow: 0 2px 12px rgba(74, 124, 255, 0.3); }
.error-msg { margin-top: 1.5rem; color: var(--danger); font-size: 0.875rem; }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100; flex-wrap: wrap; gap: 0.5rem;
}
.app-header h1 { font-size: 1.125rem; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; }
.header-logo { width: 24px; height: 24px; }
.phase-tag {
  font-size: 0.65rem; font-weight: 600; color: var(--warning); border: 1px solid var(--warning);
  border-radius: 6px; padding: 0.1rem 0.4rem; letter-spacing: 0.03em; text-transform: uppercase;
}
.header-right { display: flex; align-items: center; gap: 1rem; font-size: 0.875rem; }
#user-name { color: var(--text-dim); }
.btn-logout {
  color: var(--text-dim); text-decoration: none; font-size: 0.8rem; padding: 0.25rem 0.5rem;
  border: 1px solid var(--border); border-radius: 6px;
}

/* Tabs */
.tabs { display: flex; gap: 0.25rem; }
.tab {
  background: none; border: 1px solid transparent; color: var(--text-dim); font-size: 0.85rem;
  font-weight: 600; padding: 0.4rem 0.75rem; border-radius: 8px; cursor: pointer; font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--surface2); border-color: var(--border); }

/* Views */
.view { display: none; padding: 1.25rem; max-width: 1000px; margin: 0 auto; }
.view.active { display: block; }

.section-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; }
.section-header h2 { font-size: 1.25rem; font-weight: 600; }
.hint { font-weight: 400; color: var(--text-dim); font-size: 0.8rem; }
.note { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1rem; line-height: 1.5; }

/* Inputs */
.input {
  width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 1rem; padding: 0.65rem 0.75rem; margin-bottom: 1rem;
  font-family: inherit; -webkit-appearance: none;
}
.input:focus { outline: none; border-color: var(--primary); }

/* Tables */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table thead th {
  text-align: left; background: var(--surface2); color: var(--text-dim); font-weight: 600;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.6rem 0.9rem;
  position: sticky; top: 0;
}
.data-table tbody td { padding: 0.6rem 0.9rem; border-top: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr:hover { background: var(--surface); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table.mini { font-size: 0.82rem; }
.data-table.mini thead th { text-transform: none; letter-spacing: 0; }
.prod-name { font-weight: 600; }
.prod-desc { color: var(--text-dim); font-size: 0.8rem; margin-top: 0.15rem; max-width: 460px; }

/* Config / picklist cards */
.cfg-h { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); margin: 1.5rem 0 0.5rem; }
.cfg-h:first-child { margin-top: 0; }
.pl-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 0.75rem; }
.pl-title { font-weight: 600; margin-bottom: 0.6rem; display: flex; align-items: center; gap: 0.5rem; }
.pl-meta { font-weight: 400; color: var(--text-dim); font-size: 0.75rem; }
.pl-meta.missing { color: var(--warning); }
.badge { font-size: 0.65rem; background: var(--primary); color: #fff; border-radius: 4px; padding: 0.05rem 0.35rem; }

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 0.75rem 1.25rem; border-radius: 10px; font-size: 0.9rem; font-weight: 500;
  opacity: 0; transition: transform 0.3s, opacity 0.3s; z-index: 200; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* States */
.loading { text-align: center; color: var(--text-dim); padding: 2rem; }
.empty-state { text-align: center; color: var(--text-dim); padding: 3rem 1rem; }
.empty-state.small { padding: 1rem; font-size: 0.85rem; }

/* ===== Phase 2: templates ===== */

/* Buttons (variants on the base .btn) */
.btn-inline, .btn-sm { display: inline-block; width: auto; }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.85rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #e03a30; }
.btn-icon {
  background: none; border: 1px solid var(--border); color: var(--text); font-size: 1.1rem;
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; flex: none;
}
.btn-icon:hover { border-color: var(--primary); }
.btn-icon.danger { color: var(--danger); }
.btn-icon.danger:hover { border-color: var(--danger); }

/* Form section (editor meta) */
.form-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.form-section label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; }
.btn-back { background: none; border: none; color: var(--primary); font-size: 0.95rem; cursor: pointer; padding: 0.5rem 0; margin-bottom: 0.5rem; }

/* Templates list */
.tpl-card { display: flex; align-items: stretch; gap: 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.tpl-card:hover { border-color: var(--primary); }
.tpl-main { flex: 1; cursor: pointer; }
.tpl-name { font-weight: 600; font-size: 1.05rem; }
.tpl-cat { display: inline-block; font-size: 0.72rem; color: var(--primary); border: 1px solid var(--primary); border-radius: 5px; padding: 0.05rem 0.4rem; margin-top: 0.3rem; }
.tpl-desc { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.35rem; }
.tpl-meta { color: var(--text-dim); font-size: 0.78rem; margin-top: 0.45rem; }
.tpl-actions { display: flex; flex-direction: column; gap: 0.4rem; }

/* Editor sections */
.sec-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 0.75rem; }
.sec-head { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.6rem; }
.sec-name { margin-bottom: 0 !important; font-weight: 600; }
.sec-items { margin-bottom: 0.6rem; }
.sec-empty { color: var(--text-dim); font-size: 0.82rem; padding: 0.3rem 0 0.7rem; }
.it-name { font-weight: 500; }
.it-id { color: var(--text-dim); font-size: 0.75rem; margin-left: 0.4rem; }
.qty { margin-bottom: 0 !important; padding: 0.35rem 0.5rem !important; text-align: right; }
.editor-footer { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.editor-footer .btn { width: auto; min-width: 110px; }

/* Product picker modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 1rem; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; width: 100%; max-width: 520px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 1.5rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.picker-results { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.picker-row { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; width: 100%; text-align: left; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.75rem; cursor: pointer; color: var(--text); font-family: inherit; }
.picker-row:hover { border-color: var(--primary); }
.pr-name { font-weight: 600; font-size: 0.92rem; }
.pr-meta { color: var(--text-dim); font-size: 0.78rem; }

/* Picker type toggle + item-type badges */
.picker-types { display: flex; gap: 0.3rem; margin-bottom: 0.6rem; }
.ptype { background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); font-size: 0.8rem; font-weight: 600; padding: 0.35rem 0.75rem; border-radius: 7px; cursor: pointer; font-family: inherit; }
.ptype:hover { color: var(--text); }
.ptype.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.it-type { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.03em; border-radius: 4px; padding: 0.05rem 0.35rem; margin-left: 0.4rem; vertical-align: middle; }
.it-type.service { background: rgba(52,199,89,0.18); color: var(--success); }
.it-type.labor { background: rgba(255,159,10,0.18); color: var(--warning); }
.it-type.missing { background: rgba(255,69,58,0.18); color: var(--danger); }

/* ===== Phase 3: build quote ===== */
.combo { position: relative; }
.combo-results { position: absolute; top: calc(100% - 0.5rem); left: 0; right: 0; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.25rem; padding: 0.35rem; box-shadow: 0 8px 24px rgba(0,0,0,0.45); }
.combo-row { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; width: 100%; text-align: left; background: var(--surface2); border: 1px solid var(--border); border-radius: 7px; padding: 0.5rem 0.65rem; cursor: pointer; color: var(--text); font-family: inherit; }
.combo-row:hover { border-color: var(--primary); }
.selected-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.75rem; margin-bottom: 1rem; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.85rem; font-family: inherit; }
.builder-actions { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.quote-summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-top: 1rem; }
.qs-row { display: flex; justify-content: space-between; align-items: center; }
.qs-row.grand { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.85rem; }
.qs-row.grand span:last-child { color: var(--primary); }
.center { text-align: center; margin-top: 0.5rem; }
.sec-sub-label { color: var(--text-dim); text-align: right; font-size: 0.78rem; }
.sec-subtotal { font-weight: 600; }
.data-table tfoot td { border-top: 1px solid var(--border); }
