*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --card-bg: #ffffff;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --border-subtle: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --radius-card: 18px;
  --shadow-card: 0 14px 40px rgba(15, 23, 42, 0.24);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #0f766e 0, #0f172a 50%, #020617 100%);
  color: var(--text-main);
}

/* App shell */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 1rem 1.25rem 0.25rem;
  color: #f9fafb;
}

/* Top bar with brand + hamburger */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.5);
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 0.9rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: #e2e8f0;
}

/* Hamburger button */

.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.8);
  color: #e5e7eb;
  font-size: 0.82rem;
  cursor: pointer;
}

.menu-toggle:hover {
  background: rgba(15, 23, 42, 0.95);
}

.menu-toggle:focus-visible {
  outline: 2px solid #a5f3fc;
  outline-offset: 2px;
}

.hamburger {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
}

.hamburger span {
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: #e5e7eb;
}

.menu-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
}

/* Dropdown / overlay menu */

.main-menu {
  margin-top: 0.6rem;
  background: rgba(15, 23, 42, 0.98);
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  padding: 0.45rem 0.5rem;
  backdrop-filter: blur(14px);
  max-width: 280px;
}

.main-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.menu-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.86rem;
  color: #e5e7eb;
}

.menu-link-sub {
  font-size: 0.72rem;
  color: #9ca3af;
}

.menu-link:hover {
  background: rgba(15, 118, 110, 0.28);
}

/* On wider screens, tuck menu to the left slightly */

@media (min-width: 880px) {
  .app-header {
    padding-inline: 1.5rem;
  }
}

/* Layout */

.app-main {
  flex: 1;
  padding: 1rem 1.25rem 1.5rem;
  display: grid;
  gap: 1rem;
  max-width: 1040px;
  margin: 0 auto;
}

/* Cards */

.card {
  background: var(--card-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1.1rem 1.1rem 1.15rem;
}

/* Controls layout */

.controls {
  order: 2;
}

.graph-panel {
  order: 1;
}

@media (min-width: 880px) {
  .app-main {
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    align-items: start;
  }
  .controls {
    order: 1;
    position: sticky;
    top: 0.75rem;
    align-self: flex-start;
  }
  .graph-panel {
    order: 2;
  }
}

/* Fields */

h2 {
  margin: 0 0 0.6rem;
  font-size: 1.05rem;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.field-row .field {
  flex: 1 1 130px;
}

.field {
  margin-bottom: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-main);
}

.field-inline-input {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.unit {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: #f9fafb;
  border: 1px solid var(--border-subtle);
}

input[type="number"],
select {
  flex: 1;
  padding: 0.46rem 0.55rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  font-size: 0.9rem;
  outline: none;
  min-height: 40px;
}

input[type="number"]:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.2);
}

.hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

/* Warning text */

.warning {
  color: #b91c1c;
}

/* Section label */

.separator-label {
  margin: 0.2rem 0 0.4rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* Toggle (switch) */

.toggle-row {
  margin-bottom: 0.4rem;
}

.switch-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
}

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #e5e7eb;
  border-radius: 999px;
  transition: 0.2s;
}

.slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  border-radius: 999px;
  background-color: #ffffff;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background-color: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(18px);
}

.insulin-settings {
  border-radius: 12px;
  padding: 0.7rem 0.7rem 0.75rem;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  margin-bottom: 0.8rem;
  transition: opacity 0.2s;
}

.label-inline {
  margin: 0.2rem 0 0.3rem;
  font-size: 0.83rem;
  font-weight: 500;
}

/* Chips */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  font-size: 0.78rem;
  cursor: pointer;
}

.chip input[type="checkbox"] {
  cursor: pointer;
}

/* Buttons */

.primary-btn {
  margin-top: 0.4rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #ecfeff;
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
}

.primary-btn:hover {
  background: #115e59;
}

.primary-btn:active {
  transform: translateY(1px);
}

/* Graph area */

.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.graph-header h2 {
  margin-bottom: 0.1rem;
}

.graph-subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.canvas-wrapper {
  width: 100%;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

#graph {
  display: block;
  width: 100%;
  height: 260px;
}

/* Summary */

.summary {
  margin-top: 0.65rem;
  display: grid;
  gap: 0.4rem;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  font-size: 0.82rem;
}

.summary-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.summary-value {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.dot-noinsulin {
  background: #64748b;
}
.dot-pre {
  background: #1d4ed8;
}
.dot-at {
  background: #dc2626;
}
.dot-post {
  background: #f97316;
}

/* Disclaimer */

.disclaimer {
  margin-top: 0.8rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Footer */

.app-footer {
  padding: 0.8rem 1.25rem 1.1rem;
  font-size: 0.76rem;
  color: #cbd5e1;
  text-align: center;
}

/* Mobile tweaks */

@media (max-width: 600px) {
  .app-main {
    padding-inline: 0.75rem;
  }

  .card {
    padding: 0.9rem 0.85rem 1rem;
  }

  .subtitle {
    font-size: 0.82rem;
  }

  #graph {
    height: 240px;
  }
}
