/* =============================================================
   THALIB PDF — Custom Styles (Bootstrap 5 complement)
   Bootstrap handles: reset, flex utilities, grid, spacing,
   display, overflow, text utilities, border-radius utilities.
   This file: design tokens, themes, custom components, animations.
   ============================================================= */

/* ── Design Tokens ── */
:root {
  /* Surfaces */
  --bg:        #022c22;
  --surface:   #064e3b;
  --surface-2: #065f46;
  --raised:    #047857;
  --overlay:   rgba(2,44,34,.85);

  /* Ink */
  --ink:      #ecfdf5;
  --ink-soft: #a7f3d0;
  --ink-dim:  #6ee7b7;
  --display:  #ffffff;
  --on-ink:   #022c22;

  /* Accent – warm gold / amber */
  --accent:      #f59e0b;
  --accent-2:    #fbbf24;
  --accent-soft: rgba(245,158,11,.12);
  --accent-line: rgba(245,158,11,.38);
  --accent-glow: rgba(245,158,11,.18);

  /* Status */
  --sage:       #6FA98A;
  --sage-soft:  rgba(111,169,138,.14);
  --danger:     #D4726A;
  --danger-soft:rgba(212,114,106,.13);

  /* Diff */
  --ins-fg: #A8DFC0;
  --del-fg: #E8A89F;

  /* Structure */
  --line:       #232C3B;
  --line-soft:  rgba(255,255,255,.05);
  --radius:     12px;
  --radius-lg:  18px;
  --radius-xl:  24px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md:  0 4px 16px rgba(0,0,0,.45), 0 1px 4px rgba(0,0,0,.3);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.55), 0 4px 12px rgba(0,0,0,.35);

  /* Ambient glow background */
  --bg-glow-1: rgba(200,165,90,.07);
  --bg-glow-2: rgba(111,169,138,.05);

  /* Layout */
  --sidebar-w: 200px;
  --header-h:  64px;
  --bottom-nav-h: 60px;
}

/* ── Light theme ── */
:root[data-theme="light"] {
  --bg:        #f8faf7;
  --surface:   #ffffff;
  --surface-2: #ecfdf5;
  --raised:    #d1fae5;
  --overlay:   rgba(248,250,247,.88);

  --ink:      #064e3b;
  --ink-soft: #047857;
  --ink-dim:  #059669;
  --display:  #022c22;
  --on-ink:   #ffffff;

  --accent:      #d97706;
  --accent-2:    #b45309;
  --accent-soft: rgba(217,119,6,.11);
  --accent-line: rgba(217,119,6,.42);
  --accent-glow: rgba(217,119,6,.15);

  --sage:       #4A7D64;
  --sage-soft:  rgba(74,125,100,.12);
  --danger:     #A84840;
  --danger-soft:rgba(168,72,64,.1);

  --ins-fg: #1F5B3E;
  --del-fg: #7A2E23;

  --line:       #E2D8C5;
  --line-soft:  rgba(0,0,0,.05);

  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 16px rgba(0,0,0,.1), 0 1px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.14), 0 4px 12px rgba(0,0,0,.08);

  --bg-glow-1: rgba(168,118,44,.08);
  --bg-glow-2: rgba(74,125,100,.06);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg:        #f8faf7;
    --surface:   #ffffff;
    --surface-2: #ecfdf5;
    --raised:    #d1fae5;
    --overlay:   rgba(248,250,247,.88);
    --ink:      #064e3b;
    --ink-soft: #047857;
    --ink-dim:  #059669;
    --display:  #022c22;
    --on-ink:   #ffffff;
    --accent:      #d97706;
    --accent-2:    #b45309;
    --accent-soft: rgba(217,119,6,.11);
    --accent-line: rgba(217,119,6,.42);
    --accent-glow: rgba(217,119,6,.15);
    --sage:       #4A7D64;
    --sage-soft:  rgba(74,125,100,.12);
    --danger:     #A84840;
    --danger-soft:rgba(168,72,64,.1);
    --ins-fg: #1F5B3E;
    --del-fg: #7A2E23;
    --line:       #E2D8C5;
    --line-soft:  rgba(0,0,0,.05);
    --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:  0 4px 16px rgba(0,0,0,.1), 0 1px 4px rgba(0,0,0,.06);
    --shadow-lg:  0 12px 40px rgba(0,0,0,.14), 0 4px 12px rgba(0,0,0,.08);
    --bg-glow-1: rgba(168,118,44,.08);
    --bg-glow-2: rgba(74,125,100,.06);
  }
}

