:root {
  --bg: #eef2f7;
  --bg-soft: #f8fafc;
  --panel: #ffffff;
  --panel-strong: #f3f8ff;
  --line: #cfd9e8;
  --line-strong: #9fb3d4;
  --text: #16253d;
  --muted: #5f718e;
  --primary: #0e7490;
  --primary-2: #2563eb;
  --danger: #dc2626;
  --ok: #0f766e;
  --shadow: 0 18px 48px rgba(18, 40, 79, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Sora", "Poppins", "Noto Sans", sans-serif;
  background:
    radial-gradient(circle at 8% 0%, #ffffff 0%, transparent 42%),
    radial-gradient(circle at 92% 20%, #dff4ff 0%, transparent 28%),
    linear-gradient(140deg, #f4f7fb, #ebf2fb 56%, #e9eff8);
}

.app-shell {
  width: 100%;
  min-height: 100vh;
}

.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
}

.screen.is-active {
  display: block;
}

.upload-screen {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 36px 18px;
}

.upload-screen.is-active {
  display: flex;
}

.upload-card {
  width: min(740px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.96), rgba(245, 250, 255, 0.95)),
    repeating-linear-gradient(
      -45deg,
      rgba(224, 234, 248, 0.22) 0,
      rgba(224, 234, 248, 0.22) 8px,
      transparent 8px,
      transparent 24px
    );
  box-shadow: var(--shadow);
}

.upload-card h1 {
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 3.1vw, 2.4rem);
  line-height: 1.1;
  letter-spacing: 0.2px;
}

.upload-card p {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 1.02rem;
}

.upload-form {
  display: grid;
  gap: 12px;
}

.upload-form label {
  font-size: 0.95rem;
  font-weight: 600;
  color: #253956;
}

.file-label {
  width: fit-content;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid #b5cde8;
  background: #e9f4ff;
  color: #1e4f80;
}

input[type="file"],
input[type="text"],
input[type="password"] {
  width: 100%;
  border-radius: 12px;
  font-size: 0.98rem;
  color: var(--text);
  background: #fff;
}

input[type="file"] {
  border: 1px dashed var(--line-strong);
  padding: 12px;
}

input[type="text"],
input[type="password"] {
  border: 1px solid var(--line);
  padding: 11px 13px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: #3e7ad5;
  box-shadow: 0 0 0 3px rgba(62, 122, 213, 0.16);
}

.primary-btn,
#upload-btn,
#login-btn {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  width: fit-content;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.2px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
}

.primary-btn:disabled,
#upload-btn:disabled,
#login-btn:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.status-line {
  min-height: 22px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.page-top-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.process-screen {
  padding: 14px;
}

.ocr-status-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(160deg, #ffffff, #f4f8ff);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.ocr-status-card.is-error {
  border-color: #f0b2b2;
  background: linear-gradient(160deg, #fff9f9, #fff2f2);
}

.ocr-status-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.ocr-status-title {
  font-size: 1.03rem;
  font-weight: 700;
}

.ocr-status-message {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.93rem;
}

.ocr-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 12px;
  background: #e8f4ff;
  color: #1f4b7e;
  font-size: 0.82rem;
  font-weight: 700;
}

.ocr-status-badge.is-error {
  background: #ffe7e7;
  color: #9f1f1f;
}

.ocr-progress-wrap {
  width: 100%;
  height: 10px;
  margin-top: 11px;
  border-radius: 999px;
  overflow: hidden;
  background: #dbe7f7;
}

.ocr-progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #2563eb);
  transition: width 0.35s ease;
}

.ocr-progress-text {
  margin-top: 7px;
  color: #41536f;
  font-size: 0.85rem;
  font-weight: 600;
}

.ocr-status-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

#btn-retry-status {
  display: none;
}

.ocr-log-list {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
  max-height: 120px;
  overflow: auto;
}

