/* Theme */
:root { --bg: #0e0f12; --fg: #e8e8f0; --muted: #a0a3ad; --card: #171a20; --accent: #ff3b81; --ok: #38d39f; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
/* Prevent layout shift when vertical scrollbar appears/disappears */
html { scrollbar-gutter: stable; }
a { color: #8ab4ff; text-decoration: none; }
a:hover { text-decoration: underline; }
button, .btn { transition: background 0.15s ease, border-color 0.15s ease; }
button:hover, .btn:hover { background: #151a24; border-color: #34384a; }
input::placeholder { color: #6e7380; }
/* Layout */
header { padding: 24px; text-align: center; border-bottom: 1px solid #242633; }
header h1 { margin: 0 0 8px 0; font-size: 28px; }
header p { margin: 0; color: var(--muted); }
main { max-width: 980px; margin: 0 auto; padding: 16px; }
/* Auth page */
.auth-center { display: flex; flex-direction: column; gap: 0; align-items: stretch; justify-content: center; padding: 0; margin: 32px auto; width: 100%; max-width: 540px; background: var(--card); border: 1px solid #2a2d3a; border-radius: 16px; box-shadow: 0 18px 50px rgba(0,0,0,0.35); overflow: hidden; }
.authorized .tg-auth { display: none !important; }
.authorized .topbar { display: flex; }

/* Auth card */
.card .segment { padding: 20px 20px; border-bottom: 1px solid #242633; }
.card .segment:last-child { border-bottom: 0; }
.card .segment.header { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 24px; background: linear-gradient(180deg, rgba(26,29,39,0.6), rgba(23,26,32,0.1)); }
.card .segment.footer { background: #151822; }
.logo-badge { width: 60px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 44px; }
.card h2 { margin: 0; font-size: 22px; }
.card .text { margin: 0; color: var(--muted); }
.list-wrap { background: #12141b; border: 1px solid #242633; border-radius: 12px; padding: 12px; margin: 12px 0 16px; }
.list-title { font-weight: 600; margin-bottom: 6px; }
.list { margin: 0; padding-left: 18px; color: var(--muted); }
.list li { margin: 4px 0; }
.list-note { color: var(--muted); font-size: 13px; margin-top: 8px; }
.widget { display: flex; align-items: center; justify-content: center; padding-top: 12px; }

/* Keep Telegram widget centered and stable in width */
.widget { width: 100%; display: flex; justify-content: center; align-items: center; }
.tg-login-wrap { display: flex; align-items: center; justify-content: center; width: 100%; text-align: center; }
.tg-login-wrap { max-width: 320px; min-width: 260px; margin: 0 auto; }
.tg-login-wrap iframe, .tg-login-wrap > * { margin: 0 auto !important; display: block; }
.topbar { position: sticky; top: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #242633; background: rgba(14,15,18,0.8); backdrop-filter: blur(6px);z-index: 99999; }
.user-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; margin-right: auto; border-radius: 999px; background: linear-gradient(180deg, #181b24, #12141b); border: 1px solid #272a37; color: var(--fg); font-weight: 600; font-size: 13px; box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 6px 18px rgba(0,0,0,0.25); }
.user-badge .avatar { width: 20px; height: 20px; border-radius: 50%; border: 1px solid #2a2d3a; object-fit: cover; background: #111318; display: none; }
.user-badge .placeholder { width: 20px; height: 20px; border-radius: 50%; border: 1px solid #2a2d3a; background: #0b0c0f; }
.user-badge .name { font-weight: 600; }
.logout { cursor: pointer; padding: 8px 10px; border-radius: 8px; border: 1px solid #2a2d3a; background: #11131a; color: var(--fg); }
.quota { background: #12141b; border: 1px solid #242633; border-radius: 12px; padding: 10px 12px; display: inline-flex; gap: 8px; align-items: center; }
.quota .pill { background: #1a1d27; border: 1px solid #2a2d3a; border-radius: 999px; padding: 4px 8px; font-size: 12px; color: var(--muted); }

/* Topbar quota badge */
.quota-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; margin-right: auto; border-radius: 999px; background: linear-gradient(180deg, #181b24, #12141b); border: 1px solid #272a37; color: var(--fg); font-weight: 600; font-size: 13px; box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 6px 18px rgba(0,0,0,0.25); }
.quota-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(56,211,159,0.15); }
.quota-badge .text { opacity: 0.9; }
.quota-badge .count { background: #1a1d27; border: 1px solid #2a2d3a; border-radius: 8px; padding: 2px 6px; font-size: 12px; color: var(--muted); }
.controls { display: flex;  align-items: center; margin-bottom: 16px; }
#search { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid #2a2d3a; background: #0f1116; color: var(--fg); }
#emp_search { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid #2a2d3a; background: #0f1116; color: var(--fg); }
#stats_month { padding: 10px 12px; border-radius: 8px; border: 1px solid #2a2d3a; background: #0f1116; color: var(--fg); min-width: 160px; }
.status { min-height: 24px; color: var(--muted); }
.mtproto { margin: 16px 0 24px; border: 1px solid #242633; border-radius: 12px; padding: 12px; background: #12141b; }
.mtproto h2 { margin: 0 0 12px 0; font-size: 18px; }
.mtproto .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-bottom: 8px; }
.mtproto .row { display: flex; gap: 8px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.mtproto label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.mtproto input { padding: 8px 10px; border-radius: 8px; border: 1px solid #2a2d3a; background: #0f1116; color: var(--fg); min-width: 220px; }
.log { background: #0f1116; color: var(--muted); border: 1px solid #2a2d3a; padding: 10px; border-radius: 8px; max-height: 200px; overflow: auto; }
/* Employee list */
.employees { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.emp { background: var(--card); border: 1px solid #242633; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.emp .row { display: flex; gap: 12px; align-items: center; }
.photo-wrap { position: relative; width: 48px; height: 48px; }
.emp img.photo.img { position: absolute; inset: 0; width: 48px; height: 48px; border-radius: 50%; border: 1px solid #2a2d3a; object-fit: cover; background: #111318; display: none; }
.emp .photo.placeholder { width: 48px; height: 48px; border-radius: 50%; border: 1px solid #2a2d3a; background: #0b0c0f; }
.emp .name { font-weight: 600; }
.emp .meta { color: var(--muted); font-size: 13px; }
.name.editable { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.name.editable .name-input { padding: 8px 10px; border-radius: 8px; border: 1px solid #2a2d3a; background: #0f1116; color: var(--fg); }
.name.editable .save-name { padding: 8px 10px; }
.actions { display: flex; gap: 8px; align-items: center; }
.cooldown { margin-left: auto; color: var(--muted); font-size: 12px; min-width: 62px; text-align: right; }
.emp.cooling::after { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,0.55); border-radius: 12px; }
.emp { position: relative; }
.cooldown-overlay { position: absolute; inset: 0; display: none; justify-content: center; text-align: center; }
.emp.cooling .cooldown-overlay { display: flex; }
.cooldown-box { background: rgba(21,24,34,0.95); border: 1px solid #2a2d3a; border-radius: 12px; padding: 16px 14px; color: var(--fg); box-shadow: 0 12px 30px rgba(0,0,0,0.35); }
.cooldown-title { font-weight: 700; margin-bottom: 8px; }
.cooldown-time { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 18px; }
.btn { cursor: pointer; padding: 8px 10px; border-radius: 8px; border: 1px solid #2a2d3a; background: #11131a; color: var(--fg); }
.btn.thanks { background: #131821; border-color: #2a2d3a; }
.btn.thanks::before { content: '❤️ '; }
.btn.primary { background: var(--accent); border-color: #ff5f96; color: #fff; }
.btn.primary:hover { background: #ff4b8b; border-color: #ff7aa8; }
/* Toast */
.toast { position: fixed; right: 16px; bottom: 16px; background: #151822; border: 1px solid #2a2d3a; color: var(--fg); padding: 12px 14px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.35); display: none; }
.toast.show { display: block; }
footer { max-width: 980px; margin: 12px auto 32px; padding: 0 16px; color: var(--muted); }

/* Admin UI */
.tabs { display: flex; gap: 12px; align-items: center; justify-content: center; }
.tabs a { padding: 8px 10px; border-radius: 8px; border: 1px solid #2a2d3a; background: #11131a; color: var(--fg); }
.tabs a:hover { background: #151a24; border-color: #34384a; }


/* Quota banner */
.quota-banner { margin: 12px auto 8px; max-width: 980px; padding: 12px 16px; border-radius: 14px; border: 1px solid #272a37; background: linear-gradient(180deg, #181b24, #12141b); color: var(--fg); display: flex; align-items: center; gap: 12px; box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 10px 30px rgba(0,0,0,0.25); }
.quota-banner .badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: #1a1d27; border: 1px solid #2a2d3a; font-weight: 600; color: var(--muted); }
.quota-banner .strong { font-weight: 700; color: var(--fg); }
.quota-banner .spacer { flex: 1; }
.quota-banner .progress { height: 8px; flex: 1.5; background: #0f131b; border: 1px solid #242633; border-radius: 999px; overflow: hidden; }
.quota-banner .bar { height: 100%; background: linear-gradient(90deg,#da4bf3, #7755ff); width: 0%; }

/* Mobile adjustments */
@media (max-width: 420px) {
  main { padding: 12px; }
  .quota-banner { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px; }
  .quota-banner .badge { align-self: flex-start; font-size: 12px; padding: 4px 8px; }
  .quota-banner .strong { font-size: 14px; line-height: 1.3; }
  .quota-banner .spacer { display: none; }
  .quota-banner .progress { flex: none; width: 100%; height: 6px; }
}

/* Modal */
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 100000; }
.modal.open { display: flex; }
.modal .backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); }
.modal .dialog { position: relative; width: min(92vw, 520px); background: var(--card); border: 1px solid #2a2d3a; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,0.45); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.modal .header { display: flex; align-items: center; justify-content: space-between; }
.modal .title { margin: 0; font-size: 18px; }
.modal .btn.icon { width: 32px; height: 32px; padding: 0; display: grid; place-items: center; font-size: 20px; line-height: 1; border: none; }
.modal .body { display: flex; flex-direction: column; gap: 10px; }
.modal .recipient { color: var(--muted); font-size: 14px; }
.modal textarea { width: 100%; min-height: 110px; resize: vertical; padding: 10px 12px; border-radius: 10px; border: 1px solid #2a2d3a; background: #0f1116; color: var(--fg); }
.modal .hint { color: var(--muted); font-size: 12px; }
.modal .footer { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
@media (max-width: 420px) {
  .modal .dialog { width: calc(100vw - 24px); padding: 12px; }
}

/* Admin stats */
.stats-block { background: #12141b; border: 1px solid #242633; border-radius: 12px; padding: 12px; }
.stats-title { font-weight: 700; margin: 0 0 8px 0; }
.toplist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.topitem { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: center; background: var(--card); border: 1px solid #242633; border-radius: 10px; padding: 8px 10px; }
.topitem .left { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-start; }
.topitem .cnt { display: inline-block; min-width: 28px; text-align: right; font-weight: 800; }
.topitem .heart { opacity: 0.9; }
.topitem .right { display: inline; }
.person { display: inline-flex; align-items: center; gap: 6px; margin-right: 8px; }
.person .avatar.ph { width: 18px; height: 18px; border-radius: 50%; border: 1px solid #2a2d3a; background: #0b0c0f; }
.person img.avatar.img { width: 18px; height: 18px; border-radius: 50%; border: 1px solid #2a2d3a; object-fit: cover; display: none; background: #111318; }
.person .nm { white-space: nowrap; }

/* Admin filters */
#thanks_from, #thanks_to, #thanks_sender, #thanks_recipient {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #2a2d3a;
  background: #0f1116;
  color: var(--fg);
}
#thanks_sender, #thanks_recipient { min-width: 220px; }

/* Mobile-friendly filters for admin thanks */
@media (max-width: 640px) {
  #view_thanks .controls { flex-wrap: wrap; align-items: stretch; }
  #view_thanks .controls label { display: block; width: 100%; margin-top: 6px; }
  #thanks_from, #thanks_to, #thanks_sender, #thanks_recipient, #reload_thanks {
    flex: 1 1 100%;
    min-width: 0;
  }
  #thanks_sender, #thanks_recipient { min-width: 0; }
}

/* Analytics styles */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.analytics-card {
  background: var(--card);
  border: 1px solid #242633;
  border-radius: 12px;
  padding: 16px;
}

.analytics-title {
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--fg);
}

.analytics-content {
  color: var(--muted);
  font-size: 14px;
}

/* Export styles */
.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.export-card {
  background: var(--card);
  border: 1px solid #242633;
  border-radius: 12px;
  padding: 16px;
}

.export-title {
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--fg);
}

.export-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.form-group input,
.form-group select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #2a2d3a;
  background: #0f1116;
  color: var(--fg);
}

.form-group input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.form-group label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  flex-direction: row;
}

/* Settings styles */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.settings-card {
  background: var(--card);
  border: 1px solid #242633;
  border-radius: 12px;
  padding: 16px;
}

.settings-title {
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--fg);
}

.settings-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Content styles */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.content-card {
  background: var(--card);
  border: 1px solid #242633;
  border-radius: 12px;
  padding: 16px;
}

.content-title {
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--fg);
}

.content-content textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #2a2d3a;
  background: #0f1116;
  color: var(--fg);
  resize: vertical;
  min-height: 80px;
}

/* Analytics specific styles */
#total_stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat-item {
  text-align: center;
  padding: 12px;
  background: #0f1116;
  border: 1px solid #242633;
  border-radius: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

#daily_activity {
  max-height: 200px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #242633;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-date {
  font-weight: 600;
}

.activity-count {
  background: var(--accent);
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

#top_recipients,
#top_senders {
  max-height: 300px;
  overflow-y: auto;
}

.top-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #242633;
}

.top-item:last-child {
  border-bottom: none;
}

.top-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid #2a2d3a;
  object-fit: cover;
}

.top-count {
  background: var(--accent);
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .analytics-grid,
  .export-grid,
  .settings-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }
  
  .tabs {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .tabs a {
    font-size: 13px;
    padding: 6px 8px;
  }
  
  #total_stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .analytics-card,
  .export-card,
  .settings-card,
  .content-card {
    padding: 12px;
  }
  
  #total_stats {
    grid-template-columns: 1fr;
  }
  
  .form-group input,
  .form-group select {
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

/* Texts styles */
.texts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.texts-category {
  background: var(--card);
  border: 1px solid #242633;
  border-radius: 12px;
  padding: 16px;
}

.texts-category-title {
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--fg);
  font-size: 16px;
}

.texts-category-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.texts-category-content .form-group {
  margin: 0;
}

.texts-category-content .form-group label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.texts-category-content .form-group input,
.texts-category-content .form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #2a2d3a;
  background: #0f1116;
  color: var(--fg);
  font-size: 13px;
}

.texts-category-content .form-group textarea {
  resize: vertical;
  min-height: 60px;
}

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