/* ============================================================
   GreenPulse Mini App — Vibrant Edition + Complete UI System
   ============================================================ */

:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #060908;
  --bg-sidebar: rgba(10, 16, 13, 0.85);
  --bg-card: rgba(18, 28, 23, 0.65);
  --bg-card-hover: rgba(24, 38, 31, 0.92);
  --bg-input: rgba(10, 16, 13, 0.9);
  --text: #f0fdf4;
  --text-muted: #86efac;
  --text-dim: #9ca3af;
  --border: rgba(134, 239, 172, 0.14);
  --border-hover: rgba(134, 239, 172, 0.45);
  --accent: #4ade80;
  --accent-2: #86efac;
  --accent-deep: #22c55e;
  --accent-text: #052e16;
  --danger: #f87171;
  --warn: #fbbf24;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  --glow: 0 0 32px rgba(74, 222, 128, 0.22);
}

[data-theme="light"] {
  --bg: #f0fdf4;
  --bg-sidebar: rgba(255, 255, 255, 0.9);
  --bg-card: rgba(255, 255, 255, 0.88);
  --bg-card-hover: rgba(255, 255, 255, 1);
  --bg-input: #ffffff;
  --text: #052e16;
  --text-muted: #166534;
  --text-dim: #6b7280;
  --border: rgba(34, 197, 94, 0.22);
  --border-hover: rgba(34, 197, 94, 0.55);
  --accent: #16a34a;
  --accent-2: #22c55e;
  --accent-deep: #15803d;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --shadow: 0 8px 28px rgba(22, 163, 74, 0.12);
  --glow: 0 0 28px rgba(34, 197, 94, 0.18);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(74, 222, 128, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 222, 128, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.nav-toggle { display: none; }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: 252px;
  height: 100vh;
  background: var(--bg-sidebar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.9rem;
  z-index: 120;
  transition: transform var(--transition);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.65rem 1.15rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.sidebar__logo { border-radius: 50%; object-fit: cover; background: #fff; }
.sidebar__brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.3px; }

.sidebar__nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.62rem 0.85rem;
  border-radius: 10px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}
.nav-item__icon { width: 19px; height: 19px; flex-shrink: 0; }
.nav-item:hover { color: var(--text); background: rgba(74, 222, 128, 0.08); }
.nav-item--active {
  background: rgba(74, 222, 128, 0.14);
  color: var(--accent);
  font-weight: 600;
}
.nav-item--active::after {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.sidebar__profile {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 0.4rem 0.2rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.profile__avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.82rem; flex-shrink: 0;
}
.profile__info { display: flex; flex-direction: column; overflow: hidden; flex: 1; }
.profile__name { font-size: 0.84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile__role { font-size: 0.72rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile__logout {
  color: var(--text-dim); text-decoration: none; font-size: 0.85rem;
  padding: 0.25rem 0.4rem; border-radius: 6px;
}
.profile__logout:hover { color: var(--danger); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  z-index: 110;
}

/* ===== LAYOUT & TOPBAR ===== */
.layout {
  margin-left: 252px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 2rem;
  background: var(--bg-sidebar);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}
.topbar__title { font-size: 1.05rem; font-weight: 600; flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: 0.6rem; }

.badge {
  padding: 0.24rem 0.6rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.badge--pro, .badge--trial {
  background: rgba(74, 222, 128, 0.16);
  color: var(--accent);
  border: 1px solid var(--border-hover);
}
.badge--free {
  background: rgba(148, 163, 184, 0.14);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.theme-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 0.42rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
}
.theme-toggle:hover { border-color: var(--border-hover); color: var(--accent); }
.theme-toggle svg { width: 17px; height: 17px; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }

.burger { display: none; flex-direction: column; gap: 4.5px; cursor: pointer; padding: 0.35rem; }
.burger span { width: 20px; height: 2px; background: var(--text); border-radius: 2px; }

/* ===== CONTENT ===== */
.content { padding: 1.6rem 2rem 3rem; max-width: 1360px; width: 100%; }
.content__head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end;
  gap: 1rem; margin-bottom: 1.5rem;
}
.content__heading { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.4px; }
.content__subtitle { color: var(--text-dim); font-size: 0.88rem; margin-top: 0.15rem; }

/* ===== CARDS ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}
.card:hover { border-color: var(--border-hover); box-shadow: var(--shadow), var(--glow); transform: translateY(-2px); }

.card__top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.85rem; }
.card__icon {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: rgba(74, 222, 128, 0.12);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.card__icon svg { width: 20px; height: 20px; }

.card__trend {
  font-size: 0.74rem; font-weight: 600;
  padding: 0.18rem 0.5rem; border-radius: 6px;
  background: rgba(148, 163, 184, 0.12); color: var(--text-dim);
}
.card__trend--up { background: rgba(74, 222, 128, 0.16); color: var(--accent); }
.card__trend--down { background: rgba(248, 113, 113, 0.16); color: var(--danger); }

.card__value {
  font-size: 1.95rem; font-weight: 800; letter-spacing: -1px;
  line-height: 1.15; font-variant-numeric: tabular-nums; margin-bottom: 0.25rem;
}
.card__label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.card__hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.4rem; }
.card__hint--danger { color: var(--danger); display: flex; align-items: center; gap: 0.4rem; font-weight: 600; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot--danger { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

/* ===== PANELS, CHARTS, TABLES ===== */
.charts { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }

.panel, .chart {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.charts .chart { margin-bottom: 0; }

.panel__head, .chart__head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 0.75rem; margin-bottom: 1rem;
}
.panel__title, .chart__title { font-size: 1rem; font-weight: 600; }
.panel__meta, .chart__meta { font-size: 0.8rem; color: var(--text-dim); }

.chart__body { height: 185px; position: relative; }
.chart-svg { width: 100%; height: 100%; display: block; overflow: visible; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th {
  text-align: left; padding: 0.65rem 0.75rem;
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); border-bottom: 1px solid var(--border);
}
.table td { padding: 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table__num { text-align: right; font-variant-numeric: tabular-nums; }
.table__mono { font-family: ui-monospace, monospace; color: var(--text-dim); font-size: 0.82rem; }
.table__strong { font-weight: 600; display: block; }
.table__sub { font-size: 0.76rem; color: var(--text-dim); display: block; }

/* ===== STATUS PILLS ===== */
.status {
  display: inline-flex; align-items: center;
  padding: 0.18rem 0.55rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
}
.status--new, .status--active { background: rgba(74, 222, 128, 0.16); color: var(--accent); }
.status--done, .status--completed { background: rgba(148, 163, 184, 0.16); color: var(--text-dim); }
.status--printed { background: rgba(56, 189, 248, 0.16); color: #38bdf8; }
.status--pro { background: rgba(251, 191, 36, 0.18); color: var(--warn); }
.status--global { background: rgba(74, 222, 128, 0.14); color: var(--accent-2); }
.status--own { background: rgba(167, 139, 250, 0.18); color: #c4b5fd; }
.status--danger { background: rgba(248, 113, 113, 0.18); color: var(--danger); }

/* ===== BUTTONS & FORMS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.55rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-family: inherit;
  font-size: 0.86rem; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: all var(--transition);
}
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover { filter: brightness(1.08); box-shadow: var(--glow); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { border-color: var(--border-hover); color: var(--accent); }
.btn--danger { background: rgba(248, 113, 113, 0.15); border-color: rgba(248, 113, 113, 0.35); color: var(--danger); }
.btn--sm { padding: 0.35rem 0.68rem; font-size: 0.78rem; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.85rem; }
.form-group { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.85rem; }
.form-group label { font-size: 0.78rem; font-weight: 600; color: var(--text-dim); }
.input, .select, .textarea {
  width: 100%; padding: 0.58rem 0.78rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-input); color: var(--text);
  font-family: inherit; font-size: 0.9rem;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); }

/* ===== SCENARIOS & TASKS LISTS ===== */
.filter-pills { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 1rem; }
.pill {
  padding: 0.38rem 0.85rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text-dim); font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.pill--active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.scenario-list, .task-list { list-style: none; display: flex; flex-direction: column; gap: 0.65rem; }
.scenario, .task-row {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.9rem 1rem; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.02);
}
.scenario__title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; margin-bottom: 0.3rem; }
.scenario__name { font-weight: 600; font-size: 0.95rem; }
.scenario__meta { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; font-size: 0.78rem; color: var(--text-dim); }
.scenario__tag { padding: 0.12rem 0.45rem; border-radius: 6px; border: 1px solid var(--border); }
.scenario__actions { display: flex; align-items: center; gap: 0.45rem; flex-shrink: 0; }

.progress-bar { height: 7px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 0.45rem; }
.progress-bar__fill { height: 100%; background: var(--accent); border-radius: 999px; }

/* ===== CHAT (AGRONOM) ===== */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 220px); min-height: 420px; }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; padding: 0.5rem 0.25rem 1rem; }
.chat-msg { max-width: 85%; padding: 0.75rem 1rem; border-radius: 14px; font-size: 0.9rem; white-space: pre-wrap; }
.chat-msg--user { align-self: flex-end; background: var(--accent); color: var(--accent-text); font-weight: 500; }
.chat-msg--ai { align-self: flex-start; background: var(--bg-card-hover); border: 1px solid var(--border); }
.chat-form { display: flex; gap: 0.6rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }

/* ===== MODAL & TOAST ===== */
.modal {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(4px);
  align-items: center; justify-content: center; padding: 1rem;
}
.modal--open { display: flex; }
.modal__card {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border-hover);
  border-radius: var(--radius); padding: 1.35rem; box-shadow: var(--shadow);
}
.modal__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal__close { background: none; border: none; color: var(--text-dim); font-size: 1.25rem; cursor: pointer; }

.toast {
  position: fixed; bottom: 80px; right: 20px; z-index: 300;
  padding: 0.7rem 1.1rem; border-radius: 10px;
  background: var(--bg-card-hover); border: 1px solid var(--border-hover);
  color: var(--text); font-size: 0.85rem; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(10px);
  pointer-events: none; transition: all 0.25s ease;
}
.toast--show { opacity: 1; transform: translateY(0); }

.empty { text-align: center; padding: 2rem 1rem; color: var(--text-dim); }
.empty__title { font-weight: 600; color: var(--text); margin-bottom: 0.3rem; }

/* ===== MOBILE BOTTOM NAV (Telegram Mini App) ===== */
.bottom-nav { display: none; }

@media (max-width: 960px) {
  .charts { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .nav-toggle:checked ~ .sidebar { transform: translateX(0); }
  .nav-toggle:checked ~ .sidebar-overlay { display: block; }
  .layout { margin-left: 0; padding-bottom: 68px; }
  .burger { display: flex; }
  .topbar { padding: 0.75rem 1rem; }
  .content { padding: 1.1rem 1rem 1.8rem; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .scenario, .task-row { flex-direction: column; align-items: flex-start; }
  .scenario__actions { width: 100%; justify-content: flex-end; }

  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 95;
    background: var(--bg-sidebar); backdrop-filter: blur(18px);
    border-top: 1px solid var(--border);
    padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0));
  }
  .bottom-nav__item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    text-decoration: none; color: var(--text-dim); font-size: 0.68rem; font-weight: 500;
    padding: 0.25rem 0;
  }
  .bottom-nav__item--active { color: var(--accent); font-weight: 700; }
  .bottom-nav__item svg { width: 20px; height: 20px; }
}

@media (max-width: 460px) {
  .cards { grid-template-columns: 1fr; }
}
