/* Receipts Mini App — dark glass theme */
:root {
  --bg0: #0a0c10;
  --bg1: #12151c;
  --bg2: #1a1f2a;
  --glass-bg: rgba(255, 255, 255, 0.055);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-hover: rgba(255, 255, 255, 0.09);
  --text: #eef0f6;
  --muted: #9aa3b5;
  --primary: #6aa3ff;
  --primary-dim: rgba(106, 163, 255, 0.16);
  --accent: #8bd7ff;
  --success: #5dd39e;
  --warning: #f0b429;
  --danger: #ff7b6b;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.35);
  --nav-h: 58px;
  --topbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(106, 163, 255, 0.12), transparent 50%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(139, 215, 255, 0.06), transparent 45%),
    linear-gradient(165deg, var(--bg0) 0%, var(--bg1) 45%, var(--bg0) 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px calc(24px + var(--nav-h) + var(--safe-bottom));
}

/* Top header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 45;
  margin: 0 -16px 14px;
  padding: calc(10px + var(--safe-top)) 16px 12px;
  background: rgba(10, 12, 16, 0.94);
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
}

.topbar-brand {
  flex: 1;
  min-width: 0;
}

.title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-refresh {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  min-height: 42px;
  min-width: 42px;
}

.topbar-refresh-icon {
  font-size: 1.15rem;
  line-height: 1;
}

@media (max-width: 380px) {
  .topbar-refresh-label {
    display: none;
  }

  .topbar-refresh {
    padding: 10px;
    min-width: 42px;
  }
}

/* Bottom tab navigation (Telegram-friendly) */
.navbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  gap: 6px;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  margin: 0;
  background: rgba(14, 17, 24, 0.88);
  border-top: 1px solid var(--glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
}

.tab {
  flex: 1;
  padding: 10px 8px;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}

.tab:hover { color: var(--text); background: var(--glass-hover); }

.tab:active { transform: scale(0.98); }

.tab.active {
  color: var(--text);
  background: var(--primary-dim);
  border-color: rgba(106, 163, 255, 0.35);
  box-shadow: 0 0 0 1px rgba(106, 163, 255, 0.12) inset;
}

/* Cards */
.card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  margin-bottom: 14px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  position: relative;
}

.card > h2 {
  margin: 0 0 4px;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-desc {
  margin: 0 0 14px;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.45;
}

.panel {
  margin-top: 4px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
}

.panel + .panel { margin-top: 12px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.panel-head h3 {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.method-block + .method-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--glass-border);
}

.method-title {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

h3:not(.method-title) {
  margin: 0 0 8px;
  font-size: 0.9375rem;
  font-weight: 600;
}

.label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin: 0 0 6px;
}

.textarea,
.filter,
input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  font-size: 0.9375rem;
  font-family: inherit;
  min-height: 42px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.4;
}

.textarea::placeholder,
.filter::placeholder {
  color: rgba(154, 163, 181, 0.75);
}

.textarea:focus,
.filter:focus,
input[type="text"]:focus {
  outline: none;
  border-color: rgba(106, 163, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(106, 163, 255, 0.15);
}

.row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.row.tight { margin-top: 6px; }

.btn {
  border: 1px solid var(--glass-border);
  background: var(--glass-hover);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9375rem;
  font-family: inherit;
  min-height: 44px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn:active { transform: scale(0.98); }

.btn.primary {
  background: linear-gradient(135deg, #7eb4ff 0%, var(--primary) 100%);
  border-color: transparent;
  color: #0a1220;
  box-shadow: 0 4px 16px rgba(106, 163, 255, 0.35);
}

.btn.primary:hover {
  box-shadow: 0 6px 20px rgba(106, 163, 255, 0.45);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
  border-color: rgba(255, 123, 107, 0.35);
  background: rgba(255, 123, 107, 0.08);
}

.btn.icon-btn {
  min-width: 44px;
  padding: 8px 12px;
  font-size: 1.25rem;
  line-height: 1;
}

.btn-block { width: 100%; justify-content: center; }

.sep {
  height: 1px;
  background: var(--glass-border);
  margin: 16px 0;
  border: none;
}

.hint {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.45;
}

/* Lists */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.item.clickable {
  cursor: pointer;
}

.item.clickable:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(106, 163, 255, 0.25);
}

.item.clickable:active {
  transform: scale(0.995);
}

.item .meta {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 6px;
  line-height: 1.4;
}

.item-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-title {
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.35;
}

.item-sub {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 2px;
}

.item-amount {
  font-weight: 700;
  font-size: 0.9375rem;
  white-space: nowrap;
  color: var(--accent);
}

.item-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
}

.badge-imported {
  color: var(--success);
  background: rgba(93, 211, 158, 0.12);
  border-color: rgba(93, 211, 158, 0.3);
}

.badge-pending {
  color: var(--warning);
  background: rgba(240, 180, 41, 0.12);
  border-color: rgba(240, 180, 41, 0.35);
}

.badge-failed,
.badge-error {
  color: var(--danger);
  background: rgba(255, 123, 107, 0.1);
  border-color: rgba(255, 123, 107, 0.35);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 28px 16px;
  border-radius: var(--radius);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.15);
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.empty-state strong {
  display: block;
  color: var(--text);
  font-size: 0.9375rem;
  margin-bottom: 6px;
}

.hidden { display: none !important; }

.clickable { cursor: pointer; }

#videoPreview {
  width: 100%;
  max-height: 280px;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  background: #000;
}

#videoRow {
  margin-top: 10px;
  width: 100%;
}