/* ── Base ── */
body {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 900px 500px at 5% -5%,  var(--bg-glow-1), transparent 60%),
    radial-gradient(ellipse 600px 400px at 95% 90%, var(--bg-glow-2), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background .25s, color .2s;
}

/* Override Bootstrap link-color so it doesn't clash with theme */
a { color: inherit; }

/* ── App Shell ── */
.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px 96px;
}

/* ── Header ── */
header.top {
  z-index: 40;
  gap: 16px;
  padding: 14px 0;
  margin-bottom: 28px;
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  background: var(--overlay);
  border-bottom: 1px solid var(--line-soft);
  /* extend full-bleed without extra wrapper */
  margin-left: -20px;
  margin-right: -20px;
  padding-left: 20px;
  padding-right: 20px;
}
/* ── Top Nav Buttons ── */
.top-nav-btn {
  border: 1px solid var(--accent-line);
  color: var(--accent);
  background: transparent;
  font-weight: 600;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}
.top-nav-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-2);
  transform: translateY(-1px);
}

/* ── Brand ── */
.brand-logo {
  width: 36px !important;
  height: 36px !important;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  display: block;
  object-fit: cover;
}

.brand-text h1 {
  font-size: 18px !important;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--display);
  line-height: 1.2;
  margin: 0 !important;
}

.brand-text p {
  margin: 2px 0 0 !important;
  font-size: 11.5px;
  color: var(--ink-soft);
  max-width: 46ch;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (max-width: 580px) {
  .brand-text p { display: none; }
  .brand-text h1 { font-size: 16px; }
}

/* ── Stamp badge ── */
.stamp {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--sage);
  background: var(--sage-soft);
  border: 1px solid rgba(111,169,138,.25);
  border-radius: 999px;
  padding: 5px 10px;
}

.stamp-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sage);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 var(--sage-soft); }
  50%       { box-shadow: 0 0 0 4px var(--sage-soft); }
}

@media (max-width: 480px) { .stamp { display: none !important; } }

/* ── Theme Toggle ── */
.themeToggle {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.themeToggle button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-dim);
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.themeToggle button span { display: none; }

@media (min-width: 640px) {
  .themeToggle button span { display: inline; }
}

.themeToggle button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.themeToggle button:hover:not(.active) {
  color: var(--ink-soft);
}

/* ── Main Layout ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 24px;
  align-items: start;
}

/* ── Sidebar Navigation ── */
nav.tools {
  position: sticky;
  top: calc(var(--header-h) + 28px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100dvh - var(--header-h) - 56px);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
nav.tools::-webkit-scrollbar { display: none; }

nav.tools .grplabel {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  padding: 6px 12px 4px;
  margin-top: 8px;
}
nav.tools .grplabel:first-child { margin-top: 0; }

nav.tools .grp {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

nav.tools button.tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  background: none;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
  position: relative;
  min-height: 36px;
  width: 100%;
}

nav.tools button.tool-btn .icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  opacity: .75;
  transition: opacity .15s;
}

nav.tools button.tool-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

nav.tools button.tool-btn:hover .icon { opacity: 1; }

nav.tools button.tool-btn.active {
  background: var(--accent-soft);
  color: var(--accent-2);
  font-weight: 600;
}

nav.tools button.tool-btn.active .icon { opacity: 1; }

nav.tools button.tool-btn.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  bottom: 25%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Sidebar separator between groups */
nav.tools .grp + .grplabel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

/* ── Mobile: Bottom Navigation ── */
.bottom-nav {
  display: none;
}

