:root {
  --navy: #16233d;
  --blue: #2f7fd8;
  --blue-dark: #1b63c4;
  --blue-darker: #14509e;
  --blue-bar: #cfe7fb;
  --blue-panel: #dceefc;
  --blue-panel-2: #c8e2f7;
  --blue-step: #bcdbf5;
  --bg-top: #e3f2fc;
  --bg-bottom: #cfe4f8;
  --red: #e6484f;
  --red-bg: #fdeceb;
  --orange: #f2994a;
  --green: #27ae60;
  --text: #16233d;
  --muted: #5c6b85;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Poppins', 'Segoe UI', sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
  min-height: 100vh;
}

a { text-decoration: none; color: inherit; }

.app-shell {
  min-height: 100vh;
  background: linear-gradient(180deg, #eef8ff, #dcedfb);
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: var(--blue-bar);
  border-bottom: 2px solid rgba(22, 35, 61, .08);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 22px;
  color: var(--blue-darker);
}

.brand i { color: var(--blue); }

.navtabs {
  display: flex;
  gap: 6px;
  background: rgba(255,255,255,.5);
  padding: 6px;
  border-radius: 20px;
}

.navtabs a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--navy);
}

.navtabs a.active {
  background: #fff;
  color: var(--blue-darker);
  box-shadow: 0 2px 8px rgba(20,50,100,.15);
}

.user-menu {
  position: relative;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 2px solid var(--blue-darker);
  border-radius: 20px;
  padding: 6px 14px 6px 6px;
  font-weight: 700;
  color: var(--blue-darker);
  cursor: pointer;
  font-size: 14px;
}

.user-chip .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--blue-darker);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}

.user-dropdown {
  position: absolute;
  right: 0;
  top: 42px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20,40,80,.2);
  min-width: 160px;
  overflow: hidden;
  display: none;
  z-index: 20;
}

.user-menu.open .user-dropdown { display: block; }

.user-dropdown a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--navy);
}

.user-dropdown a:hover { background: var(--blue-panel); }

.profile-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid var(--blue-darker);
  display: flex; align-items: center; justify-content: center;
  color: var(--blue-darker);
  background: #fff;
  font-size: 16px;
}

/* ---------- Flash messages ---------- */
.flash-wrap { padding: 12px 24px 0; }
.flash {
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}
.flash-error { background: var(--red-bg); color: var(--red); border: 1px solid #f6c6c6; }
.flash-success { background: #e6f7ec; color: var(--green); border: 1px solid #bfe9cf; }

/* ---------- Auth pages ---------- */
.auth-wrap {
  padding: 40px 20px 32px;
  text-align: center;
}

.auth-card {
  max-width: 340px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--blue-panel), var(--blue-panel-2));
  border-radius: 22px;
  padding: 26px 24px 20px;
  text-align: left;
}

.auth-card h2 {
  text-align: center;
  margin: 0 0 18px;
  font-size: 20px;
  color: var(--navy);
}

.input-icon {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 22px;
  padding: 10px 16px;
  margin-bottom: 12px;
}

.input-icon i { color: var(--muted); width: 16px; text-align: center; }

.input-icon input {
  border: none;
  outline: none;
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  background: transparent;
}

.input-icon .toggle-eye { cursor: pointer; color: var(--muted); }

.btn-primary {
  width: 100%;
  border: none;
  border-radius: 24px;
  padding: 12px;
  background: linear-gradient(90deg, #3f92f2, var(--blue-darker));
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  margin-top: 4px;
}

.btn-primary:hover { filter: brightness(1.05); }

.auth-links {
  text-align: center;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--navy);
}

.auth-links a { color: var(--blue-darker); font-weight: 700; }
.auth-links div { margin-top: 4px; }

.tagline {
  margin-top: 18px;
  font-size: 13px;
  color: var(--navy);
}

/* ---------- Home page ---------- */
.home-wrap { padding: 20px 24px 28px; }

.welcome-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--blue-panel);
  border-radius: 16px;
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 18px;
}

.welcome-bar span i { color: var(--green); margin-right: 6px; }

