/**
 * Global styles and CSS variables for Повозка
 * Telegram-inspired dark theme
 */

:root {
  /* Telegram-like dark + умеренный «чёрный» акцент */
  --bg-primary: #0b0d10;
  --bg-secondary: #12151a;
  --bg-tertiary: #1a1e26;
  --bg-hover: #2a2f38;
  --bg-active: #2a2f38;
  --bg-input: #1a1e26;
  --bg-message-out: #2a2e36;
  --bg-message-in: #151920;
  --bg-modal: #12151a;

  --text-primary: #f0f2f5;
  --text-secondary: #8b939e;
  --text-hint: #6b7280;
  --text-link: #a8b0bc;
  --text-accent: #c5cad3;

  --accent: #3a3f4a;
  --accent-hover: #4a5160;
  --accent-green: #4fae4e;
  --online: #4dcd5e;
  --offline: #7d8b99;

  --border: #0b0d10;
  --border-light: #1a1e26;
  --scrollbar: #1a1e26;
  --scrollbar-hover: #2a2f38;

  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-msg: 12px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;

  --sidebar-width: 360px;
  --header-height: 56px;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: none;
  outline: none;
}

img {
  max-width: 100%;
  display: block;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-hover);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 10000;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-success {
  border-left: 4px solid var(--accent-green);
}

.toast-error {
  border-left: 4px solid #e53935;
}

.toast-info {
  border-left: 4px solid var(--accent);
}

/* Avatar styles */
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-placeholder {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(135deg, #5288c1, #3d6a9e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  text-transform: uppercase;
}

/* Status dot */
.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

.status-dot.online {
  background: var(--online);
}

.status-dot.offline {
  background: var(--offline);
  display: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
  transition: background var(--transition), opacity var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-block {
  width: 100%;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  padding: 16px;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-modal);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-overlay.show .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px 20px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Form elements */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid transparent;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-hint);
}

.form-error {
  color: #e53935;
  font-size: 13px;
  margin-top: 6px;
}

/* Loading spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(14, 22, 33, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* Utility */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ========== LIGHT THEME ========== */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f0f2f5;
  --bg-tertiary: #e4e6eb;
  --bg-hover: #d8dce3;
  --bg-active: #c5d0dc;
  --bg-input: #ffffff;
  --bg-message-out: #effdde;
  --bg-message-in: #ffffff;
  --bg-modal: #ffffff;

  --text-primary: #0e1621;
  --text-secondary: #707579;
  --text-hint: #a0a5ab;
  --text-link: #3390ec;
  --text-accent: #3390ec;

  --accent: #3390ec;
  --accent-hover: #1a7ad9;
  --accent-green: #4fae4e;
  --online: #0ac630;
  --offline: #a0a5ab;

  --border: #dfe1e5;
  --border-light: #e7e7e7;
  --scrollbar: #c5c9ce;
  --scrollbar-hover: #a0a5ab;

  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .message.own .msg-bubble {
  background: var(--bg-message-out);
  color: var(--text-primary);
}

[data-theme="light"] .message.own .msg-time {
  color: var(--text-hint);
}

[data-theme="light"] .msg-checks {
  color: var(--text-hint);
}

[data-theme="light"] .msg-checks.read {
  color: #4fae4e;
}

[data-theme="light"] .empty-chat {
  background: var(--bg-primary);
}

