@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Caveat:wght@500;700&family=Dancing+Script:wght@600;700&display=swap');

:root {
  /* Shadcn neutral / zinc design system tokens */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --fold: transparent;
  --line: #e4e4e7;
  --line-strong: #d4d4d8;
  --ink: #09090b;
  --ink-soft: #71717a;
  --primary: #18181b;
  --primary-hover: #27272a;
  --on-primary: #fafafa;
  --primary-soft: #f4f4f5;
  --safe: #16a34a;
  --safe-soft: #f0fdf4;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --shadow-lift: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --focus: 0 0 0 2px #ffffff, 0 0 0 4px #18181b;
  --radius: 0.75rem;
  --radius-sm: 0.375rem;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-head: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #09090b;
    --surface: #121215;
    --surface-2: #1c1c20;
    --fold: transparent;
    --line: #27272a;
    --line-strong: #3f3f46;
    --ink: #fafafa;
    --ink-soft: #a1a1aa;
    --primary: #fafafa;
    --primary-hover: #e4e4e7;
    --on-primary: #18181b;
    --primary-soft: #27272a;
    --safe: #22c55e;
    --safe-soft: #052e16;
    --danger: #ef4444;
    --danger-soft: #450a0a;
    --shadow-lift: 0 12px 30px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --focus: 0 0 0 2px #09090b, 0 0 0 4px #fafafa;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #09090b;
  --surface: #121215;
  --surface-2: #1c1c20;
  --fold: transparent;
  --line: #27272a;
  --line-strong: #3f3f46;
  --ink: #fafafa;
  --ink-soft: #a1a1aa;
  --primary: #fafafa;
  --primary-hover: #e4e4e7;
  --on-primary: #18181b;
  --primary-soft: #27272a;
  --safe: #22c55e;
  --safe-soft: #052e16;
  --danger: #ef4444;
  --danger-soft: #450a0a;
  --shadow-lift: 0 12px 30px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --focus: 0 0 0 2px #09090b, 0 0 0 4px #fafafa;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-family: var(--font-head);
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.025em;
  color: var(--ink);
}
h1 { font-size: clamp(2rem, 4.5vw, 2.75rem); letter-spacing: -0.035em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, canvas, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

.wrap { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 28px; } }

/* Header / Navbar */
.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 0.15s;
}
:root[data-theme='light'] .topbar, :root:not([data-theme='dark']) .topbar {
  background: rgba(255, 255, 255, 0.88);
}
:root[data-theme='dark'] .topbar {
  background: rgba(9, 9, 11, 0.88);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .topbar {
    background: rgba(9, 9, 11, 0.88);
  }
}

.topbar .wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--font-head);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  min-height: 40px;
  transition: opacity 0.15s;
}
.brand:hover { opacity: 0.85; }
.brand-mark { width: 26px; height: 32px; color: var(--primary); }
.topbar-spacer { flex: 1; }

.offline-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.775rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all 0.2s ease;
}
.offline-pill svg { width: 14px; height: 14px; }
.offline-pill:not(.is-online) {
  background: var(--safe-soft);
  color: var(--safe);
  border-color: rgba(22, 163, 74, 0.25);
}
.offline-pill.is-online {
  background: var(--surface-2);
  color: var(--ink-soft);
}
@media (max-width: 520px) {
  .topbar .wrap { flex-wrap: nowrap; min-height: 54px; gap: 6px; }
  .brand { font-size: 1.05rem; }
  .offline-pill { padding: 0; width: 36px; height: 36px; justify-content: center; }
  .offline-pill .pill-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
.top-actions { display: flex; gap: 6px; align-items: center; }

/* Buttons (shadcn button variants) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  height: 38px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
.btn-primary:hover {
  background: var(--primary-hover);
  opacity: 0.95;
  transform: translateY(-0.5px);
}
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
}
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.btn-danger {
  background: var(--danger);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
.btn-danger:hover {
  opacity: 0.92;
  transform: translateY(-0.5px);
}
.btn[disabled] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn-big { min-height: 44px; height: 44px; padding: 10px 22px; font-size: 0.95rem; font-weight: 600; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  color: var(--ink);
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 15px; height: 15px; }
.lang-btn {
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  width: auto;
  padding: 0 10px;
}

/* Modern Card (replaces dog-eared sheet) */
.sheet {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  clip-path: none !important;
  box-shadow: var(--shadow-sm);
}
.sheet::after {
  display: none !important;
  content: none !important;
}

/* Home Hero */
.home-hero { padding: 44px 0 32px; display: grid; gap: 32px; }
@media (min-width: 900px) {
  .home-hero { grid-template-columns: 1.1fr 1fr; align-items: center; padding: 56px 0 40px; }
}
.home-hero h1 {
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-soft) 100%);
  -webkit-background-clip: text;
  color: var(--ink);
}
.home-hero .lede {
  color: var(--ink-soft);
  font-size: 1.05rem;
  margin-top: 14px;
  line-height: 1.6;
  max-width: 36em;
}
.promise-list {
  list-style: none;
  padding: 0;
  margin: 22px 0 0;
  display: grid;
  gap: 10px;
}
.promise-list li {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 0.925rem;
  font-weight: 500;
  color: var(--ink);
}
.promise-list svg {
  width: 15px;
  height: 15px;
  color: var(--safe);
  flex: none;
  padding: 3px;
  background: var(--safe-soft);
  border-radius: 50%;
}