.logout-mini {
  display: flex; align-items: center; gap: 6px;
  color: var(--blue-darker);
  font-weight: 700;
  font-size: 13px;
}

.quick-scan {
  background: linear-gradient(135deg, #3f92f2, var(--blue-darker));
  color: #fff;
  border-radius: 20px;
  padding: 26px 24px;
  text-align: center;
  margin-bottom: 20px;
}

.quick-scan h2 {
  margin: 0 0 10px;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}

.quick-scan p { margin: 0 0 16px; font-size: 14px; opacity: .95; }

.btn-white {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: var(--blue-darker);
  border: none;
  border-radius: 20px;
  padding: 10px 20px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}

.steps-wrap {
  background: var(--blue-panel);
  border-radius: 20px;
  padding: 22px;
  text-align: center;
  margin-bottom: 20px;
}

.steps-wrap h3 { margin: 0 0 16px; color: var(--navy); }

.steps {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.step {
  background: var(--blue-step);
  border-radius: 14px;
  padding: 16px 22px;
  font-weight: 700;
  color: var(--navy);
  min-width: 90px;
}

.step i { display: block; font-size: 20px; margin-bottom: 8px; color: var(--blue-darker); }

.btn-scan-full {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(90deg, #3f92f2, var(--blue-darker));
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 16px;
  width: 100%;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
}

/* ---------- Scan page: kamera realtime full-screen ---------- */
.camera-view {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #000;
  overflow: hidden;
}

#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(0,0,0,.55), rgba(0,0,0,0));
}

.cam-icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.16);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.cam-title {
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex; align-items: center; gap: 8px;
}

.camera-alert {
  position: absolute;
  top: 70px; left: 16px; right: 16px;
  z-index: 3;
  background: #fff7e6;
  border: 1px solid #ffe1a8;
  color: #8a6100;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 12.5px;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.guide-box {
  position: relative;
  width: min(72vw, 340px);
  aspect-ratio: 1 / 1;
  border: 2px solid rgba(47, 127, 216, .85);
  border-radius: 20px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .45);
  animation: guide-pulse 2.2s ease-in-out infinite;
}

@keyframes guide-pulse {
  0%, 100% { border-color: rgba(47, 127, 216, .85); }
  50% { border-color: rgba(110, 231, 183, .95); }
}

.guide-label {
  position: absolute;
  top: -34px; left: 0;
  background: var(--blue-darker);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 8px;
  white-space: nowrap;
}

.corner {
  position: absolute;
  width: 22px; height: 22px;
  border: 3px solid #6ee7b7;
}
.corner.tl { top: -3px; left: -3px; border-right: none; border-bottom: none; border-top-left-radius: 10px; }
.corner.tr { top: -3px; right: -3px; border-left: none; border-bottom: none; border-top-right-radius: 10px; }
.corner.bl { bottom: -3px; left: -3px; border-right: none; border-top: none; border-bottom-left-radius: 10px; }
.corner.br { bottom: -3px; right: -3px; border-left: none; border-top: none; border-bottom-right-radius: 10px; }

.camera-hint {
  position: absolute;
  left: 16px; right: 16px;
  bottom: 130px;
  z-index: 3;
  text-align: center;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.camera-hint-error { color: #ffb4b4; }

.camera-bottom-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  padding: 26px 0 34px;
  background: linear-gradient(0deg, rgba(0,0,0,.6), rgba(0,0,0,0));
}

.capture-btn {
  width: 76px; height: 76px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  border: 4px solid #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.capture-btn:disabled { opacity: .4; cursor: not-allowed; }
.capture-btn-inner {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #fff;
  display: block;
}
.capture-btn:active .capture-btn-inner { background: var(--blue); }

.camera-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: rgba(0,0,0,.55);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 600;
}
.camera-loading i { font-size: 30px; }

/* ---------- Scan page: menunggu gambar dari koper DermaSense (IoT) ---------- */
.waiting-center {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 32px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #1b2b4a, #05070d 78%);
}

.waiting-pulse {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: rgba(47, 127, 216, .18);
  border: 2px solid rgba(47, 127, 216, .6);
  display: flex; align-items: center; justify-content: center;
  color: #6ee7b7;
  font-size: 32px;
  animation: waiting-pulse-ring 1.8s ease-in-out infinite;
}

@keyframes waiting-pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(110, 231, 183, .45); }
  70% { box-shadow: 0 0 0 22px rgba(110, 231, 183, 0); }
  100% { box-shadow: 0 0 0 0 rgba(110, 231, 183, 0); }
}

