* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f1f3f5;
  color: #1a1a1a;
  margin: 0;
}

/* ---------- App nav ---------- */

.app-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 18px 16px 0;
}

.app-nav.hidden {
  display: none;
}

.nav-tab {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 0.95em;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
}

.nav-tab:hover {
  background: #e2e8f0;
}

.nav-tab.active {
  background: #2563eb;
  color: #fff;
}

/* ---------- Upload screen ---------- */

.upload-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.upload-screen.hidden {
  display: none;
}

.upload-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 2px dashed #cbd5e1;
  border-radius: 16px;
  padding: 48px 32px;
  text-align: center;
  transition: border-color 0.15s, background-color 0.15s;
}

.upload-card.drag-over {
  border-color: #2563eb;
  background: #eff6ff;
}

.upload-icon {
  width: 40px;
  height: 40px;
  color: #2563eb;
  margin-bottom: 16px;
}

.upload-card h1 {
  font-size: 1.3em;
  margin: 0 0 8px;
}

.upload-sub {
  color: #64748b;
  font-size: 0.95em;
  margin: 0 0 24px;
  line-height: 1.4;
}

.upload-btn {
  display: inline-block;
  background: #2563eb;
  color: #fff;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
}

.upload-btn:hover {
  background: #1d4ed8;
}

.upload-hint {
  color: #94a3b8;
  font-size: 0.85em;
  margin: 16px 0 0;
}

/* ---------- Tools screen ---------- */

.tools-screen {
  min-height: 100vh;
  padding: 8px 16px 60px;
}

.tools-screen.hidden {
  display: none;
}

.tools-header {
  text-align: center;
  margin: 24px 0 32px;
}

.tools-header h1 {
  font-size: 1.5em;
  margin: 0 0 8px;
}

.tools-header p {
  color: #64748b;
  margin: 0;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.tool-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-card h3 {
  margin: 0;
  font-size: 1.05em;
}

.tool-card > p {
  margin: 0;
  color: #64748b;
  font-size: 0.85em;
  line-height: 1.4;
}

.tool-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.tool-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8em;
  color: #334155;
  font-weight: 600;
}

.tool-card input[type="file"],
.tool-card input[type="text"],
.tool-card input[type="password"],
.tool-card input[type="number"],
.tool-card select {
  font: inherit;
  font-size: 0.85em;
  padding: 7px 9px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
}

.tool-card button[type="submit"] {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
}

.tool-card button[type="submit"]:hover:not(:disabled) {
  background: #1d4ed8;
}

.tool-card button[type="submit"]:disabled {
  background: #cbd5e1;
  cursor: default;
}

.tool-status {
  font-size: 0.8em;
  color: #64748b;
  min-height: 1.2em;
}

.tool-status.error {
  color: #dc2626;
}

.tool-status.success {
  color: #16a34a;
}

/* ---------- Toolbar ---------- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.toolbar.hidden {
  display: none;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.icon-btn {
  background: #f1f5f9;
  color: #334155;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1em;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: #e2e8f0;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: #f1f5f9;
}

.file-name {
  font-size: 0.9em;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button#exportBtn {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  white-space: nowrap;
}

button#exportBtn:hover:not(:disabled) {
  background: #1d4ed8;
}

button#exportBtn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.status-text {
  color: #64748b;
  font-size: 0.85em;
  white-space: nowrap;
}

/* ---------- Viewer ---------- */

#viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 30px 16px 60px;
}

.page-container {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.12);
  border-radius: 2px;
  max-width: 100%;
}

.page-container canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.text-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.editable-line {
  position: absolute;
  white-space: pre;
  color: transparent;
  background: rgba(37, 99, 235, 0.08);
  outline: 1px dashed rgba(37, 99, 235, 0.45);
  caret-color: #000;
  cursor: text;
  line-height: 1;
  overflow: visible;
  transition: background-color 0.1s, outline-color 0.1s;
}

.editable-line:hover:not(.activated):not(:focus):not(.computed) {
  background: rgba(37, 99, 235, 0.16);
  outline: 1px dashed rgba(37, 99, 235, 0.7);
}

.editable-line.activated {
  color: #000;
  background: #fff;
  outline: 1px solid rgba(37, 99, 235, 0.5);
}

.editable-line:focus {
  color: #000;
  background: #fff;
  outline: 1px solid #2563eb;
}

.editable-line.computed {
  color: #000;
  background: rgba(22, 163, 74, 0.1);
  outline: 1px dashed rgba(22, 163, 74, 0.5);
  cursor: default;
}