.ocr-log-item {
  padding: 8px 10px;
  font-size: 0.84rem;
  color: #3d5170;
  border-bottom: 1px solid #e4ecf8;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.ocr-log-item:last-child {
  border-bottom: none;
}

.toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.ghost-btn,
.primary-link {
  border-radius: 11px;
  padding: 9px 14px;
  text-decoration: none;
  font-weight: 650;
}

.ghost-btn {
  border: 1px solid var(--line-strong);
  color: #183052;
  background: linear-gradient(180deg, #ffffff, #eef4fc);
  cursor: pointer;
}

.ghost-btn:hover {
  border-color: #87a7d3;
}

.primary-link {
  color: #fff;
  background: linear-gradient(135deg, #0f766e, #0284c7);
}

.session-info {
  color: var(--muted);
  font-size: 0.94rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 230px minmax(520px, 1fr) minmax(420px, 560px);
  gap: 12px;
  height: calc(100vh - 90px);
}

.thumbnail-pane,
.image-pane,
.table-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.thumbnail-pane h2,
.image-pane h2,
.table-pane h2 {
  margin: 0;
  padding: 12px 14px;
  font-size: 0.98rem;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(120deg, #f7fbff, #eef5ff);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(120deg, #f7fbff, #eef5ff);
}

.pane-head h2 {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.zoom-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zoom-level {
  min-width: 56px;
  text-align: center;
  font-size: 0.84rem;
  color: #385072;
  font-weight: 700;
}

.zoom-btn {
  padding: 6px 10px;
  min-width: 36px;
}

.thumbnail-list {
  height: calc(100% - 48px);
  padding: 10px;
  display: grid;
  gap: 10px;
  overflow: auto;
}

.thumb-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.thumb-item:hover {
  transform: translateY(-1px);
  border-color: #7ea6d8;
}

.thumb-item.active {
  border-color: #2d66d0;
  box-shadow: 0 0 0 2px rgba(45, 102, 208, 0.2);
}

.thumb-item img {
  width: 100%;
  height: 95px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.thumb-item .meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.image-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.image-wrap {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
  cursor: grab;
  background:
    linear-gradient(180deg, rgba(227, 236, 249, 0.55), rgba(240, 245, 252, 0.8)),
    repeating-linear-gradient(
      0deg,
      rgba(165, 182, 212, 0.08) 0,
      rgba(165, 182, 212, 0.08) 1px,
      transparent 1px,
      transparent 28px
    );
}

.image-wrap.is-panning {
  cursor: grabbing;
  user-select: none;
}

.image-stage {
  position: relative;
  display: none;
  flex: 0 0 auto;
}

.image-empty {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  padding: 10px 14px;
  border: 1px dashed #9db2d4;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  color: #41536f;
  font-size: 0.9rem;
  text-align: center;
}

#annotated-image {
  display: block;
  max-width: none;
  max-height: none;
  border: 1px solid #b7c8e0;
  border-radius: 8px;
}

.bbox-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bbox-item {
  position: absolute;
  border: 2px solid rgba(37, 99, 235, 0.75);
  background: rgba(37, 99, 235, 0.08);
  border-radius: 6px;
  pointer-events: auto;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.bbox-item.active {
  border-color: var(--danger);
  background: rgba(220, 38, 38, 0.09);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
  animation: pulse 0.85s ease-in-out infinite alternate;
}

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.014);
  }
}

.table-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.91rem;
}

th,
td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  vertical-align: top;
}

th {
  top: 0;
  position: sticky;
  z-index: 1;
  background: #eef5ff;
}

tr.active-row {
  background: #fff4ee;
}

td[contenteditable="true"] {
  min-width: 150px;
  background: #fffdf4;
}

.empty-block {
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  background: #f9fcff;
}

.empty-cell {
  padding: 18px 10px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 190px 1fr 410px;
  }
}

@media (max-width: 1040px) {
  .toolbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .session-info {
    white-space: normal;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .pane-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .thumbnail-pane,
  .image-pane,
  .table-pane {
    min-height: 300px;
  }
}
