:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --border: #e5e7eb;
  --shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 {
  margin: 0 0 0.5rem;
}

p {
  margin: 0.5rem 0 0;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.app-header {
  padding: 3rem 1.5rem 2rem;
  background: linear-gradient(120deg, #1e3a8a, #2563eb);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
  opacity: 0.8;
}

.subtitle {
  max-width: 520px;
  opacity: 0.9;
}

.accent {
  color: #fef08a;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card {
  background: var(--card);
  padding: 1.75rem;
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.status-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
}

.status-block {
  padding: 1rem 1.25rem;
  background: var(--accent-soft);
  border-radius: 1rem;
}

.label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.status {
  font-weight: 600;
}

.status.safe {
  color: var(--success);
}

.status.warning {
  color: var(--warning);
}

.status.danger {
  color: var(--danger);
}

.progress-wrap {
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444);
  transition: width 0.3s ease;
}

.inline-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.settings-grid label,
.meal-form label,
.mapping label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.settings-grid input,
.settings-grid select,
.meal-form input,
.mapping input {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  font-size: 1rem;
  color: var(--text);
}

.toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.meal-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.table-wrapper {
  overflow-x: auto;
}

th, td {
  text-align: left;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.cgm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.upload-card {
  background: #f8fafc;
  padding: 1.25rem;
  border-radius: 1rem;
  border: 1px dashed var(--border);
}

.chart-card {
  background: #ffffff;
  border-radius: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
}

.notice {
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.9rem;
}

.primary,
.ghost {
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}

.primary:hover,
.ghost:hover {
  transform: translateY(-1px);
}

.ghost {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
}

.ghost.danger {
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.4);
}

.footer {
  text-align: center;
  padding: 2rem 1rem 3rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.hint {
  color: var(--muted);
  font-size: 0.95rem;
}

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
  }

  .primary,
  .ghost {
    width: 100%;
    justify-content: center;
  }
}