.waiting-title {
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}

.waiting-sub {
  color: #b9c6dd;
  font-size: 13.5px;
  max-width: 320px;
  line-height: 1.5;
}
.waiting-sub.camera-hint-error { color: #ffb4b4; }

/* ---------- Scan page: hasil deteksi ---------- */
.scan-wrap { padding: 20px 24px 28px; }

.scan-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 18px;
  margin-top: 4px;
}

@media (max-width: 720px) {
  .scan-grid { grid-template-columns: 1fr; }
}

.result-card, .chart-card {
  background: var(--blue-panel);
  border-radius: 20px;
  padding: 18px;
}

.result-card h4, .chart-card h4 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--navy);
}

.result-img {
  width: 100%;
  border-radius: 14px;
  border: 3px solid var(--blue-darker);
  object-fit: cover;
  max-height: 260px;
}

.diagnosis-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

.diagnosis-name { font-weight: 700; font-size: 17px; color: var(--blue-darker); }

.risk-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 700;
}

.risk-tinggi { background: var(--red-bg); color: var(--red); }
.risk-sedang { background: #fff2e2; color: var(--orange); }
.risk-rendah { background: #e6f7ec; color: var(--green); }

.confidence-ring {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--blue-darker);
  background: conic-gradient(var(--blue-darker) calc(var(--pct) * 1%), #dceefc 0);
  position: relative;
}

.confidence-ring::before {
  content: '';
  position: absolute;
  width: 48px; height: 48px;
  background: #fff;
  border-radius: 50%;
}

.confidence-ring span { position: relative; z-index: 1; }

.action-alert {
  margin-top: 14px;
  background: var(--red-bg);
  color: var(--red);
  font-weight: 700;
  text-align: center;
  border-radius: 14px;
  padding: 10px;
  font-size: 13px;
}

.recent-list { margin-top: 16px; }

.recent-list h5 {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--navy);
  margin: 0 0 8px;
}

.recent-list h5 a { color: var(--blue-darker); font-weight: 700; }

.recent-item {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(22,35,61,.08);
}

.recent-item .name { font-weight: 700; color: var(--navy); }
.recent-item .date { color: var(--muted); }

/* ---------- Riwayat page ---------- */
.riwayat-wrap { padding: 20px 24px 28px; }

.riwayat-card {
  background: var(--blue-panel);
  border-radius: 18px;
  overflow: hidden;
}

.riwayat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 6px;
}

.riwayat-head h3 { margin: 0; color: var(--navy); }

.btn-outline {
  border: 2px solid var(--blue-darker);
  color: var(--blue-darker);
  background: #fff;
  border-radius: 16px;
  padding: 6px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

table.riwayat-table { width: 100%; border-collapse: collapse; }

table.riwayat-table thead th {
  background: var(--blue-darker);
  color: #fff;
  text-align: left;
  padding: 10px 16px;
  font-size: 13px;
}

table.riwayat-table tbody td {
  padding: 10px 16px;
  font-size: 13px;
  border-bottom: 1px solid rgba(22,35,61,.08);
  vertical-align: middle;
}

.thumb {
  width: 40px; height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--blue-darker);
}

.row-actions a, .row-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 15px;
  margin-right: 10px;
}

.row-actions .view { color: var(--blue-darker); }
.row-actions .del { color: var(--red); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

@media print {
  .navtabs, .topbar .user-menu, .btn-outline, .row-actions { display: none !important; }
  body { background: #fff; }
  .app-shell { border: none; box-shadow: none; margin: 0; }
}
