:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde2e8;
  --text: #1c2733;
  --muted: #66788a;
  --primary: #1b5e9b;
  --primary-dark: #154a7a;
  --danger: #c62828;
  --done: #2e7d32;
  --working: #f9a825;
  --pending: #9e9e9e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(20, 30, 45, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }

.view { min-height: 100vh; }

#auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.brand { margin: 0 0 4px; color: var(--primary); font-size: 28px; }
.subtitle { margin: 0 0 20px; color: var(--muted); }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  background: none;
  border: none;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}

/* Text-like inputs stretch; checkboxes and radios must keep their own size. */
input:not([type="checkbox"]):not([type="radio"]), select {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

input:focus, select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}

.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.full { width: 100%; }

.error { color: var(--danger); font-size: 13px; }
.notice { color: var(--primary); font-size: 13px; }

/* ---------- App layout ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 { margin: 0; font-size: 20px; }
.header-user { font-size: 13px; color: var(--muted); }
.header-actions { display: flex; gap: 8px; }

.content { padding: 24px; max-width: 1100px; margin: 0 auto; }

/* ---------- Jobs ---------- */
.jobs-list { display: flex; flex-direction: column; gap: 14px; }

.job-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

/*
 * Rush orders keep the normal white card so the progress bar stays readable.
 * Priority is signalled by a thick left accent bar, a tinted border and a
 * RUSH badge - obvious at a glance without drowning the content.
 */
.job-card.rush {
  border-color: #e53935;
  border-left: 6px solid #e53935;
  box-shadow: 0 1px 3px rgba(229, 57, 53, 0.35);
}

.rush-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: #e53935;
  color: #fff;
}

.job-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.job-bar {
  display: flex;
  overflow-x: auto;
  padding-bottom: 8px;
  gap: 2px;
}

.bar-col {
  min-width: 104px;
  flex: 0 0 auto;
  text-align: center;
  padding: 6px 4px;
  border-right: 1px dashed var(--border);
}

.bar-col.bar-wo { min-width: 72px; }

.bar-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-wo .bar-val { font-size: 15px; font-weight: 700; }
.bar-val { margin: 2px 0; }

.bar-worker { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.chip.done { background: var(--done); }
.chip.working { background: var(--working); }
.chip.pending { background: var(--pending); }
.chip.skipped { background: var(--pending); }

.job-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.job-actions .spacer { flex: 1; }

.fab {
  position: fixed;
  right: 28px;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(27, 94, 155, 0.4);
}
.fab:hover { background: var(--primary-dark); }

/* ---------- Settings ---------- */
.panel { margin-top: 16px; }
.inline-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.inline-row input { flex: 1; min-width: 160px; }

.list { list-style: none; padding: 0; margin: 0; }

.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 8px;
}

.list li .pos {
  flex: 0 0 28px;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
}

.list li .name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list li .sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list li .actions {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.icon-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn.danger { color: var(--danger); }

.rush-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  padding: 10px 14px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}

.rush-toggle input {
  width: 18px;
  height: 18px;
  accent-color: #e53935;
}


/* ---------- Work order form ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }

.form-steps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }

.step-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.step-row label {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.step-row .locked { font-size: 11px; color: var(--primary); font-weight: 600; }

.step-row select {
  flex: 0 0 220px;
  width: 220px;
}

/* ---------- Dialog ---------- */
/* ---------- Job details ---------- */
.details-block { margin: 4px 0 18px; }

textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;      /* textarea defaults to monospace */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  resize: vertical;
}

textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

/* The administrator's line breaks are meaningful - a numbered list has to
   survive as a list, so the text is wrapped rather than collapsed. */
.job-details-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
  max-height: 55vh;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.5;
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 32, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.dialog {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow: auto;
}

.dialog h3 { margin: 0 0 8px; }
.dialog .dialog-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }

/* ---------- Study table ---------- */
.study-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
.study-table th, .study-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.study-table th { color: var(--muted); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Checkbox + label on one line (reminder settings). */
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 4px;
}

/* ---------- Danger zone (delete company) ---------- */
.danger-zone {
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.danger-zone .hint { margin-bottom: 12px; color: var(--danger); }

/* Inline text input inside the delete-company confirmation dialog. */
.delete-company-input {
  width: 100%;
  margin: 14px 0 6px;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.delete-company-input:focus {
  outline: 2px solid var(--danger);
  border-color: var(--danger);
}

.app-error {
  margin: 16px 24px 0;
  padding: 12px 16px;
  background: #fdecea;
  border: 1px solid #f5c6cb;
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 14px;
}

@media (max-width: 640px) {
  .app-header { flex-direction: column; gap: 10px; align-items: flex-start; }
  .content { padding: 16px; }
  .inline-row input { min-width: 100%; }
}

