:root {
  --primary: #6A6DB0;
  --primary-dark: #131767;
  --primary-light: #A69ED6;
  --success: #24BE62;
  --success-dark: #148441;
  --black: #313131;
  --muted: #757575;
  --hint: #B3B3B3;
  --grey: #E9E9E9;
  --grey-light: #D9D9D9;
  --bg: #F5F5F5;
  --white: #ffffff;
  --danger: #DC3545;
  --warning: #FFC107;
  --c-very-low: #DE6D6D;
  --c-low: #FFDC64;
  --c-in-range: #66D397;
  --c-high: #5C59FA;
  --c-very-high: #B978FF;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(19, 23, 103, 0.08);
  --nav-h: 72px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: "Lexend", system-ui, sans-serif;
  background: #cfcfcf;
  color: var(--black);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; }
a { color: var(--primary); }

.app {
  max-width: 430px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--white);
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,.12);
}
@media (min-width: 900px) {
  .app.app-wide { max-width: 1080px; }
}

.boot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #9e9e9e;
  color: var(--white);
  gap: 12px;
}
.boot-logo { width: 180px; height: auto; }

.screen { min-height: 100vh; padding-bottom: calc(var(--nav-h) + 16px); }
.screen.no-nav { padding-bottom: 24px; }

.hero-grey {
  background: #9e9e9e;
  padding: 28px 20px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}
