/* ============================================================
   NutriCo — Design System & Global Styles
   ============================================================ */

:root {
  /* Основна палітра */
  --color-bg:         #F7F4EF;
  --color-surface:    #FFFFFF;
  --color-surface-2:  #F0EBE3;
  --color-border:     #E8E0D5;

  /* Акценти */
  --color-primary:        #7BAE8E;
  --color-primary-light:  #A8C9B5;
  --color-secondary:      #D4A5A5;
  --color-accent:         #C4B5A5;
  --color-warning:        #E8C99A;

  /* Текст */
  --color-text:         #3D3530;
  --color-text-muted:   #8C7B72;
  --color-text-light:   #B5A89E;

  /* Типографіка */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;

  /* Радіуси */
  --radius-sm:  8px;
  --radius-md:  16px;
  --radius-lg:  24px;
  --radius-xl:  32px;

  /* Тіні */
  --shadow-sm: 0 2px 8px rgba(61, 53, 48, 0.06);
  --shadow-md: 0 4px 20px rgba(61, 53, 48, 0.10);
  --shadow-lg: 0 8px 40px rgba(61, 53, 48, 0.14);

  /* Анімації */
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 0.15s var(--ease-out);
  --transition-med:  0.3s var(--ease-out);
  --transition-slow: 0.6s var(--ease-out);

  /* Layout */
  --sidebar-width: 260px;
  --bottom-nav-height: 72px;
}

/* ── Reset & Base ─────────────────────────────────────────── */

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--color-text);
  margin-top: 0;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: #5e9470;
}

/* ── Root Layout ──────────────────────────────────────────── */

.app-root {
  display: flex;
  min-height: 100vh;
}

.app-main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-main {
  flex: 1;
  padding: 20px 16px calc(var(--bottom-nav-height) + 24px);
}

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* ── Sidebar (desktop ≥768px) ───────────────────────────── */

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  padding: 28px 20px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: none;
}

.app-sidebar-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Logo block */
.app-sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 36px;
  padding: 0 4px;
}

.app-sidebar-logo-icon {
  font-size: 22px;
  line-height: 1;
}

.app-sidebar-logo-text {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

/* Legacy top block (avatar at top — kept for compat) */
.app-sidebar-top {
  margin-bottom: 24px;
}

.app-sidebar-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
}

.app-sidebar-subtitle {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* Navigation */
.app-nav-vertical {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.app-nav-vertical .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: background var(--transition-fast),
              color var(--transition-fast),
              transform var(--transition-fast);
}

.app-nav-vertical .nav-link .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
}

.app-nav-vertical .nav-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.app-nav-vertical .nav-link.active {
  background: var(--color-primary);
  color: #fff;
}

.app-nav-vertical .nav-link.active .dot {
  background: rgba(255, 255, 255, 0.7);
}

/* Sidebar bottom — user + logout */
.app-sidebar-bottom {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}

.app-sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.app-avatar-lg,
.app-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--color-text);
  flex-shrink: 0;
}

.app-sidebar-user-info {
  min-width: 0;
}

.app-sidebar-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar-user-role {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* ── Bottom Navigation (mobile <768px) ──────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 20px rgba(61, 53, 48, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  max-width: 72px;
  height: 56px;
  border-radius: var(--radius-md);
  font-size: 22px;
  color: var(--color-text-light);
  text-decoration: none;
  transition: color var(--transition-fast),
              background var(--transition-fast);
}

.bottom-nav a.active {
  color: var(--color-primary);
  background: rgba(123, 174, 142, 0.12);
}

.bottom-nav a:hover:not(.active) {
  color: var(--color-text-muted);
}

/* ── Cards ────────────────────────────────────────────────── */

.card,
.app-card,
.dash-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}

.card-surface-2 {
  background: var(--color-surface-2);
}

/* Staggered page-load animation */
.animate-in {
  opacity: 0;
  transform: translateY(16px);
  animation: fadeUp 0.5s var(--ease-out) forwards;
}

.animate-in:nth-child(1) { animation-delay: 0ms; }
.animate-in:nth-child(2) { animation-delay: 100ms; }
.animate-in:nth-child(3) { animation-delay: 200ms; }
.animate-in:nth-child(4) { animation-delay: 300ms; }
.animate-in:nth-child(5) { animation-delay: 400ms; }

@keyframes fadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Buttons ──────────────────────────────────────────────── */

.btn-primary,
.btn-nutrico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 24px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast),
              box-shadow var(--transition-fast),
              background var(--transition-fast);
}

.btn-primary:hover,
.btn-nutrico:hover {
  background: #6a9d7d;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  color: #fff;
}

.btn-primary:active,
.btn-nutrico:active {
  transform: translateY(0);
}

.btn-outline-secondary,
.btn-outline-nutrico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--color-secondary);
  border: 1.5px solid var(--color-secondary);
  border-radius: var(--radius-md);
  padding: 11px 24px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast),
              transform var(--transition-fast);
}

.btn-outline-secondary:hover,
.btn-outline-nutrico:hover {
  background: rgba(212, 165, 165, 0.12);
  transform: translateY(-1px);
  color: var(--color-secondary);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 20px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast),
              color var(--transition-fast);
}

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

