*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[x-cloak] { display: none !important; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: #f5f5f5;
  color: #222;
}

/* Nav */
.navbar {
  background: #1a1a2e;
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  height: 52px;
  gap: 2rem;
}
.nav-brand a { color: #fff; font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.nav-links { display: flex; gap: 1.25rem; flex: 1; }
.nav-links a { color: #ccc; text-decoration: none; font-size: 0.9rem; }
.nav-links a:hover { color: #fff; }
.nav-user { display: flex; align-items: center; gap: 1rem; color: #aaa; font-size: 0.85rem; }
.btn-link { background: none; border: none; color: #aaa; cursor: pointer; font-size: 0.85rem; }
.btn-link:hover { color: #fff; }

/* Container */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* Page header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 600; }

/* Buttons */
.btn { display: inline-block; padding: 0.45rem 1rem; border-radius: 4px; border: none; cursor: pointer; font-size: 0.875rem; text-decoration: none; font-weight: 500; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #e5e7eb; color: #374151; }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

/* Table */
.table-wrap { background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.08); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { background: #f9fafb; text-align: left; padding: 0.6rem 0.75rem; font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: #6b7280; border-bottom: 1px solid #e5e7eb; }
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }
.actions { display: flex; gap: 0.4rem; }

/* Card */
.card { background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.08); padding: 1.25rem; margin-bottom: 1rem; }
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: #374151; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.5rem; }

/* Form */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 0.8rem; font-weight: 600; color: #374151; }
input[type=text], input[type=number], input[type=email], input[type=password], select, textarea {
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
  font-size: 0.875rem;
  width: 100%;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
textarea { resize: vertical; min-height: 80px; }

/* Line items builder */
.line-items { border: 1px solid #e5e7eb; border-radius: 6px; overflow: hidden; margin-top: 0.5rem; }
.line-items table { margin: 0; }
.line-items th { font-size: 0.75rem; }
.line-item-row td { padding: 0.4rem 0.5rem; }
.line-item-row input, .line-item-row select { padding: 0.3rem 0.4rem; }
.add-row-btn { padding: 0.5rem 0.75rem; background: #f9fafb; border: none; border-top: 1px solid #e5e7eb; width: 100%; text-align: left; cursor: pointer; font-size: 0.8rem; color: #2563eb; }
.add-row-btn:hover { background: #eff6ff; }

/* Totals summary */
.totals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-top: 1rem; }
.total-box { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 0.75rem 1rem; }
.total-box .label { font-size: 0.75rem; color: #6b7280; font-weight: 600; text-transform: uppercase; }
.total-box .value { font-size: 1.25rem; font-weight: 700; color: #111; margin-top: 0.2rem; }
.total-box.highlight { background: #eff6ff; border-color: #bfdbfe; }
.total-box.highlight .value { color: #1d4ed8; }

/* Auth */
.auth-wrap { max-width: 380px; margin: 4rem auto; }
.auth-wrap h1 { text-align: center; margin-bottom: 1.5rem; }
.error-msg { background: #fee2e2; color: #b91c1c; border-radius: 4px; padding: 0.5rem 0.75rem; margin-bottom: 1rem; font-size: 0.875rem; }
.success-msg { background: #dcfce7; color: #15803d; border-radius: 4px; padding: 0.5rem 0.75rem; margin-bottom: 1rem; font-size: 0.875rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

/* Sections */
.section-card { background: #fff; border-radius: 6px; box-shadow: 0 2px 6px rgba(0,0,0,.1); margin-bottom: .75rem; overflow: hidden; border: 1px solid #e2e8f0; }
.section-header { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; background: linear-gradient(135deg, #1a1a2e 0%, #2d3561 100%); border-bottom: 2px solid #2563eb; gap: 1rem; }
.section-title { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.section-name { font-weight: 700; font-size: .95rem; color: #fff; }
.section-meta { font-size: .8rem; color: #93c5fd; white-space: nowrap; background: rgba(255,255,255,.1); padding: 2px 8px; border-radius: 12px; }
.section-desc { padding: .5rem 1rem; color: #4b5563; font-size: .875rem; border-bottom: 1px solid #e5e7eb; background: #f8fafc; font-style: italic; }
.section-items { padding: .75rem 1rem; display: flex; flex-direction: column; gap: .75rem; background: #fff; }
.items-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.items-table th { text-align: left; padding: .4rem .5rem; font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: #fff; background: #374151; border-bottom: 2px solid #2563eb; }
.items-table td { padding: .4rem .5rem; border-bottom: 1px solid #e5e7eb; }
.items-table tbody tr:nth-child(even) td { background: #f8fafc; }
.items-table tbody tr:hover td { background: #eff6ff; }
.items-table tr:last-child td { border-bottom: none; }
.section-children { background: #f1f5f9; padding: .5rem .75rem; border-top: 1px solid #e2e8f0; }
.section-children .section-card { box-shadow: 0 1px 3px rgba(0,0,0,.08); border-color: #cbd5e1; }
.section-children .section-header { background: linear-gradient(135deg, #1e3a5f 0%, #2d5282 100%); border-bottom-color: #3b82f6; }
.section-children .section-children .section-header { background: linear-gradient(135deg, #1e4d3a 0%, #276749 100%); border-bottom-color: #10b981; }
.meta-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; }
.drag-handle { cursor: grab; color: rgba(255,255,255,.5); padding: 0 4px; font-size: 1rem; user-select: none; }
.drag-handle:hover { color: #fff; }
.sortable-ghost { opacity: .4; background: #eff6ff; }

/* Section action buttons override for dark header */
.section-header .btn-secondary { background: rgba(255,255,255,.15); color: #e2e8f0; border: 1px solid rgba(255,255,255,.2); }
.section-header .btn-secondary:hover { background: rgba(255,255,255,.25); color: #fff; }
.section-header .btn-danger { background: rgba(220,38,38,.7); }
.section-header .btn-danger:hover { background: #dc2626; }

/* Dashboard */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.dash-card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); padding: 1.5rem; text-decoration: none; color: inherit; border-left: 4px solid #2563eb; }
.dash-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.dash-card h3 { font-size: 0.9rem; color: #6b7280; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.dash-card .count { font-size: 2rem; font-weight: 700; color: #111; margin-top: 0.25rem; }

/* Part search widget */
.part-search { position: relative; width: 100%; }
.part-search-input { width: 100%; padding: .375rem .5rem; border: 1px solid #d1d5db; border-radius: 4px; font-size: .875rem; background: #fff; }
.part-search-input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.part-search-results { display: none; position: fixed; background: #fff; border: 1px solid #d1d5db; border-radius: 4px; max-height: 220px; overflow-y: auto; z-index: 9999; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.part-search-option { padding: .4rem .6rem; font-size: .875rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.part-search-option:hover { background: #eff6ff; color: #1d4ed8; }
.part-search-mfr { margin-left: .5rem; font-size: .75rem; color: #6b7280; background: #f3f4f6; border-radius: 3px; padding: 1px 5px; }
.part-search-option:hover .part-search-mfr { background: #dbeafe; color: #1d4ed8; }

/* Section totals footer */
.section-footer { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; padding: .5rem 1rem; border-top: 2px solid #e2e8f0; background: #f1f5f9; font-size: .8rem; color: #1e3a5f; font-weight: 600; }
.section-footer-label { font-weight: 700; text-transform: uppercase; font-size: .7rem; letter-spacing: .05em; color: #2563eb; margin-right: .25rem; }

/* Assembly expand toggle */
.assembly-expand-btn { background: none; border: none; cursor: pointer; font-size: .65rem; color: #6b7280; padding: 0 3px; vertical-align: middle; line-height: 1; }
.assembly-expand-btn:hover { color: #2563eb; }
