/* ═══ RESET & BASE ══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #05164D;
  --accent:  #FFAD00;
  --danger:  #F44336;
  --success: #4CAF50;
  --warning: #FF9800;
  --gray-50: #FAFAFA;
  --gray-100:#F5F5F5;
  --gray-200:#EEEEEE;
  --gray-300:#E0E0E0;
  --gray-500:#9E9E9E;
  --gray-700:#616161;
  --text:    #1A1A1A;
  --radius:  10px;
  --shadow:  0 2px 8px rgba(0,0,0,.10);
  --tab-h:   60px;
  --header-h:54px;
}

html, body { height: 100%; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background: #F0F2F8; color: var(--text); }

/* ═══ APP SHELL ════════════════════════════════════════════════════════════ */
#app { display: flex; flex-direction: column; height: 100vh; max-width: 700px; margin: 0 auto; background: #F0F2F8; position: relative; }

/* Header */
#app-header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  z-index: 10;
}
#app-title { flex: 1; font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.header-back--hidden { display: none; }
.header-back, .header-icon {
  background: transparent; border: none; color: #fff; cursor: pointer;
  font-size: 20px; padding: 6px 8px; border-radius: 6px; line-height: 1;
}
.header-back:hover, .header-icon:hover { background: rgba(255,255,255,.15); }

/* Page container */
#page-container { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 20px; }

/* Tab bar */
#tab-bar {
  height: var(--tab-h);
  background: #fff;
  border-top: 1px solid var(--gray-300);
  display: flex;
  flex-shrink: 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,.07);
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: transparent; border: none; cursor: pointer;
  font-size: 10px; color: var(--gray-500); font-family: inherit; padding: 4px 2px;
  transition: color .15s;
}
.tab-btn .tab-icon { font-size: 18px; }
.tab-btn.active { color: var(--primary); font-weight: 600; }
.tab-btn:hover { color: var(--primary); }

/* ═══ CARD ══════════════════════════════════════════════════════════════════ */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.card-header {
  padding: 12px 14px 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-body { padding: 4px 14px 14px; }
.card-body--flush { padding: 0; }

/* ═══ BUTTONS ════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: none; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600; transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { opacity: .88; }
.btn--outline { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn--outline:hover:not(:disabled) { background: rgba(5,22,77,.06); }
.btn--outline-warn { background: transparent; border: 1.5px solid var(--warning); color: var(--warning); }
.btn--outline-warn:hover:not(:disabled) { background: rgba(255,152,0,.06); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { opacity: .88; }
.btn--ghost { background: transparent; border: none; color: var(--primary); padding: 6px 10px; font-size: 13px; }
.btn--ghost:hover { background: rgba(5,22,77,.07); border-radius: 6px; }
.btn--small { padding: 5px 10px; font-size: 12px; }
.btn--block { width: 100%; margin-bottom: 8px; }
.btn--fab {
  position: fixed; bottom: calc(var(--tab-h) + 16px); right: 16px;
  width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 26px; box-shadow: 0 4px 12px rgba(0,0,0,.25); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.btn--fab:hover { opacity: .9; }

/* ═══ FORM ELEMENTS ═════════════════════════════════════════════════════════ */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-700); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 5px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray-300); border-radius: 8px;
  font-family: inherit; font-size: 14px; color: var(--text); background: #fff;
  outline: none; transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); }
.form-textarea { resize: vertical; min-height: 70px; }
.form-hint { font-size: 11px; color: var(--gray-500); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

/* Radio group */
.radio-group { display: flex; gap: 8px; }
.radio-label {
  display: flex; align-items: center; gap: 5px; cursor: pointer;
  font-size: 13px; padding: 6px 12px; border-radius: 6px; border: 1.5px solid var(--gray-300);
}
.radio-label input { display: none; }
.radio-label.selected { border-color: var(--primary); background: rgba(5,22,77,.06); color: var(--primary); font-weight: 600; }

/* Chips / multi-select */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 14px; border-radius: 20px; border: 1.5px solid var(--gray-300);
  font-size: 13px; cursor: pointer; background: #fff; transition: all .15s;
}
.chip.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.chips-group-label {
  width: 100%; font-size: 10px; font-weight: 700; color: #9E9E9E;
  text-transform: uppercase; letter-spacing: 0.6px; margin: 8px 0 2px;
}
.chips-group-label:first-child { margin-top: 0; }

/* Joint map circles – tap feedback */
.jmap-joint circle { transition: fill .12s, opacity .12s; }
.jmap-joint:active circle { opacity: 0.6; }