/* Dropzone (shadcn upload drop area) */
.dropzone {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 12px;
  padding: 36px 20px;
  min-height: 220px;
  border: 2px dashed var(--line-strong);
  background: var(--surface);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-sm);
}
.dropzone:hover {
  border-color: var(--ink-soft);
  background: var(--surface-2);
}
.dropzone .dz-icon {
  width: 44px;
  height: 44px;
  color: var(--ink);
  padding: 8px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: transform 0.2s;
}
.dropzone:hover .dz-icon { transform: translateY(-2px); }
.dropzone strong { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
.dropzone .dz-sub { color: var(--ink-soft); font-size: 0.875rem; }
.dropzone.is-over {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: scale(1.01);
}
.dropzone:focus-visible { box-shadow: var(--focus); }
.dropzone.compact {
  min-height: 0;
  padding: 18px 16px;
  grid-auto-flow: column;
  gap: 14px;
  justify-content: center;
}
.dropzone.compact .dz-icon { width: 30px; height: 30px; padding: 4px; border-radius: 8px; }

.pending-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.pending-bar .grow { flex: 1; min-width: 180px; font-size: 0.92rem; color: var(--ink); }
.pending-bar .grow strong { font-weight: 600; }

/* Tool Groups & Grid (shadcn Cards) */
.tool-groups { display: grid; gap: 36px; padding: 12px 0 44px; }
.tool-group h2 {
  margin-bottom: 16px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.tool-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.tool-tile {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 4px 14px;
  align-items: start;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
  min-height: 94px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.tool-tile:hover {
  border-color: var(--line-strong);
  background: var(--surface);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lift);
}
.tool-tile:hover .tool-ico {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.tool-tile:focus-visible { box-shadow: var(--focus); }
.tool-ico {
  grid-row: span 2;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  transition: all 0.2s ease;
}
.tool-ico svg { width: 22px; height: 22px; }
.tool-tile .t-name { font-weight: 600; font-size: 0.975rem; letter-spacing: -0.015em; color: var(--ink); }
.tool-tile .t-desc { color: var(--ink-soft); font-size: 0.85rem; line-height: 1.45; }
.tool-tile.is-hint {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow-md);
}

/* History Section */
.history { padding: 12px 0 60px; }
.history-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.history-head h2 { flex: 1; font-size: 1.25rem; font-weight: 700; }
.history-note { color: var(--ink-soft); font-size: 0.875rem; margin-bottom: 16px; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.history-item:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}
.history-item .h-ico {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--ink);
}
.history-item .h-ico svg { width: 18px; height: 18px; }
.history-item .h-name { font-weight: 600; font-size: 0.92rem; word-break: break-word; color: var(--ink); }
.history-item .h-meta { color: var(--ink-soft); font-size: 0.825rem; }
.history-item .h-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 560px) {
  .history-item { grid-template-columns: 42px 1fr; }
  .history-item .h-actions { grid-column: 1 / -1; justify-content: flex-start; }
}
.empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.empty strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; font-size: 0.95rem; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  min-height: 38px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
}
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }

