:root {
  --bg: #eef2f6;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #1e3a5f;
  --orange: #ea580c;
  --ok: #059669;
  --err: #dc2626;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, #e8eef5 0%, #f8fafc 120px);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

header,
.page-header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2d4a73 55%, #1a3352 100%);
  color: #fff;
  padding: 20px 18px 18px;
  border-bottom: 4px solid var(--orange);
  box-shadow: 0 4px 20px rgba(30, 58, 95, 0.25);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.page-header-text { min-width: 0; }

.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.header-user {
  font-size: 0.82rem;
  opacity: 0.9;
}

.header-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font: inherit;
  border-radius: 8px;
  padding: 6px 10px;
}

.login-page .login-main {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

.login-step-label {
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-names {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.login-name-btn {
  padding: 14px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

.login-name-btn:active {
  transform: scale(0.98);
  background: #eef2f7;
}

.login-pin-step label {
  display: block;
  margin-top: 12px;
}

.login-pin-step input {
  width: 100%;
  margin-top: 6px;
  font-size: 1.4rem;
  letter-spacing: 0.2em;
  text-align: center;
}

.login-selected {
  margin: 0 0 4px;
}

.login-pin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

header h1,
.page-header h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

header p,
.page-header p { margin: 0; opacity: 0.88; font-size: 0.88rem; }

.header-link {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.header-link:hover {
  background: rgba(255, 255, 255, 0.24);
}

main {
  padding: 16px 14px 32px;
  max-width: 520px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 16px 14px;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  border-left: 4px solid var(--accent);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 0.92rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

label {
  display: block;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  margin: 8px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  font-size: 1rem;
  background: #f8fafc;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
  background: #fff;
}

textarea { resize: vertical; min-height: 80px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.worker-hint { margin: 0 0 10px; }

.worker-row {
  display: grid;
  grid-template-columns: 1fr 74px 74px 52px 36px;
  gap: 6px;
  margin-bottom: 8px;
  align-items: end;
}

.worker-row select {
  padding: 10px 6px;
  font-size: 0.88rem;
}

.worker-row .w-hours {
  text-align: center;
  font-weight: 700;
  background: #eef2f7;
  color: var(--accent);
  padding: 10px 4px;
}

.worker-row .w-hours.invalid-hours {
  color: var(--err);
  background: #fef2f2;
}

@media (max-width: 480px) {
  .worker-row {
    grid-template-columns: 1fr 1fr 48px 32px;
  }
  .worker-row .w-col-name {
    grid-column: 1 / -1;
  }
}

.arbeit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.arbeit-actions .btn-polish,
.arbeit-actions .btn-voice {
  margin-top: 0;
}

.btn-voice.listening {
  background: #fef2f2;
  color: var(--err);
  border-color: #fecaca;
  animation: voice-pulse 1.2s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.polish-diff {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
}

.polish-diff-title {
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 0.92rem;
}

.polish-diff-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.polish-diff-label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.polish-diff-text {
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: auto;
}

.polish-diff-col:last-child .polish-diff-text {
  border-color: #86efac;
  background: #f0fdf4;
}

.polish-diff-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

@media (max-width: 520px) {
  .polish-diff-grid {
    grid-template-columns: 1fr;
  }
}

.polish-hint { margin: 8px 0 0; }

.material-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.material-cat {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfc;
  overflow: hidden;
}

.material-cat > summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 0.92rem;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.material-cat > summary::-webkit-details-marker { display: none; }

.material-cat > summary::after {
  content: "▾";
  color: var(--muted);
  font-size: 0.85rem;
}

.material-cat[open] > summary::after { content: "▴"; }

.material-cat-count {
  font-weight: 500;
  font-size: 0.78rem;
  color: var(--muted);
}

.material-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 10px;
}

.material-row {
  display: grid;
  grid-template-columns: 1fr 52px 56px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
}

.material-row.active {
  border-color: #93c5fd;
  background: #f0f9ff;
}

.material-row .mat-name {
  font-size: 0.84rem;
  line-height: 1.3;
}

.material-row .mat-unit {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

.material-row .mat-qty {
  width: 100%;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  text-align: center;
}

@media (max-width: 420px) {
  .material-row {
    grid-template-columns: 1fr 56px;
    grid-template-rows: auto auto;
  }
  .material-row .mat-unit {
    grid-column: 1;
    text-align: left;
    margin-top: -4px;
  }
  .material-row .mat-qty {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
}

.photo-hint { margin: 0 0 10px; }

.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.photo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-top: 0 !important;
  cursor: pointer;
  font-size: 0.9rem !important;
  padding: 12px 10px !important;
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.photo-thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 1;
  background: #e2e8f0;
  border: 1px solid var(--border);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.92);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.hours-summary {
  margin-top: 10px;
  min-height: 160px;
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.5;
  background: #f1f5f9;
  color: var(--text);
}

.worker-row button {
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--err);
  font-size: 1.1rem;
  cursor: pointer;
}

.btn-primary, .btn-secondary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 15px 16px;
  font: inherit;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
}

.form-actions {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.form-actions .btn-primary {
  margin-top: 0;
}

.draft-hint {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 0.86rem;
}

.login-card input[type="password"] {
  width: 100%;
  margin-bottom: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--orange) 0%, #f97316 100%);
  color: #fff;
  margin-top: 6px;
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.35);
}

.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn-secondary {
  background: #eef2f7;
  color: var(--accent);
  margin-top: 6px;
}

.hint { font-size: 0.82rem; color: var(--muted); margin: 8px 0 0; }



.meta-box {
  margin-top: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
  border-radius: 10px;
  font-size: 0.84rem;
  line-height: 1.45;
  border: 1px solid #dbeafe;
}

.meta-box .tag {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  margin-right: 6px;
}

.status {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.status.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.status.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.signature-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.signature-pad {
  width: 100%;
  max-width: 100%;
  height: 180px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

.header-link {
  color: #fff;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}

#customer {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 1rem;
  background: #fff;
}