/* ══════════════════════════════════════════════════════
   EasyDose – Dark Premium Theme
   ══════════════════════════════════════════════════════ */

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

:root {
  /* brand palette – same blue, adapted for dark */
  --blue-50:  #0d2847;
  --blue-100: #102e52;
  --blue-200: #1a4a7a;
  --blue-400: #42a5f5;
  --blue-500: #2196f3;
  --blue-600: #1e88e5;
  --blue-700: #1976d2;
  --blue-800: #1565c0;
  --blue-glow: rgba(33, 150, 243, 0.15);

  /* dark surface palette */
  --bg-base:    #0f1117;
  --bg-surface: #181b23;
  --bg-card:    #1e2230;
  --bg-card-hover: #252a3a;
  --bg-elevated: #282d3e;
  --bg-input:   #1a1e2a;

  /* dark neutrals */
  --grey-50:  #1a1e2a;
  --grey-100: #252a3a;
  --grey-200: #303648;
  --grey-300: #3d4560;
  --grey-400: #5a6380;
  --grey-500: #7c849c;
  --grey-600: #9ca3b8;
  --grey-700: #bfc5d6;
  --grey-800: #e0e4f0;

  --white: #f0f2fa;
  --black-87: #e8eaf0;
  --text-primary: #e8eaf0;
  --text-secondary: #9ca3b8;
  --text-muted: #6b7394;

  /* borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.08);
  --border-active: rgba(33, 150, 243, 0.4);

  /* shadows – dark mode */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-blue: 0 4px 20px rgba(33, 150, 243, 0.25);

  /* radii */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-pill: 100px;

  /* transitions */
  --ease-standard: cubic-bezier(.4, 0, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --t-fast: 180ms;
  --t-med: 280ms;

  /* Content width – responsive */
  --max-w: 700px;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: 'Funnel Display', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App shell ── */
#app {
  max-width: var(--max-w);
  margin: 0 auto;
  position: relative;
  padding-bottom: 100px;
}

/* ── Header ── */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  padding: 14px 20px;
  background: transparent;
  z-index: 10;
}

.header-actions {
  display: flex;
  gap: 4px;
}

#btn-auth.logged-in {
  color: var(--blue-400);
}

#app-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -.3px;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  color: rgba(255,255,255,.7);
  transition: all var(--t-fast) var(--ease-standard);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: rgba(255,255,255,.08);
  color: var(--white);
}

.icon-btn:active {
  background: rgba(255,255,255,.12);
}

/* ── Hero ── */
#hero {
  position: relative;
  overflow: visible;
  min-height: 300px;
  padding: 44px 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 12px;
}

/* Glow effect below the circle - using pseudo to avoid clipping */
#hero::after {
  content: '';
  position: absolute;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 120%;
  height: 160px;
  background: radial-gradient(ellipse at 50% 0%, rgba(25, 118, 210, 0.35) 0%, rgba(25, 118, 210, 0.1) 40%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

#hero-bg {
  position: absolute;
  --circle-size: max(300vw, 2000px);
  width: var(--circle-size);
  height: var(--circle-size);
  border-radius: 50%;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--circle-size) * -1 + 300px);
  background: linear-gradient(145deg, #1565c0 0%, #1976d2 40%, #1e88e5 100%);
  z-index: 0;
}

#hero-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#insulin-display {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

#insulin-value {
  font-size: 76px;
  font-weight: 800;
  color: var(--white);
  line-height: 1;
  letter-spacing: -2px;
  text-shadow: 0 2px 20px rgba(0,0,0,.2);
  transition: transform var(--t-med) var(--ease-standard);
}

#insulin-value.bump {
  animation: valBump 320ms var(--ease-spring);
}

@keyframes valBump {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

#insulin-unit {
  font-size: 28px;
  font-weight: 600;
  color: rgba(255,255,255,.8);
}

#carbs-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 8px 18px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--r-pill);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  letter-spacing: .3px;
}

/* ── Food section ── */
#food-section {
  position: relative;
  z-index: 10;
  background: transparent;
  padding: 32px 20px 20px;
  margin-top: 0;
}

