:root {
  color-scheme: light;
  --ink: #142832;
  --muted: #60727a;
  --line: #c7d7dc;
  --canvas: #eef5f6;
  --surface: #ffffff;
  --surface-soft: #f5fafb;
  --accent: #087f9f;
  --accent-strong: #05677f;
  --accent-soft: #e2f4f8;
  --success: #18775f;
  --success-soft: #e8f7f1;
  --danger: #b33646;
  --danger-soft: #fff0f2;
  --warning: #9a6518;
  --warning-soft: #fff7e6;
  --shadow: 0 18px 44px rgba(17, 51, 61, .1);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 100% 0, rgba(8, 127, 159, .14), transparent 35%),
    linear-gradient(180deg, #f8fbfc 0, var(--canvas) 100%);
}
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.hidden { display: none !important; }

.mobile-shell {
  width: min(100%, 620px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.mobile-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand img { width: 96px; height: 46px; object-fit: contain; }
.brand span { display: grid; line-height: 1.15; }
.brand strong { font-size: 16px; letter-spacing: .02em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .05em; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.network-state,
.permission-state {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--success);
  background: var(--success-soft);
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}
.network-state::before { content: ""; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: currentColor; }
.network-state.offline { color: var(--danger); background: var(--danger-soft); }
.text-button {
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--accent-strong);
  background: rgba(255,255,255,.8);
  font-size: 12px;
  font-weight: 800;
}

main { padding: 8px 0 28px; }
.screen { display: grid; gap: 16px; }
.login-screen { min-height: calc(100dvh - 150px); align-items: center; }
.card {
  border: 1px solid rgba(160, 187, 196, .72);
  border-radius: 20px;
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow);
}
.login-card { padding: 24px 20px; }
.work-order-card,
.photo-card,
.success-card { padding: 20px 18px; }
.screen-heading { display: flex; align-items: flex-start; gap: 13px; margin-bottom: 22px; }
.screen-heading.compact { margin-bottom: 17px; }
.screen-heading h1,
.screen-heading h2 { margin: 0; font-size: 23px; line-height: 1.25; }
.screen-heading h2 { font-size: 19px; }
.screen-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.step-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #0d98ba, var(--accent-strong));
  box-shadow: 0 8px 18px rgba(8, 127, 159, .24);
  font-size: 12px;
  font-weight: 900;
}