/* Tool Page / Workspace */
.tool-page { padding-top: 24px; padding-bottom: 64px; }
@media (max-width: 560px) {
  .tool-page { padding-top: 14px; }
  .tool-head { gap: 12px; margin-bottom: 18px; }
  .tool-head .tool-ico { width: 44px; height: 44px; }
  .tool-head .tool-ico svg { width: 24px; height: 24px; }
  .tool-head h1 { font-size: 1.6rem; }
  .crumbs { margin-bottom: 8px; margin-left: -8px; }
}
.crumbs { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.tool-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 24px; }
.tool-head .tool-ico {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  place-items: center;
}
.tool-head .tool-ico svg { width: 28px; height: 28px; }
.tool-head h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.025em; }
.tool-head p { color: var(--ink-soft); margin-top: 6px; font-size: 0.95rem; max-width: 48em; line-height: 1.5; }

.tool-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
.tool-layout > * { min-width: 0; }
@media (min-width: 768px) {
  .tool-layout.has-side { grid-template-columns: minmax(0, 1fr) 290px; align-items: start; gap: 24px; }
  .tool-side { position: sticky; top: 80px; max-height: calc(100vh - 96px); overflow-y: auto; overscroll-behavior: contain; padding-bottom: 4px; }
}
@media (min-width: 1100px) {
  .tool-layout.has-side { grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; }
}

/* Panels (shadcn Card containers) */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.panel + .panel { margin-top: 16px; }
.panel h3 { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.015em; margin-bottom: 14px; }
.panel-actions { display: grid; gap: 10px; margin-top: 18px; }

/* Form Controls */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label, .field > .label { font-weight: 600; font-size: 0.875rem; letter-spacing: -0.01em; color: var(--ink); }
.field .hint { color: var(--ink-soft); font-size: 0.825rem; }
.input, select.input, textarea.input {
  width: 100%;
  min-height: 38px;
  height: 38px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.875rem;
  transition: all 0.15s ease;
}
textarea.input { min-height: 90px; height: auto; resize: vertical; padding: 10px 12px; }
.input:focus, select.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus);
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; min-width: 120px; }
input[type='range'] { width: 100%; accent-color: var(--primary); min-height: 32px; }
input[type='color'] {
  width: 48px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  padding: 8px 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
}
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: none; }

/* Segmented control (shadcn Tabs style) */
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.segmented button {
  flex: 1 1 auto;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  border: 0;
  background: transparent;
  font-weight: 500;
  font-size: 0.825rem;
  color: var(--ink-soft);
  transition: all 0.15s ease;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

.choice-list { display: grid; gap: 8px; }
.choice {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  cursor: pointer;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.choice:hover { border-color: var(--line-strong); background: var(--surface-2); }
.choice input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); }
.choice:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.choice .c-title { font-weight: 600; font-size: 0.9rem; color: var(--ink); }
.choice .c-desc { color: var(--ink-soft); font-size: 0.825rem; }

/* File List & Rows */
.file-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.file-row {
  display: grid;
  grid-template-columns: auto 52px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.file-row:hover { border-color: var(--line-strong); }
.file-row .drag-handle {
  cursor: grab;
  color: var(--ink-soft);
  width: 24px;
  height: 40px;
  display: grid;
  place-items: center;
  transition: color 0.15s;
}
.file-row .drag-handle:hover { color: var(--ink); }
.file-row .thumb {
  width: 52px;
  height: 64px;
  border-radius: 4px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.file-row .thumb canvas, .file-row .thumb img { width: 100%; height: 100%; object-fit: contain; }
.file-row .f-name { font-weight: 600; font-size: 0.9rem; word-break: break-word; color: var(--ink); }
.file-row .f-meta { color: var(--ink-soft); font-size: 0.825rem; }
.file-row .f-meta.is-error { color: var(--danger); font-weight: 600; }
.file-row .f-actions { display: flex; gap: 4px; }
@media (max-width: 560px) {
  .file-row { grid-template-columns: auto 44px 1fr; }
  .file-row .thumb { width: 44px; height: 54px; }
  .file-row .f-actions { grid-column: 2 / -1; }
}
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { box-shadow: var(--shadow-lift); }

/* Page Grid & Thumbnails */
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 16px; }
@media (max-width: 480px) { .page-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }
.page-card { display: grid; gap: 6px; }
.page-thumb {
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 6px;
  background: var(--surface-2);
  cursor: pointer;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}
.page-thumb:hover { border-color: var(--line-strong); transform: scale(1.02); }
.page-thumb canvas { max-height: 100%; width: auto; box-shadow: 0 1px 3px rgba(0,0,0,0.12); border-radius: 2px; }
.page-card.is-selected .page-thumb { border-color: var(--primary); background: var(--primary-soft); }
.page-card.is-deleted .page-thumb { opacity: 0.35; }
.page-card .p-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  min-height: 34px;
}
.page-card .p-tools { display: flex; gap: 2px; }
.page-card .sel-mark {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.75rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.page-thumb .loading-dots { color: var(--ink-soft); font-size: 0.85rem; }
.page-thumb:focus-visible { box-shadow: var(--focus); }

/* Progress & Status */
.progress { display: grid; gap: 8px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.progress-track { height: 8px; border-radius: 9999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress-fill { height: 100%; width: 0; background: var(--primary); transition: width 0.25s ease; }
.progress-label { display: flex; justify-content: space-between; gap: 12px; font-size: 0.85rem; font-weight: 500; color: var(--ink); }
.notice {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.875rem;
  color: var(--ink);
}
.notice.warn { background: var(--surface-2); border-color: var(--line-strong); }
.notice.error { background: var(--danger-soft); color: var(--danger); border-color: rgba(239, 68, 68, 0.3); font-weight: 600; }
.notice + .notice, .notice + .panel, .panel + .notice { margin-top: 12px; }
.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--primary);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } * { transition: none !important; } }