#food-section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}

/* Search box */
#search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 0 14px;
  transition: border-color var(--t-fast) var(--ease-standard),
              box-shadow var(--t-fast) var(--ease-standard);
}

#search-box:focus-within {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.12);
}

.search-icon {
  color: var(--text-muted);
  font-size: 22px;
}

#search-input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  padding: 13px 0;
  color: var(--text-primary);
}

#search-input::placeholder {
  color: var(--text-muted);
}

/* Food list */
#food-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Food card ── */
.food-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 13px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-default);
  background: var(--bg-card);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease-standard),
              background var(--t-fast) var(--ease-standard),
              box-shadow var(--t-fast) var(--ease-standard),
              transform var(--t-fast) var(--ease-standard);
  user-select: none;
  -webkit-user-select: none;
}

.food-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255,255,255,.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

.food-card.selected {
  border-color: var(--blue-500);
  border-width: 2px;
  background: var(--blue-50);
  padding: 12px 13px;
}

/* Checkbox */
.food-checkbox {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 2px solid var(--grey-400);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast) var(--ease-standard);
  margin-right: 4px;
}

.food-card.selected .food-checkbox {
  background: var(--blue-500);
  border-color: var(--blue-500);
  box-shadow: 0 0 8px rgba(33, 150, 243, 0.3);
}

.food-checkbox .material-icons-round {
  font-size: 16px;
  color: var(--white);
  opacity: 0;
  transform: scale(.5);
  transition: all var(--t-fast) var(--ease-standard);
}

.food-card.selected .food-checkbox .material-icons-round {
  opacity: 1;
  transform: scale(1);
}

/* Info */
.food-info {
  flex: 1;
  min-width: 0;
}

.food-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.food-carbs {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Grams input */
.food-grams-input {
  width: 64px;
  flex-shrink: 0;
  padding: 7px 8px;
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  background: var(--bg-input);
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  text-align: center;
  transition: border-color var(--t-fast) var(--ease-standard);
  -moz-appearance: textfield;
}

.food-grams-input::-webkit-outer-spin-button,
.food-grams-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.food-grams-input:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.12);
}

.food-grams-suffix {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: -4px;
  flex-shrink: 0;
}

/* Menu wrapper */
.food-menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.food-menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast) var(--ease-standard);
}

.food-menu-btn:hover {
  background: rgba(255,255,255,.06);
  color: var(--text-secondary);
}

/* Popup menu */
.popup-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--bg-elevated);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-default);
  z-index: 100;
  min-width: 140px;
  padding: 4px 0;
}

.popup-menu.open {
  display: block;
}

.popup-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-standard);
}

.popup-menu button:hover {
  background: rgba(255,255,255,.05);
}

/* ── Empty states ── */
.empty-state {
  padding: 48px 16px;
  text-align: center;
}

.empty-icon {
  font-size: 52px;
  color: var(--grey-300);
}

.empty-title {
  font-size: 16px;
  color: var(--text-muted);
  margin-top: 14px;
}

.empty-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
  opacity: .6;
}

/* ── FABs ── */
#fab-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  z-index: 50;
}

.fab {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  transition: transform var(--t-fast) var(--ease-spring),
              box-shadow var(--t-fast) var(--ease-standard);
}

.fab:hover {
  transform: scale(1.08);
}

.fab:active {
  transform: scale(.96);
}

.fab .material-icons-round {
  font-size: 26px;
}

.fab-primary {
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  box-shadow: 0 4px 20px rgba(33, 150, 243, 0.35);
}

.fab-primary:hover {
  box-shadow: 0 6px 30px rgba(33, 150, 243, 0.5);
}

.fab-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-md);
}

.fab-secondary:hover {
  background: var(--bg-card-hover);
}

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0);
  transition: background var(--t-med) var(--ease-standard);
}

.modal-overlay.visible {
  background: rgba(0, 0, 0, .6);
}