@media (max-width: 680px) {
  .layout {
    grid-template-columns: 1fr;
  }

  nav.tools {
    display: none !important;
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--overlay);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border-top: 1px solid var(--line-soft);
    overflow-x: auto;
    gap: 0;
    padding: 6px 8px env(safe-area-inset-bottom, 8px);
    scrollbar-width: none;
  }
  .bottom-nav::-webkit-scrollbar { display: none; }

  .bottom-nav .bnav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 10px;
    border-radius: 10px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 10px;
    font-weight: 500;
    color: var(--ink-dim);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .15s, color .15s;
    min-width: 52px;
  }

  .bottom-nav .bnav-item .icon {
    font-size: 18px;
    line-height: 1;
    transition: transform .15s;
  }

  .bottom-nav .bnav-item.active {
    color: var(--accent);
    background: var(--accent-soft);
  }

  .bottom-nav .bnav-item.active .icon {
    transform: scale(1.15);
  }

  .bottom-nav .bnav-item:hover:not(.active) {
    color: var(--ink-soft);
  }

  .app { padding-bottom: calc(var(--bottom-nav-h) + 24px); }
}

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 28px 30px;
  min-height: 400px;
  box-shadow: var(--shadow-md);
  transition: box-shadow .2s;
}

@media (max-width: 480px) {
  .panel { padding: 20px 18px; border-radius: var(--radius-lg); }
}

.panel h2 {
  font-size: clamp(17px, 2.5vw, 21px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  color: var(--display);
}

.panel .sub {
  color: var(--ink-soft);
  font-size: 13.5px;
  margin: 0 0 24px;
  max-width: 60ch;
  line-height: 1.65;
}

/* ── Dropzone ── */
.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .2s, background .2s, color .2s, transform .15s;
  background: var(--surface-2);
  position: relative;
}

.dropzone::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-lg);
  opacity: 0;
  background: radial-gradient(circle at center, var(--accent-glow), transparent 70%);
  transition: opacity .2s;
  pointer-events: none;
}

.dropzone:hover,
.dropzone.drag {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--ink);
  transform: scale(1.005);
}

.dropzone:hover::before,
.dropzone.drag::before {
  opacity: 1;
}

.dropzone input { display: none; }

/* ── File List ── */
.filelist {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filerow {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface-2);
  transition: border-color .15s, background .15s, opacity .15s;
}

.filerow.dragging { opacity: .35; }

.filerow.drag-over {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.draghandle {
  color: var(--ink-dim);
  font-size: 14px;
  letter-spacing: -2px;
  cursor: grab;
  flex-shrink: 0;
  user-select: none;
  padding: 2px 4px;
}

.draghandle:active { cursor: grabbing; }

.filerow .name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filerow .size {
  font-size: 11.5px;
  color: var(--ink-soft);
  flex-shrink: 0;
}

/* ── Thumbnails ── */
.thumbmini {
  object-fit: cover;
  border-radius: 5px;
  background: #fff;
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.thumbmini-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--raised);
}

.thumbmini-img {
  width: 50%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: block;
  margin: 6px auto 2px;
}

/* ── Image Cards ── */
.imgcard {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.imgcard:hover {
  border-color: var(--accent-line);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.imgcard-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--raised);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.imgcard-thumb img { width: 100%; height: 100%; object-fit: contain; }

.imgcard-rotbadge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: #1A1410;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  pointer-events: none;
  letter-spacing: .02em;
}

.imgcard-info {
  padding: 8px 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.imgcard-name {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-weight: 500;
}

.imgcard-size { font-size: 11px; color: var(--ink-soft); }

.imgcard-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 10px;
}

/* ── Icon Buttons ── */
.iconbtn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1;
  transition: color .12s, border-color .12s, background .12s;
}

.iconbtn:hover { color: var(--ink); border-color: var(--ink-dim); background: var(--raised); }
.iconbtn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* ── Primary Button ── */
button.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #1A1410;
  border: none;
  border-radius: var(--radius);
  padding: 11px 22px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 20px;
  letter-spacing: .01em;
  transition: filter .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 2px 8px var(--accent-glow);
}

button.primary:disabled {
  background: var(--raised);
  cursor: not-allowed;
  color: var(--ink-dim);
  box-shadow: none;
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 4px 16px var(--accent-glow);
}

button.primary:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 4px var(--accent-glow);
}

/* ── Ghost Button ── */
button.ghost {
  background: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}

button.ghost:hover { color: var(--ink); border-color: var(--ink-dim); background: var(--raised); }

/* ── Form Fields ── */
.field { margin-top: 18px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink-soft);
  margin-bottom: 7px;
  text-transform: uppercase;
}

.field input[type=text],
.field input[type=number],
.field input[type=password],
.field select,
.field textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}

