:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efece6;
  --ink: #181b20;
  --muted: #5f6672;
  --border: #e5e1d8;
  --sage: #1f7a5c;
  --sage-soft: #e6f4ee;
  --amber: #c26b1f;
  --amber-soft: #fdf2e6;
  --blue: #2b6294;
  --blue-soft: #eaf2f9;
  --coral: #b83b3b;
  --coral-soft: #fbecec;
  --shadow: 0 2px 10px rgba(24, 27, 32, 0.04);
  --radius: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.48;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--sage-soft);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.num, .kpi-value, table, .date-cell {
  font-variant-numeric: tabular-nums;
}

/* Focus visibility */
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: 2px;
}

/* Login */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--sage);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.brand-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.login-form {
  margin-top: 22px;
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 500;
}

.field input, .date-select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.btn-primary {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--sage);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 160ms ease;
}

.btn-primary:hover { opacity: 0.92; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.form-error {
  margin: 0;
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--coral-soft);
  color: var(--coral);
  font-size: 0.86rem;
}

/* App Shell */
.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.profile-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--surface-2);
}

.profile-switch.compact {
  display: flex;
  gap: 2px;
  padding: 3px;
}

.profile-btn {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.profile-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.side-nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-item.active {
  background: var(--sage-soft);
  color: var(--sage);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 6px;
}

.btn-ghost {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-ghost:hover { background: var(--surface-2); }
.danger-text { color: var(--coral); }

/* Mobile header & bottom nav */
.mobile-header {
  display: none;
}

.bottom-nav {
  display: none;
}

.main-col {
  min-width: 0;
}

.content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 24px 40px;
  display: grid;
  gap: 20px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.page-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

/* Grids & Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card.alert-card {
  background: var(--amber-soft);
  border-color: #ecd2b4;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
}

.kpi-value {
  margin-top: 6px;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kpi-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.badge.ok { background: var(--sage-soft); color: var(--sage); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.bad { background: var(--coral-soft); color: var(--coral); }
.badge.info { background: var(--blue-soft); color: var(--blue); }

/* Progress bars */
.macro-list {
  display: grid;
  gap: 12px;
}

.macro-row-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
  margin-bottom: 5px;
}

.progress-track {
  height: 9px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 220ms ease;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--surface-2);
  vertical-align: top;
}

table.data-table tr:last-child td {
  border-bottom: 0;
}

/* Lists & Meal Feed */
.feed-list {
  display: grid;
  gap: 10px;
}

.feed-item {
  padding: 12px 14px;
  border-radius: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: grid;
  gap: 6px;
}

.feed-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.feed-title {
  font-weight: 600;
}

.feed-macros {
  font-size: 0.84rem;
  color: var(--muted);
}

.att-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--blue);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.phone-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 3px 10px;
  border-radius: 8px;
  background: var(--sage-soft);
  color: var(--sage);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.84rem;
}

/* Charts */
.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

/* Empty & Skeleton */
.empty-box {
  padding: 18px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.skeleton-card {
  height: 110px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 25%, #f9f8f5 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Dialog */
.media-dialog {
  width: min(92vw, 760px);
  max-height: 88dvh;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(0,0,0,0.22);
}

.media-dialog::backdrop {
  background: rgba(24, 27, 32, 0.52);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-title {
  font-weight: 600;
  font-size: 0.94rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-body {
  padding: 16px;
  overflow: auto;
  max-height: calc(88dvh - 58px);
}

.dialog-body img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
  margin: 0 auto;
}

.dialog-body iframe {
  width: 100%;
  height: 70dvh;
  border: 0;
  border-radius: 10px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar .date-select {
  width: auto;
  min-width: 160px;
}

/* Mobile breakpoint */
@media (max-width: 959px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
  }

  .mobile-title-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .mobile-title {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-actions {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .content {
    padding: 16px 14px calc(86px + env(safe-area-inset-bottom));
    gap: 14px;
  }

  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }

  .bnav-item {
    min-height: 48px;
    border: 0;
    background: transparent;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font: inherit;
    font-size: 0.74rem;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
  }

  .bnav-item.active {
    color: var(--sage);
    font-weight: 700;
    background: var(--sage-soft);
  }
}
