/* PDF Editor — mobile-first styles */
:root {
  --bg: #0d1522;
  --panel: #131c2c;
  --card: #18233a;
  --line: #26344d;
  --txt: #e8eef8;
  --dim: #8fa0b8;
  --acc: #2f6df6;
  --acc-di: #1d4ed8;
  --ok: #22c55e;
  --err: #ef4444;
  --warn: #f59e0b;
  --r: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.err { color: var(--err); min-height: 20px; margin: 10px 0 0; font-size: 14px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 14px;
  background: rgba(13, 21, 34, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  height: calc(52px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .2px; }
.brand .logo { width: 24px; height: 24px; color: var(--acc); border-radius: 5px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

/* tabs */
.tabs {
  position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 39;
  display: flex; gap: 4px; padding: 8px 12px;
  background: rgba(13, 21, 34, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1; height: 42px; border: 0; border-radius: 10px;
  background: transparent; color: var(--dim);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.tabs button.active { background: var(--card); color: var(--txt); }

/* layout */
main { max-width: 780px; margin: 0 auto; padding: 14px 12px 90px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 6px; font-size: 20px; }
.card h3 { margin: 0 0 8px; font-size: 16.5px; }
.card p { margin: 6px 0 10px; }

/* controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--txt);
  font: inherit; font-weight: 600; font-size: 15px; text-decoration: none;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: filter .12s ease, opacity .12s;
}
.btn:active { filter: brightness(1.15); }
.btn:disabled, .btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; }
.btn.primary:active { background: var(--acc-di); }
.btn.ghost { background: transparent; }
.btn.small { height: 38px; padding: 0 13px; font-size: 14px; border-radius: 9px; }
.btn.wide { width: 100%; }
.btnrow { display: flex; gap: 10px; margin-top: 10px; }
.btnrow .btn { flex: 1; }
.btncol { display: flex; flex-direction: column; gap: 9px; }

input[type="text"], input[type="password"], input[type="tel"], input[type="email"], input[type="date"], input[type="number"], input:not([type]), textarea, select {
  width: 100%; margin: 6px 0;
  background: var(--panel); color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 13px; font: inherit; font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; min-height: 74px; line-height: 1.4; }
select { padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238fa0b8' stroke-width='2' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--acc); outline-offset: 0; border-color: transparent; }

.check { display: inline-flex; align-items: center; gap: 8px; color: var(--dim); font-size: 14px; margin-right: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--acc); }

.seg { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin: 10px 0; }
.seg button { flex: 1; height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--dim); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg button.active { background: var(--acc); color: #fff; }

.optrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.optrow input[type="date"], .optrow input[type="number"] { width: auto; flex: 1; min-width: 120px; margin: 0; }
.optrow select { width: auto; min-width: 110px; margin: 0; }
.rowline { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 6px; }

.uploadcard { text-align: left; }
.uploadcard .btn { margin: 8px 0; }

/* pages */
.toolrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 6px; }
.chip {
  max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 13px; font-size: 13.5px; color: var(--txt);
}
.zoomseg { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.zoomseg button { border: 0; background: transparent; color: var(--dim); font: inherit; font-size: 13px; font-weight: 600; padding: 6px 11px; border-radius: 7px; cursor: pointer; }
.zoomseg button.active { background: var(--card); color: var(--txt); }

.pages { --z: 100; overflow-x: auto; }
.pagewrap { margin: 0 0 18px; }
.pimg {
  position: relative; width: calc(var(--z) * 1%);
  background: #fff; border-radius: 8px; overflow: hidden;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
}
.pimg img { display: block; width: 100%; height: auto; }
.pnum { color: var(--dim); font-size: 12.5px; margin-top: 6px; }

.overlay { position: absolute; inset: 0; }
.hotspot {
  position: absolute; cursor: pointer; border-radius: 4px;
  min-height: 13px; min-width: 14px;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s;
}
.hotspot:hover, .hotspot:active, .hotspot.sel { background: rgba(47, 109, 246, .28); box-shadow: 0 0 0 1.5px rgba(47,109,246,.75); }
.match { position: absolute; pointer-events: none; border-radius: 3px; background: rgba(245, 158, 11, .32); box-shadow: 0 0 0 1.5px rgba(245,158,11,.7); }

/* datelist */
.datelist { margin: 10px 0; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.daterow { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.daterow:last-child { border-bottom: 0; }
.daterow input { width: 19px; height: 19px; accent-color: var(--acc); flex: none; }
.daterow .dk { color: var(--txt); font-variant-numeric: tabular-nums; }
.daterow .arrow { color: var(--dim); }
.daterow .dv { color: var(--ok); font-weight: 600; font-variant-numeric: tabular-nums; }
.daterow .cnt { margin-left: auto; color: var(--dim); font-size: 12px; white-space: nowrap; }

.banner { border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; border: 1px solid; }
.banner.warn { background: rgba(245, 158, 11, .1); border-color: rgba(245, 158, 11, .45); color: #fbd38d; }

.result { margin: 10px 0 0; }
.help { margin: 0; padding-left: 18px; }
.help li { margin: 6px 0; }

/* recent */
.recent { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.recent h3 { margin: 0 0 8px; font-size: 14px; color: var(--dim); }
.recitem { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 2px; font-size: 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.recitem:last-child { border-bottom: 0; }
.recitem .rn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recitem .rt { color: var(--dim); font-size: 12px; flex: none; }

/* sheet */
.mask { position: fixed; inset: 0; background: rgba(5, 9, 16, .55); z-index: 60; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-width: 780px; margin: 0 auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  border: 1px solid var(--line); border-bottom: 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 34px rgba(0, 0, 0, .5);
  animation: rise .18s ease;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-title { font-weight: 600; }
#sheet-orig { margin: 2px 0 6px; word-break: break-word; }

/* toast + busy */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80;
  transform: translateX(-50%);
  background: #23304a; color: var(--txt); border: 1px solid var(--line);
  border-radius: 11px; padding: 12px 18px; font-size: 14.5px; font-weight: 600;
  max-width: 88vw; text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  animation: fade .16s ease;
}
.toast.err { border-color: rgba(239, 68, 68, .6); }
.busy { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; background: rgba(5, 9, 16, .45); }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .14); border-top-color: var(--acc);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ai-status { margin-top: 10px; font-size: 14px; }
.ai-status .v-good { color: var(--ok); font-weight: 700; }
.ai-status .v-bad { color: var(--warn); font-weight: 700; }
.ai-status ul { margin: 6px 0 0; }
.aistrip { display: flex; gap: 8px; overflow-x: auto; margin-top: 12px; padding-bottom: 4px; }
.aistrip a { flex: none; }
.aistrip img { height: 150px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.switchrow { display: flex; align-items: center; gap: 12px; margin: 8px 0; cursor: pointer; user-select: none; }
.switchrow input { display: none; }
.switch { width: 48px; height: 28px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); position: relative; transition: background .15s, border-color .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: #8fa0b8; transition: transform .15s, background .15s; }
.switchrow input:checked + .switch { background: var(--acc); border-color: var(--acc); }
.switchrow input:checked + .switch::after { transform: translateX(20px); background: #fff; }

/* lock screen */
.lockbody { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.lockwrap { width: 100%; max-width: 360px; }
.lockcard { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 26px 22px; text-align: center; }
.lockcard h1 { font-size: 21px; margin: 12px 0 4px; }
.lockcard p { margin: 6px 0 14px; }
.lockcard input { text-align: center; font-size: 20px; letter-spacing: 4px; padding: 10px 12px; }
.codeblock { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px; overflow-x: auto; }

@media (min-width: 640px) {
  .card { padding: 18px; }
}
