:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c2027;
  --muted: #6b7280;
  --border: #e4e6ea;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --received: #64748b;
  --under_repair: #d97706;
  --sent_to_vendor: #7c3aed;
  --with_vendor: #9333ea;
  --received_back: #0891b2;
  --completed: #16a34a;
  --delivered: #2563eb;
  --cancelled: #dc2626;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }

input, select, button { font: inherit; }
input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  background: #fff;
  color: var(--ink);
}
label { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: block; }

.btn-primary, .btn-secondary, .btn-link, .btn-danger {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-secondary { background: #eef0f3; color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-link { background: none; color: var(--primary); padding: 4px; }

.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.muted { color: var(--muted); font-size: 14px; }

/* Auth screens */
.view#view-login, .view#view-setup { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card {
  background: var(--card);
  padding: 32px;
  border-radius: 16px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
  text-align: center;
}
.auth-card label { text-align: left; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-logo { display: block; width: 100%; max-width: 220px; height: auto; margin: 0 auto 16px; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
  gap: 10px;
}
.brand { font-weight: 700; font-size: 18px; }
nav { display: flex; gap: 8px; }
.tab {
  background: none; border: none; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-weight: 600;
}
.tab.active { background: #eef2ff; color: var(--primary); }
.user-badge { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }

.tab-panel { padding: 16px 20px 60px; max-width: 900px; margin: 0 auto; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
#search-box { max-width: 280px; margin-bottom: 0; }
.status-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--muted);
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
#new-job-btn { margin-left: auto; }

/* Job list */
.jobs-list { display: flex; flex-direction: column; gap: 10px; }
.job-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.job-card:hover { border-color: var(--primary); }
.job-main { display: flex; flex-direction: column; gap: 2px; }
.job-title { font-weight: 700; }
.job-sub { font-size: 13px; color: var(--muted); }
.status-badge {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; color: #fff;
  text-transform: uppercase; white-space: nowrap;
}
.type-tag {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px;
  background: #eef2ff; color: #4338ca; margin-left: 6px; vertical-align: middle;
}
.type-tag.rma { background: #fdf2f8; color: #be185d; }

/* Cards used in settings */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 20px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form input, .inline-form select { margin-bottom: 0; }
.service-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.service-row input { flex: 1; }
.service-row .svc-price { flex: 0 0 90px; }
.service-row .svc-category { flex: 0 0 110px; }
.service-row:last-child { border-bottom: none; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto; z-index: 100;
}
.modal {
  background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 560px; position: relative;
}
.modal-close { position: absolute; top: 12px; right: 16px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

.line-item-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.line-item-row span { flex: 1; }

.status-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.status-actions button { flex: 1; min-width: 100px; }

.photo-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.photo-thumb { position: relative; width: 110px; }
.photo-thumb img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.photo-meta { font-size: 10px; color: var(--muted); margin-top: 2px; }
.photo-delete {
  position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.6); color: #fff;
  border: none; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; font-size: 12px; line-height: 1;
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
}