/* Pain list – location badges */
.entry-locations { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.entry-loc {
  font-size: 10px; font-weight: 600;
  padding: 1px 6px; border-radius: 8px; white-space: nowrap;
}
.loc--low  { background: rgba(76,175,80,0.15);  color: #2E7D32; }
.loc--mid  { background: rgba(255,152,0,0.15);  color: #E65100; }
.loc--high { background: rgba(244,67,54,0.15);  color: #C62828; }

/* Pain form – intensity buttons */
.pf-intensity-buttons { display: flex; gap: 4px; }
.pf-intensity-btn {
  flex: 1; border: none; border-radius: 8px;
  font-size: 13px; font-weight: 700; cursor: pointer;
  padding: 10px 0; min-height: 40px;
  opacity: 0.55; transition: opacity .15s, transform .1s, box-shadow .1s;
}
.pf-intensity-btn--active { opacity: 1; transform: scale(1.08); box-shadow: 0 2px 8px rgba(0,0,0,.25); }

/* Pain form – compact type chips */
.pf-chips { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.pf-type-group-label {
  font-size: 10px; font-weight: 700; color: #9E9E9E;
  text-transform: uppercase; letter-spacing: 0.6px; margin-top: 8px;
}
.pf-type-group-label:first-child { margin-top: 0; }
.pf-chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.pf-type-chip {
  display: inline-block; border: 1.5px solid #BDBDBD; border-radius: 14px;
  padding: 3px 10px; font-size: 12px; font-weight: 500;
  color: #424242; background: white; cursor: pointer; white-space: nowrap;
  transition: background .1s, color .1s, border-color .1s;
}
.pf-type-chip--active { border-color: #05164D; background: #05164D; color: white; }

/* Slider */
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--primary); }
.intensity-badge {
  min-width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff;
}
.intensity--low  { background: var(--success); }
.intensity--mid  { background: var(--warning); }
.intensity--high { background: var(--danger); }

/* Dose grid */
.dose-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.dose-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dose-cell label { font-size: 11px; font-weight: 600; color: var(--gray-700); }
.dose-input {
  width: 100%; text-align: center; padding: 8px 4px; border: 1.5px solid var(--gray-300);
  border-radius: 8px; font-size: 15px; font-weight: 700; color: var(--primary);
  font-family: inherit; background: var(--gray-50); outline: none;
}
.dose-input:focus { border-color: var(--primary); }

/* ═══ TABLES ═════════════════════════════════════════════════════════════════ */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; white-space: nowrap; }
th {
  background: var(--primary); color: #fff; padding: 8px; text-align: left;
  font-weight: 600; font-size: 11px; border-right: 1px solid rgba(255,255,255,.15);
}
th:last-child { border-right: none; }
td { padding: 8px; border-bottom: 1px solid var(--gray-200); border-right: 1px solid var(--gray-100); vertical-align: middle; }
td:last-child { border-right: none; }
tr:nth-child(even) td { background: var(--gray-50); }
tr:hover td { background: #EEF2FF; }
.td-center { text-align: center; font-weight: 600; color: var(--primary); }
.td-small { font-size: 11px; color: var(--gray-700); white-space: normal; }
.td-actions { text-align: center; white-space: nowrap; width: 44px; }
.td-rhythm { text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.med-list-hint { font-size: 12px; color: #9E9E9E; text-align: center; padding: 10px 8px 4px; margin: 0; line-height: 1.6; }

/* ═══ PAIN ENTRY CARD ═══════════════════════════════════════════════════════ */
.entry-card {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--gray-200); cursor: pointer;
}
.entry-card:last-child { border-bottom: none; }
.entry-card:hover { background: var(--gray-50); }
.entry-info { flex: 1; min-width: 0; }
.entry-date { font-size: 11px; color: var(--gray-500); margin-bottom: 2px; }
.entry-types { font-size: 14px; font-weight: 600; }
.entry-note { font-size: 12px; color: var(--gray-700); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-delete { background: transparent; border: none; cursor: pointer; color: var(--gray-500); font-size: 18px; padding: 4px; }
.entry-delete:hover { color: var(--danger); }

/* Pain-list body thumbnail */
.entry-thumb { display: flex; align-items: center; flex-shrink: 0; padding: 0 6px; }
.entry-thumb__inner { position: relative; border-radius: 5px; overflow: hidden; border: 1px solid var(--gray-200); background: #fff; }
.entry-thumb__img { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.entry-thumb__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ═══ PATIENT CARD (dark) ════════════════════════════════════════════════════ */
.patient-card { background: var(--primary); }
.patient-card .card-title { color: #fff; }
.patient-line { color: rgba(255,255,255,.9); font-size: 14px; margin: 3px 0; }
.patient-label { font-weight: 700; color: var(--accent); }

/* ═══ BODY MAP ════════════════════════════════════════════════════════════════ */
.body-map-wrap { position: relative; width: 100%; max-width: 480px; margin: 0 auto; cursor: crosshair; }
.body-map-wrap.readonly { cursor: default; }
.body-map-wrap img { display: block; width: 100%; height: auto; pointer-events: none; border-radius: 8px; }
.body-map-wrap svg.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.body-map-wrap.readonly svg.overlay { pointer-events: none; }
.marker-g { pointer-events: all; cursor: pointer; }
.body-map-labels { display: flex; justify-content: space-around; margin-top: 6px; }
.body-map-label { font-size: 11px; font-weight: 600; color: var(--primary); }
.body-map-hint { font-size: 12px; color: var(--gray-500); text-align: center; margin-top: 6px; }

/* Side-by-side half-views (pain form) */
.body-map-stack { display: flex; flex-direction: row; gap: 8px; width: 100%; }
.body-map-half-wrap { flex: 1; min-width: 0; }
.body-map-wrap-half { position: relative; border-radius: 8px; cursor: crosshair; }
.body-map-half-img { display: block; width: 100%; aspect-ratio: 3/4; object-fit: cover; object-position: 0 0; pointer-events: none; }
.body-map-half-img--back { object-position: 100% 0; }
.body-map-wrap-half svg.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ═══ DIAGNOSIS LIST ═══════════════════════════════════════════════════════ */
.diag-item { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--gray-200); }
.diag-item:last-child { border-bottom: none; }
.diag-text { flex: 1; font-size: 14px; }
.diag-edit-row { display: flex; gap: 8px; flex: 1; }

/* ═══ EMPTY STATE ════════════════════════════════════════════════════════════ */
.empty { text-align: center; color: var(--gray-500); padding: 40px 20px; font-size: 14px; line-height: 1.8; }

/* ═══ MODAL ══════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box { background: #fff; border-radius: 14px; padding: 24px; max-width: 400px; width: 100%; max-height: 85vh; overflow-y: auto; }
.modal-box p { font-size: 14px; line-height: 1.6; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

/* ═══ TOAST ══════════════════════════════════════════════════════════════════ */
.toast {
  position: fixed; bottom: calc(var(--tab-h) + 20px); left: 50%; transform: translateX(-50%);
  background: #323232; color: #fff; border-radius: 8px; padding: 10px 20px;
  font-size: 14px; z-index: 200; white-space: nowrap; box-shadow: 0 4px 12px rgba(0,0,0,.3);
  transition: opacity .3s;
}
.toast.hidden { display: none; }

/* ═══ SPINNER ════════════════════════════════════════════════════════════════ */
.spinner-wrap { display: flex; justify-content: center; padding: 40px; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--gray-200);
  border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ NOTE / WARNING ═══════════════════════════════════════════════════════ */
.note { font-size: 13px; color: var(--gray-700); line-height: 1.6; }
.note--warn { color: #B45309; background: #FEF3C7; border-radius: 6px; padding: 8px 12px; }

/* ═══ RANGE LABELS ═══════════════════════════════════════════════════════════ */
.range-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--gray-500); margin-top: 2px; }

/* ═══ EXPORT ════════════════════════════════════════════════════════════════ */
.profile-row { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; }
.profile-label { font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .4px; }
.range-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.range-dates { font-size: 12px; color: var(--gray-500); }

/* ═══ UTILITIES ══════════════════════════════════════════════════════════════ */
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.error-msg { color: var(--danger); font-size: 13px; text-align: center; margin-top: 8px; }
.version-line { text-align: center; font-size: 12px; color: var(--gray-500); margin-top: 24px; }

/* ═══ INFO PAGE ═══════════════════════════════════════════════════════════ */
.info-hero { text-align: center; padding: 28px 16px 16px; }
.info-logo { width: 72px; height: 72px; border-radius: 18px; background: var(--primary); color: #fff; font-size: 36px; font-weight: 800; line-height: 72px; margin: 0 auto 12px; }
.info-app-name { font-size: 24px; font-weight: 700; color: var(--primary); margin: 0 0 4px; }
.info-version { font-size: 13px; color: var(--gray-500); margin: 0 0 12px; }
.info-description { font-size: 14px; color: #424242; line-height: 1.5; margin: 0; }
.info-publisher-name { font-size: 14px; font-weight: 600; color: var(--text); margin: 0 0 2px; }
.info-publisher-addr { font-size: 12px; color: var(--gray-500); margin: 0; }
.info-privacy-row { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.info-privacy-row p { font-size: 13px; color: #424242; line-height: 1.5; margin: 0; flex: 1; }
.info-privacy-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.info-privacy-icon--green { filter: hue-rotate(80deg); }
.info-privacy-icon--neutral { opacity: 0.5; }
.info-disclaimer { font-size: 13px; color: var(--gray-500); line-height: 1.5; margin: 0; font-style: italic; }
.info-tech { font-size: 13px; color: var(--gray-500); margin: 0; }
.info-footer { text-align: center; font-size: 12px; color: #BDBDBD; margin: 16px 0 32px; }
.lang-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lang-btn { flex:1; min-width:72px; padding:7px 8px; border-radius:20px; border:2px solid var(--primary); background:transparent; color:var(--primary); font-size:13px; font-weight:500; cursor:pointer; text-align:center; }
.lang-btn--active { background:var(--primary); color:#fff; }
input[type=file].hidden-file { display: none; }

.doc-detail-field { display:flex; gap:8px; font-size:0.9rem; padding:3px 0; }
.doc-detail-field strong { color:#888; flex-shrink:0; min-width:110px; font-weight:600; }
.doc-detail-text { font-size:0.9rem; line-height:1.55; white-space:pre-wrap; margin:0; }
