/* Business Card Scanner — responsive corporate PWA theme */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --steel: #0b4a94;
  --steel-dark: #07264d;
  --steel-light: #e8f1fb;
  --lei-red: #d9232e;
  --excel-green: #1e6f43;
  --excel-green-dark: #165533;
  --ink: #112236;
  --muted: #56687a;
  --line: #d4e0ec;
  --bg: #f1f5f9;
  --card: #ffffff;
  --danger: #b3261e;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(7, 38, 77, 0.06), 0 1px 2px rgba(7, 38, 77, 0.04);
  --shadow-md: 0 10px 28px rgba(7, 38, 77, 0.16);
}

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(135deg, var(--steel-dark) 0%, #0b4182 65%, #0066cc 100%);
  color: #fff;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 14px calc(16px + env(safe-area-inset-left));
  border-bottom: 3px solid var(--lei-red);
  box-shadow: 0 3px 12px rgba(7, 38, 77, 0.22);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.brand-logo {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: #ffffff;
  padding: 2px;
  object-fit: contain;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}
.brand-text { min-width: 0; }
.app-header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.2;
}
.tagline {
  margin: 2px 0 0;
  font-size: 12px;
  color: #cde0ee;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Layout ---------- */
.content {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px calc(16px + env(safe-area-inset-right)) 20px calc(16px + env(safe-area-inset-left));
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: linear-gradient(135deg, var(--steel-dark) 0%, var(--steel) 60%, #0066cc 100%);
  border-radius: var(--radius);
  padding: 15px 10px;
  margin-bottom: 14px;
  box-shadow: 0 4px 16px rgba(11, 74, 148, 0.24);
}
.stat { text-align: center; color: #fff; padding: 2px 4px; }
.stat + .stat { border-left: 1px solid rgba(255, 255, 255, 0.22); }
.stat-num {
  display: block;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #cfe1ef;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.toolbar-secondary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.985); }
.btn-big {
  width: 100%;
  min-height: 50px;
  padding: 13px 18px;
  font-size: 16px;
  box-shadow: 0 3px 10px rgba(37, 80, 110, 0.24);
}
.btn-primary { background: var(--steel); color: #fff; }
.btn-primary:hover { background: var(--steel-dark); }
.btn-secondary { background: #fff; color: var(--steel); border-color: var(--line); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--steel-light); }
.btn-light {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.36);
  min-height: 38px;
  padding: 7px 12px;
  font-size: 13px;
}
.btn-light:hover { background: rgba(255, 255, 255, 0.26); }
.btn-install.is-ready {
  background: #ffffff;
  color: var(--steel-dark);
  border-color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.btn-install[hidden] { display: none; }
.btn-excel { background: var(--excel-green); color: #fff; box-shadow: var(--shadow-sm); }
.btn-excel:hover { background: var(--excel-green-dark); }
.btn-danger-outline { background: #fff; color: var(--danger); border-color: #e6b8b4; box-shadow: var(--shadow-sm); }
.btn-danger-outline:hover { background: #fdecea; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ---------- OCR progress ---------- */
.ocr-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.ocr-status { margin: 0 0 8px; font-weight: 600; font-size: 14px; color: var(--steel); }
.progress { height: 8px; background: var(--steel-light); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--steel); border-radius: 99px; transition: width 0.2s ease; }

/* ---------- Search ---------- */
.search-row {
  position: relative;
  margin-bottom: 16px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-row input {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px 11px 42px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  font-family: inherit;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.search-row input:focus { outline: 2px solid var(--steel); outline-offset: 0; border-color: var(--steel); }

/* ---------- Card list ---------- */
.card-list { display: grid; gap: 12px; }
.card-item {
  display: flex;
  gap: 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.card-item:hover { border-color: #bfd0de; box-shadow: 0 3px 10px rgba(16, 36, 52, 0.08); }
.card-thumb {
  width: 78px;
  height: 78px;
  flex: 0 0 78px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--steel-light);
  cursor: pointer;
}
.card-thumb-placeholder {
  width: 78px;
  height: 78px;
  flex: 0 0 78px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--steel-light);
  color: var(--steel);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-body { flex: 1; min-width: 0; }
.card-name { margin: 0 0 2px; font-size: 17px; font-weight: 700; color: var(--ink); line-height: 1.25; }
.card-company { margin: 0 0 7px; font-weight: 600; color: var(--steel); font-size: 14px; line-height: 1.3; }
.card-lines { margin: 0; font-size: 13.5px; color: var(--muted); display: grid; gap: 3px; }
.card-lines div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-link { color: var(--steel); text-decoration: none; font-weight: 500; }
.card-link:hover { text-decoration: underline; }
.card-meta { margin-top: 8px; font-size: 12px; color: #8494a2; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.mini-btn {
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--steel);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.mini-btn:hover { background: var(--steel-light); }
.mini-btn.danger { color: var(--danger); border-color: #e6b8b4; }
.mini-btn.danger:hover { background: #fdecea; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  color: var(--muted);
  background: #fff;
  border: 1px dashed #bed0e2;
  border-radius: var(--radius);
  padding: 32px 20px;
  box-shadow: var(--shadow-sm);
}
.empty-logo {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  margin-bottom: 10px;
  box-shadow: 0 4px 12px rgba(7, 38, 77, 0.14);
}
.empty-title { margin: 0 0 6px; font-size: 18px; font-weight: 700; color: var(--steel-dark); }
.empty-state p { margin: 0 auto; max-width: 500px; font-size: 14px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 26, 38, 0.58);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-sheet {
  background: #fff;
  width: 100%;
  max-width: 600px;
  max-height: 92dvh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-md);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal-head h2 { margin: 0; font-size: 19px; color: var(--steel-dark); }
.modal-close {
  border: none;
  background: var(--steel-light);
  color: var(--steel);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.modal-note { margin: 8px 0 14px; color: var(--muted); font-size: 14px; }
.photo-preview { margin-bottom: 14px; text-align: center; }
.photo-preview img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.photo-actions { margin-top: 8px; display: flex; justify-content: center; gap: 8px; }
.raw-ocr {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  padding: 9px 12px;
  font-size: 12px;
}
.raw-ocr summary { cursor: pointer; font-weight: 600; color: var(--steel); }
.raw-ocr pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--ink);
  max-height: 140px;
  overflow-y: auto;
}

/* ---------- Cropper modal ---------- */
.crop-sheet { max-width: 620px; }
.crop-stage {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 12px;
  background: #131c24;
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#cropCanvas { display: block; max-width: 100%; max-height: 50dvh; }
.crop-box {
  position: absolute;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 9999px rgba(10, 20, 30, 0.58);
  cursor: move;
  touch-action: none;
}
.crop-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.25) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.25) 1px, transparent 1px);
  background-size: 33.33% 33.33%;
  pointer-events: none;
}
.crop-handle {
  position: absolute;
  width: 30px;
  height: 30px;
  touch-action: none;
}
.crop-handle::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border: 2.5px solid var(--steel);
  border-radius: 50%;
  top: 6px;
  left: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.crop-handle.nw { top: -15px; left: -15px; cursor: nwse-resize; }
.crop-handle.ne { top: -15px; right: -15px; cursor: nesw-resize; }
.crop-handle.sw { bottom: -15px; left: -15px; cursor: nesw-resize; }
.crop-handle.se { bottom: -15px; right: -15px; cursor: nwse-resize; }
.crop-toolbar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- Form ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
#cardForm label {
  display: block;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--steel);
}
#cardForm input {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 5px;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-family: inherit;
  font-weight: 400;
  color: var(--ink);
  background: #fff;
}
#cardForm input:focus { outline: 2px solid var(--steel); border-color: var(--steel); }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}
.modal-actions .btn { flex: 1 1 0; }

/* ---------- Install guide ---------- */
.install-head-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.install-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}
.install-warn {
  background: #fff4e5;
  border: 1px solid #f1c78c;
  color: #6b4106;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  margin-bottom: 12px;
}
.install-box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.install-box h3 { margin: 0 0 6px; font-size: 15px; color: var(--steel-dark); }
.install-sub { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.steps { margin: 0; padding-left: 20px; font-size: 14px; color: var(--ink); }
.steps li { margin-bottom: 7px; }
.ios-share-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  padding: 3px 6px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--steel);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #172836;
  color: #fff;
  padding: 9px 15px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: var(--shadow-md);
  z-index: 80;
  max-width: min(360px, calc(100vw - 32px));
  text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- Footer ---------- */
.app-footer {
  margin-top: 28px;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.app-footer p { margin: 2px 0; }
.app-footer p:first-child { font-weight: 700; color: var(--steel); }

/* ---------- Tablet & Desktop ---------- */
@media (min-width: 640px) {
  .app-header h1 { font-size: 22px; }
  .tagline { font-size: 13px; }
  .toolbar {
    flex-direction: row;
    align-items: center;
  }
  .btn-big { width: auto; flex: 0 0 auto; padding: 11px 20px; min-height: 44px; }
  .toolbar-secondary {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
    gap: 8px;
  }
  .modal { align-items: center; padding: 20px; }
  .modal-sheet { border-radius: 18px; padding: 22px 24px; }
  .modal-actions .btn { flex: 0 0 auto; min-width: 110px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-full { grid-column: 1 / -1; }
  .card-list { grid-template-columns: 1fr 1fr; }
}
