@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap');

@font-face {
  font-family: 'Great Vibes';
  src: url('/fonts/GreatVibes-Regular.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Dancing Script';
  src: url('/fonts/DancingScript-Regular.ttf') format('truetype');
  font-display: swap;
}
@font-face {
  font-family: 'Allura';
  src: url('/fonts/Allura-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #0b0f1a;
  --panel: #121a2a;
  --panel-2: #0f1624;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --accent: #22d3ee;
  --accent-2: #f97316;
  --success: #22c55e;
  --danger: #ef4444;
  --border: rgba(148, 163, 184, 0.2);
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 20% -10%, #1e2a49 0%, #0b0f1a 55%),
              radial-gradient(900px 600px at 90% 10%, #18253f 0%, #0b0f1a 65%);
  color: var(--text);
  min-height: 100vh;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 26, 0.9);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
}

.logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07131e;
  box-shadow: var(--shadow);
}

.title {
  font-size: 18px;
  font-weight: 700;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.content {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  padding: 24px 32px 32px;
  flex: 1;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: var(--shadow);
  min-height: 0;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 12px;
}

.pages-list {
  display: grid;
  gap: 12px;
  max-height: 320px;
  overflow: auto;
  padding-right: 6px;
}

.page-thumb {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 10px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid transparent;
  padding: 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s ease;
}

.page-thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.2);
}

.page-thumb img {
  width: 54px;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.page-thumb .meta {
  font-size: 12px;
  color: var(--muted);
}

.page-actions,
.tools {
  display: grid;
  gap: 8px;
}

.ocr-panel {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.ocr-status {
  font-size: 12px;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
}

.editor {
  background: rgba(11, 15, 26, 0.6);
  border-radius: 24px;
  border: 1px solid var(--border);
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 520px;
  box-shadow: var(--shadow);
}

.empty-state {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.empty-card {
  background: rgba(18, 26, 42, 0.8);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  text-align: center;
}

.canvas-wrap {
  position: relative;
  padding: 24px;
}

#pdf-canvas,
#fabric-canvas {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.4);
}

#pdf-canvas {
  background: #fff;
}

.hidden {
  display: none !important;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
  transition: 0.2s ease;
  text-align: center;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(148, 163, 184, 0.5);
}

.btn.tool.active {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.2), rgba(249, 115, 22, 0.2));
  border-color: rgba(34, 211, 238, 0.6);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07131e;
  border: none;
}

.btn.success {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #04150b;
  border: none;
}

.btn.danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.4);
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn input[type="file"] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 22, 0.8);
}

.modal-card {
  position: relative;
  background: var(--panel);
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 20px;
  width: min(520px, 92vw);
  box-shadow: var(--shadow);
}

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

.signature-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text);
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06121d;
  border: none;
}

#signature-pad {
  width: 100%;
  height: 200px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
}

.signature-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 12px;
}

.cache-list {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.cache-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 12px;
}

.cache-item .meta {
  font-size: 12px;
  color: var(--muted);
}

.cache-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
}

@media (max-width: 980px) {
  .content {
    grid-template-columns: 1fr;
  }
  .sidebar {
    order: 2;
  }
}