/* ========== Telegram-style gift cards ========== */
.gifts-panel { padding: 12px !important; }
.gifts-showcase {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.gifts-showcase::-webkit-scrollbar { height: 4px; }
.gift-card {
  position: relative;
  flex: 0 0 auto;
  width: 112px;
  height: 132px;
  border: none;
  border-radius: 18px;
  background: var(--gift-bg, #2a3340);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s ease;
}
.gift-card:active { transform: scale(0.96); }
.gift-card-nft {
  box-shadow: 0 4px 18px rgba(201, 162, 39, 0.35), inset 0 0 0 1.5px rgba(255, 220, 120, 0.35);
}
.gift-card-light {
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.gift-card-pattern {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  opacity: 0.12;
  font-size: 18px;
  pointer-events: none;
  line-height: 1.6;
  padding: 8px;
  overflow: hidden;
}
.gift-card-pattern::before {
  content: attr(aria-hidden);
}
/* fill pattern via repeated emoji in JS is one char - use CSS dots instead */
.gift-card-pattern {
  background-image: radial-gradient(circle at 20% 30%, rgba(255,255,255,.12) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.1) 0 2px, transparent 3px),
    radial-gradient(circle at 40% 80%, rgba(255,255,255,.08) 0 1.5px, transparent 2.5px);
  background-size: 40px 40px;
  opacity: 1;
  font-size: 0;
}
.gift-card-emoji {
  position: relative;
  z-index: 1;
  font-size: 56px;
  line-height: 1;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.3));
}
.gift-card-corner {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  font-size: 10px;
  font-weight: 700;
  padding: 5px 8px 6px 10px;
  border-radius: 0 18px 0 12px;
  background: rgba(255,255,255,.92);
  color: #1a1a1a;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.gift-card-nft .gift-card-corner {
  background: linear-gradient(135deg, #5b9fff, #3d7dd6);
  color: #fff;
}

/* Detail sheet like TG */
.tg-gift-overlay { font-family: system-ui, -apple-system, sans-serif; }
.tg-gift-sheet {
  width: 100%;
  max-width: 420px;
  max-height: 92vh;
  overflow: auto;
  border-radius: 20px 20px 0 0;
  background: var(--bg-secondary, #17212b);
  color: var(--text-primary, #f5f5f5);
  animation: tgGiftUp .28s ease;
}
@keyframes tgGiftUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.tg-gift-hero {
  position: relative;
  text-align: center;
  padding: 48px 20px 20px;
  border-radius: 20px 20px 0 0;
  min-height: 220px;
}
.tg-gift-x {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.25);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  z-index: 2;
}
.tg-gift-hero-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.15;
  background-image: radial-gradient(circle at 15% 20%, #fff 0 1.5px, transparent 2px),
    radial-gradient(circle at 80% 40%, #fff 0 1.5px, transparent 2px),
    radial-gradient(circle at 40% 75%, #fff 0 1px, transparent 2px);
  background-size: 48px 48px;
  pointer-events: none;
}
.tg-gift-hero-emoji {
  position: relative;
  font-size: 88px;
  line-height: 1;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,.35));
  margin-bottom: 12px;
}
.tg-gift-hero-title {
  position: relative;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.tg-gift-serial {
  font-weight: 600;
  opacity: 0.85;
  font-size: 18px;
}
.tg-gift-hero-sub {
  position: relative;
  margin-top: 4px;
  font-size: 15px;
  color: rgba(255,255,255,.85);
}
.tg-gift-acts {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.tg-gift-act {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 88px;
  padding: 12px 16px;
  border: none;
  border-radius: 16px;
  background: rgba(255,255,255,.22);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tg-gift-act span { font-size: 20px; }
.tg-gift-body {
  padding: 16px 16px 24px;
  background: var(--bg-primary, #0e1621);
}
.tg-gift-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--bg-secondary, #17212b);
  border-radius: 14px;
  overflow: hidden;
  font-size: 14px;
}
.tg-gift-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  vertical-align: top;
}
.tg-gift-table tr:last-child td { border-bottom: none; }
.tg-gift-table td:first-child {
  width: 34%;
  color: var(--text-hint, #8b9bab);
  font-weight: 500;
}
.tg-gift-uid {
  font-size: 11px;
  color: var(--text-hint, #6c7883);
  word-break: break-all;
}
.tg-gift-link { color: #6ab3f3; font-weight: 500; }
.tg-gift-pill {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  background: rgba(106, 179, 243, 0.2);
  color: #6ab3f3;
}
.tg-gift-note {
  margin: 14px 8px;
  font-size: 12px;
  color: var(--text-hint, #6c7883);
  text-align: center;
  line-height: 1.4;
}
.tg-gift-ok {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: #2aabee;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.tg-gift-ok:active { filter: brightness(0.95); }

@media (min-width: 480px) {
  .tg-gift-overlay { align-items: center !important; padding: 16px !important; }
  .tg-gift-sheet { border-radius: 20px; max-height: 88vh; }
}