/* Analytics */
#analytics { padding-top: 4px; }

#forecastChart {
  width: 100%;
  height: 280px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.25);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
  font-style: normal;
}

.chart-legend i.hist { background: var(--accent); }
.chart-legend i.fore { background: var(--primary); }
.chart-legend i.band {
  width: 12px;
  height: 12px;
  background: rgba(76, 141, 255, 0.2);
}

#forecastSummary { margin: 8px 0 10px; }

#basketDay { margin-top: 8px; }

.cat-grid {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.cat-chart-card,
.cat-products-card {
  flex: 1 1 280px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  min-width: 0;
}

.cat-chart-card canvas {
  width: 100%;
  max-height: 240px;
}

/* Filter bar */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin-bottom: 12px;
}

.filter-bar .field-full {
  grid-column: 1 / -1;
}

.filter-bar .field-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-bar .field-actions .btn {
  flex: 1;
  min-width: 120px;
}

#filtersRow.filter-bar .label {
  margin: 0 0 4px;
}

#filtersRow .row {
  margin-top: 0;
}

/* Segmented control */
.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--glass-border);
}

.seg-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.seg-btn:hover { color: var(--text); }

.seg-btn.active {
  color: var(--text);
  background: var(--primary-dim);
  border-color: rgba(106, 163, 255, 0.35);
}

.file-hidden { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.ok {
  color: var(--success);
  border-color: rgba(93, 211, 158, 0.35);
}

/* Button loading */
.btn.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.85;
}

.btn .spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Toasts */
#toastsHost {
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}

.toast {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  background: rgba(22, 26, 36, 0.95);
  color: var(--text);
  font-size: 0.875rem;
  max-width: min(360px, calc(100vw - 32px));
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.info { border-color: rgba(106, 163, 255, 0.45); }
.toast.success { border-color: rgba(93, 211, 158, 0.5); }
.toast.error { border-color: rgba(255, 123, 107, 0.5); }

/* Select */
.select-wrap {
  position: relative;
  display: block;
  width: 100%;
}

.select-wrap .filter {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  pointer-events: none;
}

.date-wrap {
  position: relative;
  width: 100%;
}

.date-wrap input[data-date="true"] {
  width: 100%;
  padding-right: 36px;
}

.date-wrap::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  opacity: 0.55;
  background: currentColor;
  -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23fff" d="M19 4h-1V2h-2v2H8V2H6v2H5c-1.1 0-2 .9-2 2v13c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 15H5V9h14v10z"/></svg>');
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%23fff" d="M19 4h-1V2h-2v2H8V2H6v2H5c-1.1 0-2 .9-2 2v13c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 15H5V9h14v10z"/></svg>');
}

.date-picker {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
}

.date-picker.hidden { display: none; }

.date-picker .dp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.date-picker .dp-nav { display: flex; gap: 6px; }

.date-picker .dp-btn {
  appearance: none;
  background: var(--glass-hover);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
}

.date-picker .grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.date-picker .cell {
  text-align: center;
  padding: 8px 0;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 0.875rem;
}

.date-picker .cell:hover { background: var(--glass-hover); }
.date-picker .cell.today { border-color: rgba(106, 163, 255, 0.4); }
.date-picker .cell.muted { color: rgba(154, 163, 181, 0.5); }
.date-picker .cell.selected {
  background: var(--primary-dim);
  border-color: rgba(106, 163, 255, 0.4);
}

.date-picker .weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  color: var(--muted);
  font-size: 0.6875rem;
  margin: 6px 0;
}

/* Animations */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInFromRight {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideInFromLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

.slide-in-left { animation: slideInFromLeft 0.22s ease-out forwards; }
.slide-in-right { animation: slideInFromRight 0.22s ease-out forwards; }

#detailsCard .item .row {
  margin-top: 0;
}

#loadMoreBtn {
  margin-top: 8px;
  min-width: 200px;
}

.voice-block {
  border: 1px solid rgba(76, 141, 255, 0.25);
  background: rgba(76, 141, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 14px;
}

.voice-block .hint {
  margin: 0 0 12px;
}

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  isolation: isolate;
}

.onboarding.hidden {
  display: none;
}

.onboarding-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: rgba(6, 8, 12, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.onboarding-card {
  position: relative;
  z-index: 1;
  max-width: 400px;
  width: 100%;
  padding: 22px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--bg2);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.onboarding-card h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
  color: var(--text);
}

.onboarding-steps {
  margin: 0 0 16px;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.onboarding-steps strong {
  color: var(--text);
}

.onboarding-steps li + li {
  margin-top: 10px;
}

.onboarding-skip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

body.onboarding-open {
  overflow: hidden;
}

body.onboarding-open .app {
  pointer-events: none;
  user-select: none;
}

@media (min-width: 640px) {
  .app-header {
    margin-bottom: 16px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }

  .title {
    font-size: 1.35rem;
  }

  .subtitle {
    font-size: 0.8125rem;
    margin-top: 4px;
  }

  .navbar {
    position: static;
    margin-bottom: 16px;
    padding: 6px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    box-shadow: none;
    backdrop-filter: blur(12px);
  }

  .app {
    padding-top: 12px;
    padding-bottom: 24px;
  }

  #toastsHost {
    padding-bottom: 16px;
  }

  .tab {
    padding: 12px 16px;
    font-size: 0.9375rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .slide-in-left,
  .slide-in-right,
  .tab,
  .btn,
  .item.clickable {
    animation: none;
    transition: none;
  }
}