/* Bootstrap overrides */
.btn-success {
  background: var(--color-primary) !important;
  border-color: var(--color-primary) !important;
  border-radius: var(--radius-md) !important;
  font-family: var(--font-body);
  font-weight: 600;
  padding: 12px 24px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-success:hover {
  background: #6a9d7d !important;
  border-color: #6a9d7d !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-dark {
  background: var(--color-text) !important;
  border-color: var(--color-text) !important;
  border-radius: var(--radius-sm) !important;
}

.btn-outline-secondary.bs-override {
  border-color: var(--color-border) !important;
  color: var(--color-text-muted) !important;
  border-radius: var(--radius-sm) !important;
}

/* ── Progress Bars ────────────────────────────────────────── */

.progress-bar {
  background: var(--color-surface-2);
  border-radius: var(--radius-xl);
  height: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-xl);
  background: var(--color-primary);
  transition: width var(--transition-slow);
  width: 0;
}

.progress-fill.is-loaded {
  /* width set inline via style attr */
}

.progress-fill--warning {
  background: var(--color-warning);
}

.progress-fill--secondary {
  background: var(--color-secondary);
}

.progress-fill--protein {
  background: var(--color-primary);
}

.progress-fill--fat {
  background: var(--color-secondary);
}

.progress-fill--carbs {
  background: var(--color-warning);
}

/* Circular progress ring */
.calorie-ring {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 0 auto;
}

.calorie-ring svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.calorie-ring-track {
  fill: none;
  stroke: var(--color-surface-2);
  stroke-width: 12;
}

.calorie-ring-fill {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--transition-slow),
              stroke var(--transition-med);
}

.calorie-ring-fill.is-warning {
  stroke: var(--color-secondary);
}

.calorie-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.calorie-ring-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.1;
}

.calorie-ring-label {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* ── Meal Cards ───────────────────────────────────────────── */

.meal-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform var(--transition-fast),
              box-shadow var(--transition-fast);
}

.meal-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.meal-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.meal-card-body {
  flex: 1;
  min-width: 0;
}

.meal-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-card-meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.meal-card-kcal {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary);
  flex-shrink: 0;
}

/* Legacy meal-pill compat */
.meal-pill {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.meal-pill:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.meal-pill-type {
  font-weight: 600;
  font-size: 15px;
  color: var(--color-text);
  margin-bottom: 4px;
}

.meal-pill-meta {
  display: flex;
  gap: 8px;
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.meal-pill-desc {
  font-size: 13px;
  color: var(--color-text-light);
}

/* ── Modals & Auth ────────────────────────────────────────── */

.modal-content.app-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-content .form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.modal-content .form-control {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}

.modal-content .form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(123, 174, 142, 0.2);
  outline: none;
}

.modal-backdrop.show {
  background: rgba(61, 53, 48, 0.4);
  backdrop-filter: blur(2px);
}

.alert-danger {
  background: rgba(212, 165, 165, 0.2);
  border: 1px solid var(--color-secondary);
  color: #7a4545;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

/* ── Login Page ───────────────────────────────────────────── */

body.login-page {
  background: var(--color-bg);
  font-family: var(--font-body);
}

.login-page .card {
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  background: var(--color-surface);
}

.login-page h3 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--color-text);
}

.login-page .form-control {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-body);
}

.login-page .form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(123, 174, 142, 0.2);
}

.login-page .btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  border-radius: var(--radius-md);
  font-weight: 600;
  padding: 12px;
}

/* ── Utility Classes ──────────────────────────────────────── */

.text-muted-nutrico {
  color: var(--color-text-muted);
}

.text-light-nutrico {
  color: var(--color-text-light);
}

.font-display {
  font-family: var(--font-display);
}

.font-body {
  font-family: var(--font-body);
}

.text-primary-nutrico {
  color: var(--color-primary);
}

.text-secondary-nutrico {
  color: var(--color-secondary);
}

.text-success-nutrico {
  color: var(--color-primary);
}

.badge-nutrico {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--color-primary-light);
  color: var(--color-text);
}

.badge-nutrico--warning {
  background: rgba(232, 201, 154, 0.5);
}

.badge-nutrico--secondary {
  background: rgba(212, 165, 165, 0.3);
}

/* Section headings */
.section-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
}

.section-subtitle {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (min-width: 768px) {
  .app-sidebar {
    display: flex;
    flex-direction: column;
  }

  .app-main {
    padding: 28px 32px 32px;
  }

  .bottom-nav {
    display: none;
  }
}

@media (min-width: 992px) {
  .app-main {
    padding: 32px 40px 40px;
  }
}

/* ── Admin panel ─────────────────────────────────────────── */

.admin-page {
  max-width: 1100px;
}

.admin-header {
  margin-bottom: 20px;
}

.admin-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  margin: 0;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.admin-tab {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out);
}

.admin-tab:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.admin-tab--active {
  background: rgba(123, 174, 142, 0.2);
  border-color: var(--color-primary-light);
  color: var(--color-text);
}

.admin-panel {
  padding: 20px;
}

.admin-panel--narrow {
  max-width: 420px;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.admin-table th {
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
}

.admin-table tbody tr:hover {
  background: rgba(123, 174, 142, 0.06);
}

.admin-actions {
  white-space: nowrap;
}

.admin-actions form,
.admin-actions .btn {
  margin: 2px 2px 2px 0;
}

.admin-prompt-textarea {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.admin-stat-card {
  padding: 20px;
}

.admin-stat-card--wide {
  grid-column: 1 / -1;
}

.admin-stat-label {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.admin-stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--color-text);
}

.admin-stat-value--sm {
  font-size: 18px;
  font-family: var(--font-body);
  font-weight: 500;
}

/* ── Print ────────────────────────────────────────────────── */

@media print {
  .app-sidebar,
  .bottom-nav {
    display: none !important;
  }
}