.form-stack,
.work-order-form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; }
label > span { color: #3f565f; font-size: 12px; font-weight: 850; }
input, textarea {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid #aec3ca;
  border-radius: 12px;
  outline: none;
  color: var(--ink);
  background: white;
  font-size: 16px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
textarea { min-height: 86px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(8, 127, 159, .12); }
input::placeholder, textarea::placeholder { color: #91a2a9; }

.primary-button,
.secondary-button,
.ghost-button,
.camera-button {
  min-height: 52px;
  border-radius: 13px;
  font-weight: 900;
  cursor: pointer;
}
.primary-button { border: 0; color: white; background: linear-gradient(135deg, #0d96b7, var(--accent-strong)); box-shadow: 0 9px 20px rgba(8, 127, 159, .23); }
.primary-button:disabled { cursor: not-allowed; box-shadow: none; opacity: .45; }
.secondary-button { padding: 10px 14px; border: 1px solid #81b6c3; color: var(--accent-strong); background: var(--accent-soft); }
.ghost-button { padding: 10px 14px; border: 1px solid var(--line); color: var(--muted); background: white; }

.form-message { padding: 11px 12px; border-radius: 11px; color: var(--success); background: var(--success-soft); font-size: 13px; font-weight: 800; line-height: 1.45; }
.form-message.error { color: var(--danger); background: var(--danger-soft); }
.account-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.84);
}
.account-strip > div { display: grid; gap: 2px; }
.account-strip span { color: var(--muted); font-size: 10px; font-weight: 800; }
.account-strip strong { font-size: 14px; }
.permission-state { color: var(--accent-strong) !important; background: var(--accent-soft); }
.permission-state.readonly { color: var(--warning) !important; background: var(--warning-soft); }
.context-notice { padding: 11px 13px; border: 1px solid #e6c889; border-radius: 12px; color: var(--warning); background: var(--warning-soft); font-size: 12px; font-weight: 800; line-height: 1.5; }

.work-order-form { grid-template-columns: minmax(0, 1fr) 112px; align-items: end; }
.work-order-result {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.work-order-result > div { min-width: 0; padding: 12px; border-radius: 12px; background: var(--surface-soft); }
.work-order-result > div:last-child { grid-column: 1 / -1; }
.work-order-result span,
.work-order-result small { display: block; color: var(--muted); font-size: 10px; font-weight: 800; }
.work-order-result strong { display: block; margin-top: 5px; overflow-wrap: anywhere; font-size: 15px; }
.work-order-result small { margin-top: 4px; }

.photo-card { transition: opacity .2s ease; }
.photo-card.is-disabled { opacity: .64; }
.camera-input { position: fixed; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.camera-button {
  width: 100%;
  min-height: 132px;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 18px;
  border: 2px dashed #74afbd;
  color: var(--accent-strong);
  background: linear-gradient(145deg, #f8fcfd, var(--accent-soft));
}
.camera-button:disabled { cursor: not-allowed; filter: grayscale(.5); }
.camera-symbol { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--accent); font-size: 25px; line-height: 1; }
.camera-button strong { font-size: 16px; }
.camera-button small { color: var(--muted); font-size: 11px; }
.ghost-button.compact { min-height: 40px; padding: 7px 11px; font-size: 12px; }
.photo-queue-panel { display: grid; gap: 12px; margin-top: 14px; }
.photo-queue-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.photo-queue-heading > div { display: grid; gap: 2px; }
.photo-queue-heading strong { font-size: 14px; }
.photo-queue-heading span { color: var(--muted); font-size: 11px; font-weight: 800; }
.photo-queue { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.photo-queue-item { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.photo-queue-preview { position: relative; width: 100%; display: block; padding: 0; border: 0; background: #0d171b; aspect-ratio: 4 / 3; cursor: zoom-in; }
.photo-queue-preview img { width: 100%; height: 100%; display: block; object-fit: cover; }
.photo-queue-preview span { position: absolute; top: 8px; left: 8px; min-width: 26px; padding: 4px 7px; border-radius: 999px; color: #fff; background: rgba(8, 24, 31, .8); font-size: 11px; font-weight: 900; }
.photo-queue-delete { width: 100%; min-height: 42px; border: 0; border-top: 1px solid var(--line); color: var(--danger); background: #fff; font-weight: 900; cursor: pointer; }
.photo-queue-delete:disabled { opacity: .45; cursor: not-allowed; }
.photo-lightbox { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: calc(54px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); background: rgba(3, 12, 16, .94); }
.photo-lightbox img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; }
.photo-lightbox-close { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px; width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.35); border-radius: 50%; color: #fff; background: rgba(255,255,255,.12); font-size: 25px; cursor: pointer; }
.note-field { margin-top: 15px; }
.upload-button { width: 100%; margin-top: 14px; }
.upload-progress { display: flex; align-items: center; gap: 10px; margin-top: 13px; padding: 12px; border-radius: 11px; color: var(--accent-strong); background: var(--accent-soft); font-size: 12px; }
.upload-progress span { width: 18px; height: 18px; border: 3px solid rgba(8,127,159,.22); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.upload-progress + .form-message,
#uploadMessage { margin-top: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.success-card { display: grid; grid-template-columns: auto minmax(0,1fr); align-items: center; gap: 13px; border-color: #9bcebd; background: var(--success-soft); }
.success-card .success-check { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--success); font-size: 26px; font-weight: 900; }
.success-card h2 { margin: 0; color: var(--success); font-size: 19px; }
.success-card p { margin: 5px 0 0; color: #3b675a; font-size: 13px; }
.success-card small { display: block; margin-top: 4px; color: var(--muted); }
.success-card button { grid-column: 1 / -1; width: 100%; }

footer { display: flex; justify-content: space-between; gap: 12px; padding: 6px 4px 22px; color: var(--muted); font-size: 11px; }
footer a { color: var(--accent-strong); font-weight: 800; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(calc(100% - 32px), 520px); padding: 13px 15px; border-radius: 12px; color: white; background: #1e3138; box-shadow: 0 12px 28px rgba(0,0,0,.24); font-size: 13px; font-weight: 800; text-align: center; }
.toast.error { background: var(--danger); }

@media (max-width: 430px) {
  .mobile-shell { padding-inline: 11px; }
  .mobile-header { min-height: 70px; }
  .brand img { width: 88px; height: 40px; }
  .brand strong { font-size: 14px; }
  .brand small { display: none; }
  .login-card, .work-order-card, .photo-card, .success-card { padding: 18px 15px; border-radius: 17px; }
  .work-order-form { grid-template-columns: 1fr; }
  .work-order-form .primary-button { min-height: 48px; }
  .network-state { padding-inline: 7px; }
  .photo-queue { gap: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