.field input[type=text]:focus,
.field input[type=number]:focus,
.field input[type=password]:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field .hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--ink-dim);
  line-height: 1.55;
}

/* ── Server Badge ── */
.badge-server {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  margin-bottom: 16px;
}

.badge-server::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse-dot 2.5s ease-in-out infinite;
}

/* ── AI Result ── */
.airesult {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface-2);
}

.airesult textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.65;
  transition: border-color .15s;
}

.airesult textarea:focus { outline: none; border-color: var(--accent-line); }

.airesult .links { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ── Grid ── */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

/* ── Radio Row ── */
.radiorow {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: 2px;
}

.radiorow label {
  position: relative;
  padding: 7px 2px 11px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: color .15s;
}

.radiorow input { display: none; }

.radiorow label::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: transparent;
  border-radius: 99px;
  transition: background .15s;
}

.radiorow label:has(input:checked) { color: var(--ink); font-weight: 600; }
.radiorow label:has(input:checked)::after { background: var(--accent); }

/* ── Thumb Grid ── */
.thumbgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.thumb {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: var(--surface-2);
  position: relative;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.thumb.deleted { opacity: .35; }

.thumb.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.thumb:not(.deleted):hover {
  border-color: var(--accent-line);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.thumb img {
  width: 100%;
  display: block;
  border-radius: 6px;
  background: #fff;
}

.thumb .idx {
  font-size: 11px;
  color: var(--ink-soft);
  margin: 8px 0 6px;
  font-weight: 500;
}

.thumb .ctrl { display: flex; gap: 5px; flex-wrap: wrap; }

.thumb .ctrl button {
  flex: 1 1 auto;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 11px;
  padding: 5px 4px;
  cursor: pointer;
  color: var(--ink-soft);
  font-family: inherit;
  transition: color .12s, border-color .12s, background .12s;
}

.thumb .ctrl button:hover { color: var(--ink); border-color: var(--ink-dim); background: var(--surface); }

/* ── Status ── */
.status {
  margin-top: 18px;
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status.err { color: var(--danger); }

/* ── Spinner ── */
.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result Card ── */
.resultcard {
  margin-top: 22px;
  border: 1px solid rgba(111,169,138,.3);
  background: var(--sage-soft);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: 0 4px 16px rgba(111,169,138,.08);
}

.resultcard .meta {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 3px;
}

.resultcard .links { display: flex; gap: 8px; flex-wrap: wrap; }

.resultcard a {
  background: var(--ink);
  color: var(--on-ink);
  text-decoration: none;
  padding: 9px 18px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  transition: filter .12s, transform .1s;
}

.resultcard a:hover { filter: brightness(1.2); transform: translateY(-1px); }

/* ── Range Hint ── */
.rangehint {
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 6px;
}

/* ── Page Stack ── */
.pagestack {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-top: 22px;
}

.pagecard {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--surface-2);
}

.pagecard .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ── Canvas Wrap ── */
.canvaswrap {
  position: relative;
  line-height: 0;
  touch-action: none;
}

.canvaswrap canvas {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
}

.selectbox {
  position: absolute;
  border: 1.5px dashed var(--danger);
  background: rgba(212,114,106,.15);
  pointer-events: none;
}

/* ── Signature Pad ── */
.sigpad {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: repeating-linear-gradient(45deg, #F7F4EC, #F7F4EC 8px, #EEE9DC 8px, #EEE9DC 16px);
  touch-action: none;
  width: 100%;
  max-width: 380px;
}

/* ── Diff Box ── */
.diffbox {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  font-size: 13.5px;
  line-height: 1.75;
  max-height: 420px;
  overflow-y: auto;
  white-space: pre-wrap;
  background: var(--surface-2);
}

.diffbox ins { background: var(--sage-soft); text-decoration: none; color: var(--ins-fg); border-radius: 3px; }
.diffbox del { background: var(--danger-soft); color: var(--del-fg); border-radius: 3px; }

/* ── Progress Bar ── */
.progressbar {
  height: 5px;
  border-radius: 99px;
  background: var(--raised);
  overflow: hidden;
  margin-top: 12px;
}

.progressbar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .25s ease;
  border-radius: 99px;
}

/* ── File Preview ── */
.filepreview {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  background: var(--surface-2);
  margin-top: 0;
}

.fp-thumb {
  width: 54px;
  height: 70px;
  object-fit: cover;
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.fp-thumb-empty { background: var(--raised); }

.fp-meta .name { font-size: 13.5px; color: var(--ink); word-break: break-all; font-weight: 500; }
.fp-meta .size { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }

/* ── Rotate Cards ── */
.rotatecard {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 210px;
  text-align: center;
  transition: border-color .15s, box-shadow .15s;
}

.rotatecard:hover { border-color: var(--line); box-shadow: var(--shadow-sm); }

.rotategrid { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 22px; }

.rotatecard .actions {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
}

.circlebtn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  background: var(--raised);
  color: var(--ink-soft);
  position: relative;
  line-height: 1;
  transition: filter .12s, transform .1s;
}

.circlebtn.accent { background: var(--accent); color: #1A1410; }
.circlebtn:hover { filter: brightness(1.12); transform: scale(1.05); }

.circlebtn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--raised);
  color: var(--ink);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
  pointer-events: none;
  z-index: 10;
}

.thumbframe {
  background: #fff;
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.thumbframe img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  transition: transform .2s;
}

.rotatecard .caption {
  margin-top: 14px;
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: .03em;
  text-transform: uppercase;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Edit Toolbar ── */
.edittoolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  position: sticky;
  top: calc(var(--header-h) + 8px);
  z-index: 6;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.edittoolbar .toolbtn {
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink-soft);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}

.edittoolbar .toolbtn.active {
  background: var(--accent);
  color: #1A1410;
  border-color: var(--accent);
  font-weight: 600;
}

.edittoolbar .toolbtn:hover:not(.active) { color: var(--ink); border-color: var(--ink-dim); }

.edittoolbar label {
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}

.edittoolbar input[type=color] {
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  background: var(--surface-2);
  cursor: pointer;
}

.edittoolbar input[type=number] {
  width: 58px;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
}

.edithint { margin-left: auto; font-size: 12px; color: var(--ink-dim); }

/* ── Edit Page ── */
.editpage {
  position: relative;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  container-type: size;
  margin-bottom: 24px;
}

.editpage img.editbg {
  width: 100%; height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
  object-fit: fill;
}

canvas.editstrokes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ── Edit Elements ── */
.edit-el {
  position: absolute;
  cursor: default;
}

.edit-el .elbar {
  position: absolute;
  top: -28px;
  left: 0;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .12s;
  z-index: 2;
}

.edit-el:hover .elbar,
.edit-el:focus-within .elbar { opacity: 1; }

.elbar button {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--ink-soft);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: color .1s, background .1s;
}

