*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f7f7f6;
  --surface:    #ffffff;
  --border:     #e4e4e2;
  --border-md:  #d0d0ce;
  --accent:     #2563eb;
  --accent-h:   #1d4ed8;
  --accent-bg:  #eff6ff;
  --danger:     #dc2626;
  --danger-bg:  #fef2f2;
  --text:       #18181b;
  --text-2:     #52525b;
  --text-3:     #a1a1aa;
  --success:    #16a34a;
  --success-bg: #f0fdf4;
  --radius:     6px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Noto Sans SC', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ── HEADER ─────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
  margin-left: 8px;
}

.logo-sep {
  color: var(--text-3);
  font-weight: 300;
  margin: 0 3px;
}

.lang-toggle {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.lang-btn {
  padding: 5px 13px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.lang-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.lang-btn:hover:not(.active) { color: var(--text); }

/* ── LAYOUT ─────────────────────────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 300px 1fr;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  margin-bottom: 6px;
}

.drop-zone {
  border: 1.5px dashed var(--border-md);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--bg);
  position: relative;
}

.drop-zone:hover,
.drop-zone.over {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.drop-zone.over { transform: scale(1.005); }

.drop-zone input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 10px;
  background: var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-size: 18px;
  transition: background .15s, color .15s;
}

.drop-zone:hover .drop-icon,
.drop-zone.over .drop-icon {
  background: var(--accent);
  color: white;
}

.drop-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
}

.drop-sub {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.6;
}

.progress-wrap { display: none; }
.progress-wrap.visible { display: block; }

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.progress-label { font-size: 12px; color: var(--text-2); }
.progress-pct   { font-size: 12px; font-weight: 500; color: var(--accent); }

.progress-track {
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width .25s ease;
  border-radius: 99px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
  margin-bottom: 3px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 0 -20px;
}

.btn {
  width: 100%;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-h);
  border-color: var(--accent-h);
  box-shadow: 0 2px 8px rgba(37,99,235,.3);
}

.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary.loading  { opacity: .8; cursor: wait; }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}

.btn-ghost:hover {
  border-color: var(--border-md);
  color: var(--text);
  background: var(--bg);
}

.hint-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
}

.hint-box strong { color: var(--text); font-weight: 500; }

/* ── CANVAS ──────────────────────────────────────────────── */
.canvas {
  padding: 24px;
  overflow-y: auto;
  background: var(--bg);
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-3);
  text-align: center;
}

.empty-icon {
  width: 56px;
  height: 56px;
  border: 1.5px dashed var(--border-md);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--border-md);
  margin-bottom: 4px;
}

.empty-title { font-size: 14px; font-weight: 500; color: var(--text-2); }
.empty-sub   { font-size: 12px; color: var(--text-3); line-height: 1.6; max-width: 280px; }

.pages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.pages-title { font-size: 13px; font-weight: 600; color: var(--text); }
.pages-meta  { font-size: 12px; color: var(--text-3); }

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

/* ── PAGE CARD ───────────────────────────────────────────── */
.page-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  transition: border-color .15s, box-shadow .15s, transform .15s;
  position: relative;
  user-select: none;
  box-shadow: var(--shadow-sm);
}

.page-card:hover  { border-color: var(--border-md); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.page-card:active { cursor: grabbing; }

.page-card.dragging {
  opacity: .45;
  transform: scale(.97);
  box-shadow: none;
}

.page-card.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg), 0 0 0 3px var(--accent);
}

.page-thumb-wrap {
  position: relative;
  aspect-ratio: 3/4;
  background: var(--bg);
  overflow: hidden;
}

.page-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
  transition: opacity .15s;
}

.page-thumb:hover { opacity: .88; }

.page-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,.5);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.drag-hint {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,.4);
  color: white;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s;
}

.page-card:hover .drag-hint { opacity: 1; }

.page-footer {
  padding: 7px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid var(--border);
}

.page-name {
  flex: 1;
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-remove {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  flex-shrink: 0;
  font-family: inherit;
}

.btn-remove:hover {
  background: var(--danger-bg);
  border-color: #fca5a5;
  color: var(--danger);
}

/* ── LIGHTBOX ────────────────────────────────────────────── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 100;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.lightbox.open { display: flex; }
.lightbox-inner { position: relative; }

.lightbox img {
  max-width: 90vw;
  max-height: 88vh;
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0,0,0,.35);
  display: block;
}

.lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 28px;
  height: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  transition: all .15s;
}

.lightbox-close:hover { color: var(--text); box-shadow: var(--shadow-md); }

/* ── TOAST ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  transform: translateY(12px);
  opacity: 0;
  transition: all .25s cubic-bezier(.34,1.4,.64,1);
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

.toast.show    { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.toast.error   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #fca5a5; }

/* ── FOOTER ──────────────────────────────────────────────── */
footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

footer span { font-size: 12px; color: var(--text-3); }

/* ── SPINNER ─────────────────────────────────────────────── */
.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── TOUCH DRAG GHOST ────────────────────────────────────── */
.touch-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  opacity: .9;
  transform: rotate(2deg) scale(1.04);
  transition: none;
  border: 2px solid var(--accent);
  overflow: hidden;
}

/* ── MOBILE LAYOUT ───────────────────────────────────────── */
@media (max-width: 640px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow: visible;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
    gap: 12px;
  }

  .canvas {
    padding: 16px;
    overflow-y: visible;
  }

  /* slightly bigger tap targets on mobile */
  .btn { padding: 11px 16px; }

  .pages-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  /* make drag hint always visible on touch devices */
  .drag-hint { opacity: .7 !important; }
}
