:root {
  --primary: #006783;
  --primary-dark: #004f65;
  --text: #16202b;
  --muted: #667085;
  --line: #e6edf2;
  --bg: #f8fafc;
  --card: #ffffff;
  --soft: #f3f8fa;
  --shadow: 0 18px 50px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html { min-height: 100%; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  min-height: 100%;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(0, 103, 131, .07), transparent 34%),
    var(--bg);
  overscroll-behavior-y: contain;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:active { transform: translateY(1px); }
.hidden { display: none !important; }

.app-shell {
  width: min(720px, calc(100% - 36px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.home-page {
  min-height: calc(100dvh - 80px);
  display: grid;
  place-items: center;
}

.home-card {
  width: min(440px, 100%);
  padding: 34px 26px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow);
  text-align: center;
}

.page-brand {
  color: var(--primary);
  font-size: 13px;
  line-height: 1;
  letter-spacing: .18em;
  text-transform: uppercase;
  font-weight: 700;
}

.home-page h1 {
  margin: 0 0 28px;
  font-size: clamp(28px, 6vw, 40px);
  line-height: 1.12;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.035em;
}

.home-actions { display: grid; gap: 12px; }

.home-btn,
.save-btn,
.outline-btn,
.back-btn,
.file-btn {
  border-radius: 14px;
  border: 1px solid var(--primary);
  min-height: 52px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  line-height: 1.2;
  user-select: none;
  touch-action: manipulation;
}
.home-btn:hover, .save-btn:hover, .file-btn:hover { background: var(--primary-dark); }
.home-btn.secondary, .outline-btn, .back-btn { background: #fff; color: var(--primary); }
.outline-btn.muted { border-color: var(--line); color: var(--muted); }

.input-page { padding-top: 6px; }
.page-head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 16px;
  margin-bottom: 8px;
  background: linear-gradient(to bottom, var(--bg) 72%, rgba(248,250,252,0));
}
.back-btn { min-height: 42px; border-radius: 999px; font-size: 14px; font-weight: 700; padding: 0 15px; }
.page-brand { font-size: 11px; text-align: right; letter-spacing: .12em; }
.input-page h2 { margin: 4px 0 14px; font-size: 24px; line-height: 1.15; color: var(--text); }

.scan-panel, .form-card {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .04);
}
.scan-options, .camera-actions, .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.file-btn input { display: none; }
.camera-box { margin-top: 14px; }
.camera-box video { width: 100%; max-height: 380px; object-fit: cover; border-radius: 14px; background: #000; display: block; margin-bottom: 12px; }
.ktp-preview { width: 100%; border: 1px solid var(--line); border-radius: 14px; margin-top: 14px; display: block; }
.ocr-status { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.ocr-status b { color: var(--primary); }
.ocr-text { margin-top: 8px; min-height: 92px; resize: vertical; }

.form-card { display: grid; gap: 13px; }
label { display: grid; gap: 7px; text-align: left; }
label span, .package-box > span { font-size: 13px; color: var(--muted); font-weight: 700; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 13px 14px;
  min-height: 48px;
  background: #fff;
  color: var(--text);
  outline: none;
  font-size: 16px;
}
textarea { resize: vertical; }
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,103,131,.11); }

.package-box {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 10px;
  background: var(--soft);
}
.package-box label { min-height: 38px; display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--text); }
.package-box input { width: auto; min-height: auto; padding: 0; accent-color: var(--primary); }
.save-btn { width: 100%; margin-top: 4px; border-radius: 14px; font-size: 16px; }
.save-btn:disabled { opacity: .65; cursor: wait; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(18px);
  background: #111827;
  color: #fff;
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
  max-width: min(560px, calc(100% - 24px));
  text-align: center;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  body { background: #fff; }
  .app-shell { width: 100%; padding: 0 14px 110px; }
  .home-page { min-height: 100dvh; padding: 18px 0; }
  .home-card { border: 0; box-shadow: none; padding: 18px 8px; }
  .home-page h1 { margin: 0 0 24px; font-size: clamp(30px, 9vw, 38px); }
  .home-actions { gap: 10px; }
  .home-btn { min-height: 54px; border-radius: 16px; }
  .input-page { padding-top: 0; }
  .page-head { margin-left: -14px; margin-right: -14px; padding: max(10px, env(safe-area-inset-top)) 14px 14px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); }
  .page-brand { font-size: 10px; max-width: 170px; line-height: 1.25; }
  .input-page h2 { margin-top: 16px; font-size: 22px; }
  .scan-panel, .form-card { border-radius: 18px; padding: 14px; box-shadow: none; }
  .scan-options, .camera-actions, .two-col { grid-template-columns: 1fr; gap: 10px; }
  input, textarea { font-size: 16px; min-height: 50px; }
  .save-btn { position: fixed; left: 14px; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); width: calc(100% - 28px); z-index: 30; box-shadow: 0 12px 28px rgba(0,103,131,.24); }
  .toast { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 70px); border-radius: 16px; }
}
