:root {
  --primary: #1F4E79;
  --primary-dark: #163b5c;
  --accent: #4a90e2;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #222;
  --muted: #777;
  --high: #d33;
  --medium: #e98a14;
  --low: #4a90e2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  background: var(--primary);
  color: white;
  padding: 1rem 1rem 0;
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: calc(1rem + env(safe-area-inset-top));
}

header h1 {
  margin: 0 0 0.75rem;
  font-size: 1.4rem;
  font-weight: 600;
}

.tab {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  padding: 0.6rem 1rem;
  font-size: 1rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.tab.active {
  color: white;
  border-bottom-color: white;
  font-weight: 600;
}

main {
  padding: 1rem;
}

.view { display: none; }
.view.active { display: block; }

.primary-btn, .secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1.2rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

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

.primary-btn:hover:not(:disabled) { background: var(--primary-dark); }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { background: #aaa; cursor: not-allowed; }

.secondary-btn {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--primary);
}

.secondary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.capture-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.capture-actions .primary-btn { flex: 1; min-width: 200px; }

#file-input { display: none; }

.preview-zone {
  background: var(--surface);
  border-radius: 12px;
  min-height: 240px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-zone.empty { color: var(--muted); }

.preview-zone img,
.preview-zone canvas {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 8px;
}

.crop-controls.hidden { display: none; }
.crop-controls {
  background: #fff7e6;
  border-left: 4px solid var(--medium);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.hint { color: var(--muted); text-align: center; }

.status {
  margin-top: 1rem;
  font-size: 0.95rem;
  text-align: center;
  min-height: 1.4em;
}

.status.ok    { color: #2a7d2a; }
.status.error { color: var(--high); }

.counters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.counter {
  background: var(--surface);
  border-radius: 10px;
  padding: 1rem 0.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  box-shadow: var(--shadow);
}

.counter span {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.counter.high   span { color: var(--high); }
.counter.medium span { color: var(--medium); }
.counter.low    span { color: var(--low); }

.alert-list { display: flex; flex-direction: column; gap: 0.5rem; }

.alert-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--low);
}

.alert-card.high   { border-left-color: var(--high); }
.alert-card.medium { border-left-color: var(--medium); }

.alert-card h3 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
  font-weight: 600;
}

.alert-card p {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: #444;
  line-height: 1.4;
}

.alert-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.alert-actions button {
  flex: 1;
  min-width: 80px;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: var(--surface);
  cursor: pointer;
}

.alert-actions button:hover { background: #f0f0f0; }

/* P5b — Adobe-Scan-like polish */

.scan-status {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #fff7e6;
  border-left: 3px solid var(--medium);
  border-radius: 4px;
}

.scan-status.ready {
  background: #e8f5e8;
  border-left-color: #2a7d2a;
  color: #2a7d2a;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(0, 0, 0, 0.6);
  color: white;
}

.badge-scanned {
  background: #2a7d2a;
}

/* P6.4 — Login + logout */

.logout-btn {
  margin-left: auto;
  font-size: 1.2rem;
  padding: 0.4rem 0.8rem;
}

.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 380px;
  margin: 2rem auto;
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin: 0 0 0.3rem;
  color: var(--primary);
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-card input {
  font-size: 1rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.login-card input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.login-card .primary-btn {
  margin-top: 0.5rem;
}