/* Result Section */
.result {
  display: grid;
  gap: 18px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  scroll-margin-top: 90px;
}
.result:focus, .result:focus-visible { outline: none; box-shadow: var(--shadow-lift); }
.result-head { display: flex; gap: 14px; align-items: flex-start; }
.result-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--safe-soft);
  color: var(--safe);
  border: 1px solid rgba(22, 163, 74, 0.2);
}
.result-badge svg { width: 22px; height: 22px; stroke-width: 2.5; }
.result h3 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; }
.result-summary { color: var(--ink-soft); margin-top: 4px; font-size: 0.9rem; }
.result-files { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.result-files li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.r-ico {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}
.r-name { font-weight: 600; font-size: 0.92rem; overflow-wrap: anywhere; line-height: 1.3; color: var(--ink); }
.r-size { color: var(--ink-soft); font-size: 0.825rem; }
@media (max-width: 520px) {
  .result { padding: 18px 16px; }
  .result-files li { grid-template-columns: 40px minmax(0, 1fr); }
  .result-files li .btn { grid-column: 1 / -1; }
}
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.next-step { border-top: 1px solid var(--line); padding-top: 18px; }
.next-step h4 { margin: 0 0 12px; font-size: 0.95rem; font-weight: 600; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 14px 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--line-strong); background: var(--surface-2); }
.chip-ico { width: 24px; height: 24px; display: grid; place-items: center; color: var(--ink); flex: none; }
.chip-ico svg { width: 18px; height: 18px; }
.chip-more { padding-left: 14px; color: var(--ink-soft); background: transparent; border-style: dashed; }
.save-note { color: var(--ink-soft); font-size: 0.85rem; display: flex; gap: 6px; align-items: center; }

/* Popover / Dropdown Menu (shadcn Popover/Dropdown) */
.menu-wrap { position: relative; }
.menu-trigger { min-height: 36px; height: 36px; padding: 6px 12px; }
.menu-trigger svg { width: 14px; height: 14px; margin-left: 2px; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  width: 240px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
  padding: 4px;
  animation: scaleIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}
.menu.open-up { top: auto; bottom: calc(100% + 6px); }
.menu.align-left { right: auto; left: 0; }
.menu-item {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  text-align: left;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--ink);
  transition: all 0.12s ease;
}
.menu-item:hover, .menu-item:focus-visible {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: none;
}

/* Mobile Bar */
.mobile-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(0,0,0,.08);
}
body.has-mobile-bar { padding-bottom: 84px; }