.modal-card {
  background: var(--bg-surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: var(--r-lg);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  padding: 28px;
  opacity: 0;
  transform: scale(.94) translateY(12px);
  transition: opacity var(--t-med) var(--ease-standard),
              transform var(--t-med) var(--ease-spring);
}

.modal-overlay.visible .modal-card {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.modal-card h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  background: var(--bg-input);
  font-family: inherit;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--t-fast) var(--ease-standard),
              box-shadow var(--t-fast) var(--ease-standard);
}

.field input:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}

.field input::placeholder {
  color: var(--text-muted);
}

.input-with-suffix {
  position: relative;
}

.input-with-suffix input {
  padding-right: 44px;
}

.input-with-suffix .suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.divider {
  height: 1px;
  background: var(--border-default);
  margin: 4px 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
}

/* ── Buttons ── */
.btn-text {
  background: none;
  border: none;
  padding: 10px 18px;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--blue-400);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-standard);
}

.btn-text:hover {
  background: var(--blue-glow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  color: var(--white);
  border: none;
  padding: 10px 22px;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-standard);
}

.btn-primary:hover {
  box-shadow: var(--shadow-blue);
  filter: brightness(1.1);
}

.btn-danger {
  background: linear-gradient(135deg, #ef5350, #c62828);
  color: var(--white);
  border: none;
  padding: 10px 22px;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-standard);
}

.btn-danger:hover {
  box-shadow: 0 4px 16px rgba(239, 83, 80, 0.3);
  filter: brightness(1.1);
}

/* ── Glucose result ── */
#glucose-result-content {
  padding: 12px 0 0;
  text-align: center;
}

.glucose-ok {
  color: #66BB6A;
}

.glucose-ok .material-icons-round {
  font-size: 52px;
}

.glucose-text {
  font-size: 16px;
  font-weight: 700;
}

.glucose-low {
  color: #FFB74D;
}

.glucose-high {
  color: #EF5350;
}

/* ── Snackbar ── */
.snackbar {
  position: fixed;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-default);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  white-space: nowrap;
  transition: bottom var(--t-med) var(--ease-spring);
  max-width: calc(100vw - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.snackbar.show {
  bottom: 28px;
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════ */

/* Small phones */
@media (max-width: 360px) {
  #insulin-value {
    font-size: 58px;
  }

  #insulin-unit {
    font-size: 22px;
  }

  #hero {
    padding: 36px 12px 28px;
  }

  .food-name {
    font-size: 14px;
  }

  .food-grams-input {
    width: 56px;
  }
}

/* Tablets & wider */
@media (min-width: 600px) {
  :root {
    --max-w: 720px;
  }

  #insulin-value {
    font-size: 92px;
  }

  #insulin-unit {
    font-size: 32px;
  }

  #hero {
    padding: 56px 20px 48px;
  }

  .food-card {
    padding: 14px 16px;
  }

  .food-card.selected {
    padding: 13px 15px;
  }
}

/* Desktop */
@media (min-width: 900px) {
  :root {
    --max-w: 800px;
  }

  #app-header {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    padding: 20px 32px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #app-header h1 {
    font-size: 24px;
  }

  #btn-settings {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 110;
  }

  #hero {
    padding: 64px 24px 56px;
  }

  #insulin-value {
    font-size: 104px;
  }

  #carbs-badge {
    font-size: 15px;
    padding: 10px 22px;
  }

  #food-section {
    padding: 0 24px;
    margin-top: 32px;
  }

  #food-section-title {
    font-size: 24px;
  }

  #food-list {
    display: block;
  }

  .fab {
    width: 60px;
    height: 60px;
  }

  .fab .material-icons-round {
    font-size: 28px;
  }

  #fab-container {
    bottom: 32px;
    right: 32px;
  }
}

/* Large desktop */
@media (min-width: 1200px) {
  :root {
    --max-w: 880px;
  }

  #fab-container {
    right: 40px;
  }

  #app-header {
    padding: 24px 40px;
  }

  #btn-settings {
    right: 40px;
  }
}

/* Ensure inputs don't zoom on iOS */
@supports (-webkit-touch-callout: none) {
  .field input,
  .food-grams-input,
  #search-input {
    font-size: 16px;
  }
}