.elbar button:hover { color: var(--ink); background: var(--surface); }
.elbar button:first-child { cursor: grab; }

.edit-text {
  min-width: 30px;
  outline: 1.5px dashed transparent;
  white-space: pre-wrap;
  line-height: 1.2;
  padding: 2px;
  border-radius: 4px;
  transition: outline-color .12s;
}

.edit-text:focus { outline-color: var(--accent-line); }

.edit-img-wrap { min-width: 20px; min-height: 20px; }
.edit-img-wrap img { width: 100%; height: 100%; display: block; pointer-events: none; }

.resize-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 13px;
  height: 13px;
  background: var(--accent);
  border-radius: 4px;
  cursor: nwse-resize;
  z-index: 2;
  box-shadow: var(--shadow-sm);
}

.page-clear-strokes {
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 3;
  font-size: 11px;
  padding: 5px 10px;
}

/* ── Dot (legacy, keep for compat) ── */
nav.tools button .dot { display: none; }

/* ── Bootstrap global overrides — prevent conflicts ── */

/* Bootstrap sets body { margin: 0 } — fine, keep it */
/* Bootstrap reboot sets img { max-width: 100%; height: auto } — override for brand-logo done above */

/* Bootstrap reboot adds box-sizing: border-box — already what we want */

/* Bootstrap's .sticky-top uses z-index: 1020 — bump our header higher */
header.top { z-index: 1030 !important; }

/* Bootstrap resets button outline — restore our custom focus */
:focus-visible { outline: none; }
button:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }

/* Bootstrap nav styles — reset for our custom nav */
nav.tools,
.bottom-nav { list-style: none; padding: 0; margin: 0; }