.hero-grey img.logo { width: 160px; height: auto; }
.lang-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,.9);
  border: 0;
  border-radius: 20px;
  padding: 4px 8px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.flag-btn {
  background: none; border: 0; font-size: 22px; line-height: 1;
  cursor: pointer; padding: 8px 6px;
}
.notif-btn { position: relative; }
.notif-dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%; background: #DC3545;
}
.lang-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 8px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--grey);
  font-size: 15px;
}
.lang-row:last-child { border-bottom: 0; }
.lang-row.on { font-weight: 600; }
.flag-emoji { font-size: 24px; line-height: 1; }
.chat {
  padding: 8px 16px 88px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40vh;
  max-height: calc(100dvh - var(--nav-h) - 140px);
  overflow-y: auto;
}
.bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  white-space: normal;
}
.bubble.assistant { background: var(--bg); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.user { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-composer {
  position: sticky;
  bottom: calc(var(--nav-h) + 4px);
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-top: 1px solid var(--grey);
  z-index: 15;
}
.chat-composer input {
  flex: 1;
  border: 0;
  background: var(--bg);
  border-radius: 20px;
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
}

.sheet {
  background: var(--white);
  border-radius: var(--radius);
  margin: -28px 16px 16px;
  padding: 22px 18px 18px;
  box-shadow: var(--shadow);
  position: relative;
}

h1 { font-size: 20px; font-weight: 500; margin: 0 0 8px; text-align: center; }
h2 { font-size: 16px; font-weight: 500; margin: 0 0 12px; }
.subtitle { text-align: center; color: var(--muted); font-weight: 300; font-size: 14px; margin: 0 0 18px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--success); color: #fff; }
.btn-primary:hover { background: var(--success-dark); }
.btn-ghost { background: transparent; color: var(--black); }
.btn-outline {
  background: #fff;
  color: var(--black);
  border: 1px solid var(--grey-light);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-icon {
  width: 44px; height: 44px; padding: 0; border-radius: 12px;
  background: var(--bg); border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon img { width: 22px; height: 22px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field-row {
  display: flex;
  align-items: center;
  background: var(--bg);
  border-radius: 12px;
  padding: 0 12px;
  border: 1px solid transparent;
}
.field-row:focus-within { border-color: var(--primary-light); background: #fff; }
.field-row input, .field-row select, .field-row textarea {
  flex: 1; border: 0; background: transparent; padding: 13px 0; font-size: 15px; outline: none; color: var(--black); width: 100%;
}
.field-row select {
  color: rgb(104, 107, 172);
  -webkit-text-fill-color: rgb(104, 107, 172);
  font-weight: 500;
  appearance: none;
  -webkit-appearance: none;
}
#monitorMeal, #monitorDate {
  color: rgb(104, 107, 172);
  -webkit-text-fill-color: rgb(104, 107, 172);
  font-weight: 500;
}
.dose-lines {
  margin: 12px 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.7;
}
.dose-lines strong { color: var(--black); font-weight: 600; }
.field-row .suffix { color: var(--muted); font-size: 12px; margin-left: 8px; white-space: nowrap; }
.field-row-area { align-items: flex-start; padding-top: 8px; padding-bottom: 8px; }
.field-row textarea {
  min-height: calc(1.4em * 5);
  line-height: 1.4;
  resize: vertical;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.topbar h1 { font-size: 18px; margin: 0; text-align: left; }
.brand-mini { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mini img { width: 32px; height: 32px; }

.card {
  background: var(--white);
  border: 1px solid var(--grey);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 16px 12px;
  box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; background: var(--bg); border: 0; }
.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 16px 16px;
}
.quick-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0 16px 16px;
}
.quick {
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: left;
  border: 0;
  cursor: pointer;
}
.quick img { width: 26px; height: 26px; display: block; margin-bottom: 8px; }
.quick strong { display: block; font-size: 11px; line-height: 1.2; }
.quick span { font-size: 11px; color: var(--muted); }

.section-title { font-size: 16px; margin: 4px 16px 10px; }
.section-label { font-size: 13px; color: var(--muted); margin: 8px 20px 6px; }
.monitor-card {
  margin: 0 16px 16px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(166, 158, 214, 0.12);
}
.monitor-top, .monitor-mid, .monitor-bot { display: flex; justify-content: space-between; align-items: flex-start; }
.monitor-title { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.monitor-title img { width: 18px; height: 18px; }
.monitor-gly { font-size: 42px; font-weight: 500; line-height: 1; margin-right: 4px; }
.monitor-side { text-align: right; }
.hba1c-val { font-size: 28px; font-weight: 600; margin: 4px 0; }

.seg {
  display: flex;
  background: #F1F2F4;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: #7B7D86;
  border-radius: 6px;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.on { background: var(--primary); color: #fff; }

.profile-head { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary-light); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 600;
  overflow: hidden;
}
.avatar img, .avatar-img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; display: block; }
.avatar.mini, .doctor-item .avatar-img {
  width: 40px; height: 40px; font-size: 16px; flex-shrink: 0;
}
.doctor-item { align-items: center; }
.doctor-item .btn { flex: none; width: auto; padding: 8px 12px; font-size: 13px; }
.phone-row { display: grid; grid-template-columns: 118px 1fr; gap: 8px; align-items: stretch; }
.phone-row select {
  border: 0; background: var(--bg); border-radius: 12px; padding: 0 8px; font-size: 13px;
}
.menu-card { padding: 4px 8px; }
.menu-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--grey);
  font-size: 14px;
}
.menu-row:last-child { border-bottom: 0; }
.menu-row img { width: 22px; height: 22px; }
.menu-row span { flex: 1; }
.chev { color: var(--hint); font-size: 18px; flex: none !important; }
.legal { display: block; padding: 8px 0; color: var(--primary); text-decoration: none; }
.danger-txt { color: var(--danger) !important; }
.ref-link { display: block; padding: 12px 0; border-bottom: 1px solid var(--grey); text-decoration: none; color: inherit; }
.ref-link:last-child { border-bottom: 0; }

.result-box {
  background: linear-gradient(135deg, #131767, #6A6DB0);
  color: #fff;
  border-radius: 16px;
  padding: 16px;
  margin-top: 8px;
}
.result-box .big { font-size: 28px; font-weight: 600; }
.result-box .meta { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; opacity: .9; }

.list-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--grey);
}
.list-item:last-child { border-bottom: 0; }
.dot {
  width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex-shrink: 0;
}
.muted { color: var(--muted); font-size: 13px; }
.ok { color: var(--success-dark); }
.err { color: var(--danger); font-size: 13px; text-align: center; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px);
  background: var(--primary-dark); color: #fff;
  padding: 10px 16px; border-radius: 20px; font-size: 13px; z-index: 50;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 430px;
  height: var(--nav-h);
  background: #fff;
  border-top: 1px solid var(--grey);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  padding: 6px 6px 10px;
  z-index: 20;
}
.app.app-wide .bottom-nav { max-width: 1080px; }
.nav-item {
  background: none; border: 0; color: var(--muted); font-size: 9px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  line-height: 1.15; text-align: center; padding: 0 2px;
}
.nav-item.active { color: var(--success-dark); }
.nav-item img { width: 22px; height: 22px; opacity: .7; }
.nav-item.active img { opacity: 1; }
.nav-item img.nav-avatar {
  width: 24px; height: 24px; border-radius: 50%; object-fit: cover; opacity: 1;
}
.nav-fab {
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--success); color: rgb(104, 106, 172); border: 0;
  display: flex; align-items: center; justify-content: center;
  margin: -18px auto 0; box-shadow: 0 6px 16px rgba(36,190,98,.4);
  cursor: pointer;
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
  padding: 0 0 4px;
}
.nav-fab img { width: 26px; height: 26px; }
.line-wrap, .pie-wrap { position: relative; }
.line-wrap { height: 240px; width: 100%; margin-top: 8px; }
.pie-wrap { width: 150px; height: 150px; margin: 8px auto 4px; }
.line-wrap canvas, .pie-wrap canvas { display: block !important; width: 100% !important; height: 100% !important; }

.search-box { margin: 0 16px 12px; }
.food-row {
  display: grid;
  grid-template-columns: 1fr 80px 32px;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--grey);
  position: relative;
}
.food-head {
  display: flex; justify-content: space-between; gap: 8px;
  color: var(--primary); font-size: 14px; margin-bottom: 8px;
}
.food-name-wrap { position: relative; min-width: 0; }
.food-name, .food-row input[data-mass], .food-row input[data-photo-qty] {
  width: 100%; border: 0; background: #fff; border-radius: 12px;
  padding: 10px 8px; font-size: 13px;
}
.food-name-fixed { padding: 8px 4px; }
.food-suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 8;
  background: #fff; border-radius: 12px; box-shadow: var(--shadow);
  max-height: 220px; overflow: auto;
}
.food-suggest-item {
  display: flex; justify-content: space-between; gap: 8px;
  width: 100%; border: 0; background: none; text-align: left;
  padding: 10px 12px; cursor: pointer;
}
.food-suggest-item:hover { background: var(--bg); }
.food-actions {
  display: flex; justify-content: center; align-items: center;
  gap: 10px; margin: 16px 0 12px;
}
.food-fab {
  width: 57px; height: 57px; border-radius: 50%;
  border: 0; padding: 0; cursor: pointer; flex-shrink: 0;
  background: var(--primary); color: #fff;
  font-size: 34px; font-weight: 300; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.food-fab svg { width: 32px; height: 32px; display: block; }
.food-fab img { width: 32px; height: 32px; display: block; object-fit: contain; }
.recipe-fab {
  position: relative;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.food-fab .recipe-fab-img { width: 22px; height: 28px; }
.food-fab .fab-plus {
  position: absolute;
  right: -2px;
  bottom: -1px;
  width: 16px;
  height: 16px;
}
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 35; display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
}
.sheet-card {
  background: #fff; border-radius: 16px; padding: 16px;
  width: 100%; max-width: 430px; max-height: 82vh; overflow: auto;
}
.sheet-row {
  display: block; width: 100%; border: 0; background: var(--bg);
  border-radius: 12px; padding: 14px; margin-bottom: 8px;
  text-align: left; cursor: pointer; font-size: 15px;
}
.sheet-row.cancel { background: none; color: var(--muted); text-align: center; }
.overlay-busy {
  position: fixed; inset: 0; background: rgba(255,255,255,.72);
  z-index: 36; display: flex; align-items: center; justify-content: center;
  font-weight: 500; color: var(--primary);
}
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; }
.chip {
  border: 1px solid var(--grey-light); background: #fff; border-radius: 20px;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.chip.on { background: var(--success); color: #fff; border-color: var(--success); }

.gly-field {
  background: rgba(220, 53, 69, .1);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.gly-field > label { color: var(--danger); font-weight: 500; }
.gly-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: rgba(36, 190, 98, .1);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.gly-cell { text-align: center; }
.gly-cell img { width: 42px; height: 42px; }
.gly-cell .muted { font-size: 12px; margin: 4px 0; }
.gly-badge {
  display: inline-block; min-width: 72px; padding: 3px 8px;
  border-radius: 99px; color: #fff; font-size: 12px; font-weight: 500;
}
.gly-cell.on { outline: 1px solid var(--success); border-radius: 10px; background: rgba(36,190,98,.18); }

#reader { width: 100%; border-radius: 12px; overflow: hidden; }
.scanner-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.72);
  z-index: 40; display: flex; flex-direction: column; padding: 20px;
}
.scanner-modal .inner { background: #fff; border-radius: 16px; padding: 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }

.hidden { display: none !important; }
.linkish { background: none; border: 0; color: var(--primary); cursor: pointer; font-size: 13px; padding: 0; }

.doc-toolbar { padding: 0 16px 8px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.doc-loc-row { width: 100%; gap: 8px; }
.doc-loc-row .btn { width: 44px; flex: none; padding: 0; }
.refresh-link {
  background: var(--bg); border: 0; color: var(--primary); border-radius: 10px;
  padding: 8px 12px; font-size: 12px; cursor: pointer; width: auto;
}
.doc-section-title { color: var(--primary); font-size: 14px; margin: 8px 16px; font-weight: 500; }
.doc-chip-row {
  display: flex; gap: 10px; overflow-x: auto; padding: 0 16px 12px;
  -webkit-overflow-scrolling: touch;
}
.doc-chip {
  min-width: 96px; max-width: 120px; background: var(--bg); border: 0; border-radius: 12px;
  padding: 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
}
.doc-chip-img, .doc-card-img, .doc-detail-img {
  width: 52px; height: 52px; border-radius: 50%; object-fit: cover;
}
.doc-chip-name { font-size: 11px; text-align: center; color: var(--black); }
.doc-chip-link { font-size: 10px; color: var(--primary); text-decoration: underline; }
.doc-list { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.doc-card { background: var(--bg); border-radius: 12px; padding: 12px; }
.doc-card-main {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: 0; text-align: left; cursor: pointer; padding: 0 0 12px;
}
.doc-card-text { min-width: 0; }
.doc-name { font-size: 14px; color: var(--black); }
.doc-addr { font-size: 12px; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-consult { margin-top: 0; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
  background: var(--bg); width: 100%; max-width: 430px; border-radius: 16px 16px 0 0;
  padding: 12px 20px 28px;
}
.modal-handle { width: 75px; height: 4px; background: var(--grey-light); border-radius: 10px; margin: 4px auto 16px; }
.doc-detail-card {
  background: #fff; border-radius: 12px; padding: 48px 16px 16px; margin: 32px 0 16px;
  box-shadow: var(--shadow); position: relative;
}
.doc-detail-avatar { position: absolute; top: -36px; left: 50%; transform: translateX(-50%); }
.doc-detail-row { margin-bottom: 12px; }
.doc-detail-row strong { display: block; font-size: 16px; font-weight: 500; }
.modal-confirm { background: #fff; border-radius: 16px; margin: auto 16px; padding: 20px; width: calc(100% - 32px); max-width: 400px; align-self: center; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

@media (min-width: 900px) {
  .app.app-wide .content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
