/* ============================================================
   E-Sign System — main.css
   All components use CSS custom properties defined in :root
   ============================================================ */

:root {
  --color-bg:            #0f1117;
  --color-surface:       #1a1d27;
  --color-border:        #2a2d3e;
  --color-primary:       #4f8ef7;
  --color-primary-hover: #3a7ae0;
  --color-text:          #e2e4f0;
  --color-text-muted:    #7a7f9a;
  --color-success:       #34d399;
  --color-error:         #f87171;
  --color-warning:       #fbbf24;
  --font-main:           'DM Sans', system-ui, sans-serif;
  --font-sig:            'Dancing Script', cursive;
  --radius:              8px;
  --shadow:              0 4px 24px rgba(0,0,0,0.4);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

img { max-width: 100%; display: block; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ── Typography ────────────────────────────────────────────── */
h1 { font-size: 1.8rem; font-weight: 600; margin-bottom: 0.5rem; }
h2 { font-size: 1.4rem; font-weight: 600; margin-bottom: 0.5rem; }
h3 { font-size: 1.1rem; font-weight: 500; margin-bottom: 0.4rem; }
p  { color: var(--color-text-muted); margin-bottom: 0.75rem; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 0.3rem;
}

/* ── Inputs ────────────────────────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 0.95rem;
  padding: 0.6rem 0.85rem;
  transition: border-color 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--color-primary);
}
input::placeholder { color: var(--color-text-muted); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}
.btn--primary:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn--danger {
  background: var(--color-error);
  color: #fff;
}
.btn--danger:hover:not(:disabled) { filter: brightness(0.88); }

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--color-surface);
  color: var(--color-text);
}
.btn--ghost.active {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ── Container ──────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar__logo {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-right: auto;
}

.sign-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  font-weight: 500;
}

/* ── Login / Sign card ──────────────────────────────────────── */
.login-card,
.sign-card {
  max-width: 400px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-card h1 { text-align: center; margin-bottom: 0.25rem; }
.sign-card h2  { text-align: center; }

/* ── Table ──────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.table th {
  text-align: left;
  padding: 0.75rem 0.9rem;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:nth-child(even) td { background: rgba(255,255,255,0.025); }
.table .actions-cell { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ── Badge / Status Pills ───────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge--pending   { background: rgba(251,191,36,0.15); color: var(--color-warning); }
.badge--baking    { background: rgba(79,142,247,0.15); color: var(--color-primary);
                    animation: pulse 1.4s ease-in-out infinite; }
.badge--completed { background: rgba(52,211,153,0.15); color: var(--color-success); }
.badge--bake_failed { background: rgba(248,113,113,0.15); color: var(--color-error); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* ── Spinner ────────────────────────────────────────────────── */
.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}
.toast {
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  max-width: 340px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast--info    { background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text); }
.toast--success { background: rgba(52,211,153,0.15); border: 1px solid rgba(52,211,153,0.3); color: var(--color-success); }
.toast--error   { background: rgba(248,113,113,0.15); border: 1px solid rgba(248,113,113,0.3); color: var(--color-error); }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) * 1.5);
  padding: 2rem;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal h2 { margin-bottom: 0; }
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

/* ── Drop zone ──────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--color-primary);
  background: rgba(79,142,247,0.05);
}
.drop-zone label { color: var(--color-primary); cursor: pointer; font-weight: 500; }
.drop-zone p { margin: 0; color: var(--color-text-muted); font-size: 0.9rem; }

/* ── Progress bar ───────────────────────────────────────────── */
progress {
  width: 100%;
  height: 6px;
  border: none;
  border-radius: 99px;
  overflow: hidden;
  background: var(--color-border);
}
progress::-webkit-progress-bar  { background: var(--color-border); }
progress::-webkit-progress-value{ background: var(--color-primary); }
progress::-moz-progress-bar     { background: var(--color-primary); }

#upload-status-text { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.4rem; }

/* ── Signer rows ────────────────────────────────────────────── */
.signer-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-bottom: 0.5rem;
}
.signer-row input { flex: 1; }
.signer-row .btn  { flex-shrink: 0; }

/* ── Signing page ───────────────────────────────────────────── */
#signature-panel {
  max-width: 640px;
  margin: 1.25rem auto;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.sig-name-options { display: flex; gap: 0.5rem; }

.sig-preview {
  font-family: var(--font-sig);
  font-size: 2rem;
  color: #1e1e78;
  min-height: 2.5rem;
  padding: 0.25rem 0.5rem;
  border-bottom: 2px solid var(--color-border);
  letter-spacing: 0.02em;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
}

.hint { font-size: 0.82rem; color: var(--color-text-muted); margin: 0; }

/* ── Pages container ────────────────────────────────────────── */
#pages-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
  user-select: none;
}

.page-wrapper {
  position: relative;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.page-img { width: 100%; display: block; }

/* ── Draggable signature ────────────────────────────────────── */
#draggable-sig {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  background: rgba(255,255,255,0.92);
  border: 2px solid var(--color-primary);
  border-radius: 6px;
  padding: 0.3rem 0.65rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  transform: translate(-50%, -100%);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
#draggable-sig[hidden] { display: none; }

#draggable-sig-text {
  font-family: var(--font-sig);
  font-size: 1.6rem;
  color: #1e1e78;
  white-space: nowrap;
}

#draggable-sig .btn {
  pointer-events: auto;
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  .topbar { padding: 0.75rem 1rem; }
  .modal  { padding: 1.5rem; }
  .table-wrapper { font-size: 0.8rem; }
}
