:root {
  --bg: #07111f;
  --bg-soft: #0b1627;
  --card: #101d30;
  --card-2: #13233a;
  --text: #eef5ff;
  --muted: #9db0c9;
  --primary: #0b5cff;
  --primary-2: #00a8ff;
  --danger: #ff5d70;
  --border: rgba(167, 194, 230, 0.16);
  --success: #2ad19b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(circle at 20% -10%, rgba(11, 92, 255, 0.20), transparent 34rem),
    radial-gradient(circle at 95% 0%, rgba(0, 168, 255, 0.10), transparent 26rem),
    var(--bg);
  color: var(--text);
}
button, select, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
.hidden { display: none !important; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(7, 17, 31, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { width: 42px; height: 42px; border-radius: 12px; box-shadow: 0 8px 20px rgba(0,0,0,.28); }
.brand h1 { margin: 0; font-size: 1.05rem; letter-spacing: .01em; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 54vw; }

main { width: min(100%, 700px); margin: 0 auto; padding: 16px 14px max(26px, env(safe-area-inset-bottom)); }
section { margin-bottom: 14px; padding: 17px; border: 1px solid var(--border); border-radius: 18px; background: linear-gradient(180deg, rgba(19,35,58,.95), rgba(15,29,48,.96)); box-shadow: var(--shadow); }
h2 { margin: 0; font-size: 1rem; }
.hint { display: block; margin: 5px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.hint.compact { margin: 7px 0 12px; }

.privacy-card { display: flex; gap: 12px; background: linear-gradient(135deg, rgba(25, 88, 78, .55), rgba(12, 48, 55, .55)); border-color: rgba(57, 211, 162, .28); }
.privacy-icon { font-size: 1.35rem; }
.privacy-card strong { color: #c8ffe9; }
.privacy-card p { margin: 5px 0 0; color: #a8d9ca; font-size: .82rem; line-height: 1.45; }
.section-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.badge, .device-only { flex: 0 0 auto; border-radius: 999px; padding: 5px 9px; color: #bcd6ff; background: rgba(11,92,255,.14); border: 1px solid rgba(80,140,255,.25); font-size: .72rem; }
.device-only { color: #b7f7e1; background: rgba(42,209,155,.10); border-color: rgba(42,209,155,.23); }

.primary, .ghost-btn, .filter-btn, .doc-actions button, .page-actions button { border: 0; border-radius: 12px; }
.primary { width: 100%; padding: 13px 15px; margin-top: 11px; color: #fff; font-weight: 750; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 8px 24px rgba(11,92,255,.24); }
.primary:active { transform: translateY(1px); }
.ghost-btn { padding: 9px 11px; color: #d4e3f7; background: rgba(255,255,255,.07); border: 1px solid var(--border); }
.ghost-btn.dark { width: 100%; margin-top: 8px; background: rgba(255,255,255,.04); }

.field-label { display: block; margin-top: 12px; color: #ccdaed; font-size: .8rem; font-weight: 650; }
.select-input { width: 100%; margin-top: 6px; padding: 11px 12px; color: var(--text); background: #091525; border: 1px solid var(--border); border-radius: 12px; outline: none; }
.check-card { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0 2px; padding: 12px; background: rgba(255,255,255,.035); border: 1px solid var(--border); border-radius: 13px; }
.check-card input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--primary); }
.check-card span { min-width: 0; }
.check-card strong { display: block; font-size: .82rem; }
.check-card small { display: block; margin-top: 3px; color: var(--muted); font-size: .74rem; line-height: 1.35; }
.status-text { min-height: 1.2em; margin: 10px 1px 0; color: #b9c9de; font-size: .8rem; line-height: 1.4; }

.page-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; margin: 14px 0 4px; }
.page-card { position: relative; overflow: hidden; background: #091525; border: 1px solid var(--border); border-radius: 13px; }
.page-card img { display: block; width: 100%; height: 120px; object-fit: cover; }
.page-num { position: absolute; top: 7px; left: 7px; min-width: 26px; padding: 4px 7px; text-align: center; color: white; background: rgba(4,9,17,.76); border-radius: 999px; font-size: .72rem; font-weight: 800; }
.page-actions { display: flex; gap: 4px; padding: 5px; }
.page-actions button { flex: 1; padding: 7px 0; color: #d6e5fb; background: rgba(255,255,255,.055); }

.result-card { border-color: rgba(42,209,155,.28); background: linear-gradient(145deg, rgba(13,64,55,.72), rgba(16,35,52,.95)); }
.result-icon { display: grid; place-items: center; width: 42px; height: 42px; margin-bottom: 10px; border-radius: 50%; color: #061912; background: var(--success); font-weight: 900; }
.result-copy h2 { color: #caffec; }
.filename { margin: 8px 0 0; overflow-wrap: anywhere; color: #fff; font-size: .82rem; font-weight: 700; }
.result-actions { margin-top: 10px; }
.result-actions .ghost-btn { width: 100%; margin-top: 8px; }

.doc-list { display: flex; flex-direction: column; gap: 8px; margin-top: 13px; }
.doc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px; background: rgba(255,255,255,.035); border: 1px solid var(--border); border-radius: 12px; }
.doc-row > div:first-child { min-width: 0; }
.doc-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .86rem; }
.doc-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.doc-actions button { width: 38px; height: 38px; color: #e3edfb; background: rgba(255,255,255,.06); }
.doc-actions .danger-btn { color: #ff9cab; }
.empty-state { margin: 4px 0 0; padding: 13px; color: var(--muted); text-align: center; font-size: .8rem; border: 1px dashed var(--border); border-radius: 12px; }
.info-card { box-shadow: none; background: rgba(12,25,43,.74); }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; background: rgba(3,8,15,.97); }
.crop-wrap { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.crop-wrap img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.crop-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.crop-poly { fill: rgba(11,92,255,.18); stroke: #3f8cff; stroke-width: 6; vector-effect: non-scaling-stroke; }
.crop-handle { fill: #0b5cff; stroke: white; stroke-width: 4; vector-effect: non-scaling-stroke; cursor: grab; }
.crop-controls { padding: 12px 14px max(18px, env(safe-area-inset-bottom)); background: #08111e; border-top: 1px solid var(--border); }
.filter-row { display: flex; gap: 7px; }
.filter-btn { flex: 1; padding: 9px 7px; color: #b9c9de; background: #101d30; border: 1px solid var(--border); font-size: .78rem; }
.filter-btn.active { color: white; background: #164fb2; border-color: #2f72e6; }
.processing-box { margin: auto; padding: 22px; text-align: center; color: white; }
.processing-box p { margin: 0 0 6px; font-weight: 750; }
.processing-box small { color: var(--muted); }
.spinner { width: 42px; height: 42px; margin: 0 auto 15px; border: 4px solid rgba(255,255,255,.13); border-top-color: #55b6ff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 680px) {
  main { padding-top: 24px; }
  section { padding: 20px; }
  .brand span { max-width: none; }
}

@media (max-width: 420px) {
  .app-header { padding-left: 12px; padding-right: 12px; }
  .brand-icon { width: 38px; height: 38px; }
  .brand span { max-width: 46vw; }
  main { padding-left: 10px; padding-right: 10px; }
  section { padding: 14px; border-radius: 16px; }
  .page-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-card img { height: 135px; }
}