/* Viewer & Toolbar */
.viewer {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 36px;
  justify-items: center;
  background: var(--surface-2);
  padding: 24px 16px 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
}
@media (max-width: 560px) { .viewer { padding: 12px 8px 32px; gap: 28px; } }
.viewer-page {
  position: relative;
  width: 100%;
  background: #ffffff;
  box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.12), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  touch-action: pan-y;
}
.viewer-page canvas { width: 100%; height: auto; border-radius: 4px; }
.viewer-page .overlay { position: absolute; inset: 0; }
.viewer-page .page-no {
  position: absolute;
  bottom: -28px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--ink-soft);
}
.viewer.is-placing .overlay { cursor: crosshair; }
.toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 70px;
  z-index: 5;
  margin-bottom: 14px;
}
.toolbar .btn { padding: 6px 12px; height: 34px; min-height: 34px; font-size: 0.825rem; }
.toolbar .btn[aria-pressed='true'] { background: var(--ink); color: var(--bg); }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
@media (max-width: 767px) {
  .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; top: 60px; margin-left: -4px; margin-right: -4px; }
  .toolbar > * { flex: none; }
}

.placed {
  position: absolute;
  border: 1px dashed transparent;
  touch-action: none;
  cursor: move;
  user-select: none;
}
.placed:hover, .placed.is-active { border-color: var(--primary); }
.placed.is-active { background: rgba(24, 24, 27, 0.05); }
.placed img { width: 100%; height: 100%; pointer-events: none; }
.placed .p-text {
  user-select: text;
  -webkit-user-select: text;
  white-space: pre;
  line-height: 1.15;
  cursor: text;
  outline: none;
  min-width: 1ch;
  padding: 0 1px;
  font-family: Helvetica, Arial, sans-serif;
}
.placed .handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #ffffff;
  cursor: nwse-resize;
  display: none;
}
.placed .remove {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  display: none;
  place-items: center;
  font-weight: 700;
  font-size: 0.75rem;
}
.placed.is-active .handle, .placed.is-active .remove { display: grid; }
.redact-box { position: absolute; background: #000; outline: 2px solid var(--danger); outline-offset: 1px; }
.redact-box .remove {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
}
.redact-draft { position: absolute; border: 2px dashed var(--danger); background: rgba(239, 68, 68, 0.15); pointer-events: none; }

.form-input {
  position: absolute;
  border: 1px solid rgba(59, 130, 246, 0.6);
  background: rgba(239, 246, 255, 0.7);
  color: #09090b;
  padding: 0 4px;
  border-radius: 2px;
  font-family: Helvetica, Arial, sans-serif;
}
.form-input:focus-visible { outline: 2px solid var(--primary); box-shadow: none; }
textarea.form-input { resize: none; padding: 2px 4px; line-height: 1.2; }
input[type='checkbox'].form-input, input[type='radio'].form-input { margin: 0; accent-color: #2563eb; background: transparent; border: 0; }

/* Modal (shadcn Dialog) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}
.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  padding: 24px;
  animation: scaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { flex: 1; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }
.sig-pad {
  width: 100%;
  height: 200px;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  touch-action: none;
  cursor: crosshair;
}
.sig-preview {
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  min-height: 110px;
  display: grid;
  place-items: center;
  padding: 10px;
  color: #111;
}
.saved-sigs { display: flex; gap: 10px; flex-wrap: wrap; }
.saved-sig {
  position: relative;
  width: 150px;
  height: 70px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 6px;
  transition: border-color 0.15s;
}
.saved-sig:hover { border-color: var(--line-strong); }
.saved-sig img { width: 100%; height: 100%; object-fit: contain; }
.saved-sig .del {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s ease;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected='true'] { color: var(--ink); font-weight: 600; border-bottom-color: var(--primary); }

/* Toasts (shadcn Sonner style) */
.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  left: auto;
  display: grid;
  justify-items: end;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}
@media (max-width: 640px) {
  .toasts { left: 16px; right: 16px; justify-items: center; }
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  max-width: 440px;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.error { background: var(--danger); color: #ffffff; border-color: transparent; }

.text-out {
  width: 100%;
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}
.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }
.stack { display: grid; gap: 12px; }

/* Footer */
.footer {
  border-top: 1px solid var(--line);
  padding: 24px 0 44px;
  color: var(--ink-soft);
  font-size: 0.85rem;
}
.footer .wrap { display: flex; gap: 12px 24px; flex-wrap: wrap; justify-content: space-between; align-items: center; }
.footer button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  min-height: 38px;
  font-weight: 500;
  transition: opacity 0.15s;
}
.footer button:hover { opacity: 0.75; }
