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

:root {
  --primary: #1a3a5c;
  --primary-light: #2a5a8c;
  --accent: #e8751a;
  --success: #2e7d32;
  --danger: #c62828;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────── */
.app-header {
  background: var(--primary);
  color: white;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.app-header h1 {
  font-size: 17px;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header .subtitle {
  font-size: 11px;
  opacity: 0.75;
}

.header-logo {
  width: 38px;
  height: 38px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 16px;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Nav Tabs ────────────────────────────────────────────────── */
.nav-tabs {
  display: flex;
  background: var(--primary);
  border-top: 1px solid rgba(255,255,255,0.1);
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  flex: 1;
  min-width: 80px;
  padding: 10px 8px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.65);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav-tab .icon { font-size: 20px; }
.nav-tab.active { color: white; border-bottom: 3px solid var(--accent); }
.nav-tab:hover { color: white; }

/* ── Main Layout ─────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.card-header {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 16px; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { resize: vertical; min-height: 100px; }

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── Yes/No Toggle ───────────────────────────────────────────── */
.yn-group {
  background: #f8f9fa;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.yn-question {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.yn-buttons {
  display: flex;
  gap: 8px;
}

.yn-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.yn-btn.yes.active { background: var(--success); color: white; border-color: var(--success); }
.yn-btn.no.active { background: var(--danger); color: white; border-color: var(--danger); }
.yn-btn:not(.active):hover { border-color: var(--primary); }

.yn-detail {
  margin-top: 10px;
  display: none;
}
.yn-detail.visible { display: block; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { filter: brightness(1.1); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: 8px; }
.btn-full { width: 100%; }

/* ── Login Page ──────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #2d6a9f 100%);
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-box {
  width: 72px;
  height: 72px;
  background: var(--primary);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
}

.login-logo h2 { font-size: 20px; color: var(--primary); }
.login-logo p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.error-msg {
  background: #ffebee;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}

/* ── Photo Upload ────────────────────────────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #eee;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-thumb .remove-photo {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
}
.upload-area:hover { border-color: var(--primary); color: var(--primary); }
.upload-area .upload-icon { font-size: 32px; display: block; margin-bottom: 6px; }

/* ── Signature Canvas ────────────────────────────────────────── */
.sig-container {
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: white;
  position: relative;
}

.sig-container canvas {
  display: block;
  width: 100%;
  touch-action: none;
  cursor: crosshair;
}

.sig-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f8f9fa;
  border-top: 1px solid var(--border);
}

.sig-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Protocol List ───────────────────────────────────────────── */
.protocol-item {
  background: white;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: transform 0.1s;
}

.protocol-item:hover { transform: translateX(2px); }
.protocol-item:active { transform: scale(0.99); }

.protocol-icon {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  flex-shrink: 0;
}

.protocol-info { flex: 1; min-width: 0; }
.protocol-title { font-weight: 700; font-size: 15px; }
.protocol-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.protocol-actions { display: flex; gap: 6px; flex-shrink: 0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge-success { background: #e8f5e9; color: var(--success); }
.badge-danger { background: #ffebee; color: var(--danger); }

/* ── Admin Panel ─────────────────────────────────────────────── */
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-avatar {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: 14px; }
.user-email { font-size: 12px; color: var(--text-muted); }
.role-badge {
  padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 700;
}
.role-admin { background: #e3f2fd; color: #1565c0; }
.role-user { background: #f3e5f5; color: #6a1b9a; }
.role-readonly { background: #f5f5f5; color: #555; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; align-items: center; }

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 18px; color: var(--primary); }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 600;
  z-index: 9999;
  transition: transform 0.3s;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Loading ─────────────────────────────────────────────────── */
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.8);
  z-index: 999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
.loading-overlay.show { display: flex; }

/* ── Utility ─────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); font-size: 13px; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

@media (max-width: 400px) {
  .row-2 { grid-template-columns: 1fr; }
  .login-card { padding: 28px 20px; }
}

/* ── Detail View ─────────────────────────────────────────────── */
.detail-section { margin-bottom: 20px; }
.detail-section h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary);
}
.detail-row {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}
.detail-label { color: var(--text-muted); min-width: 180px; flex-shrink: 0; }
.detail-value { font-weight: 500; word-break: break-word; }
.detail-yn { font-weight: 700; }
.detail-yn.yes { color: var(--success); }
.detail-yn.no { color: var(--danger); }
