* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f2f5; color: #333; }
.hidden { display: none !important; }

/* Login */
#login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1a1f36 0%, #2d3561 100%); }
.login-box { background: #fff; padding: 40px; border-radius: 12px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-box h1 { font-size: 22px; margin-bottom: 8px; color: #1a1f36; }
.login-box p { color: #888; margin-bottom: 24px; font-size: 14px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: #555; }
.form-group input { width: 100%; padding: 10px 14px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; }
.form-group input:focus { outline: none; border-color: #4f6ef7; }
.btn { padding: 10px 20px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; transition: .2s; }
.btn-primary { background: #4f6ef7; color: #fff; width: 100%; }
.btn-primary:hover { background: #3b5de7; }
.btn-success { background: #22c55e; color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-outline { background: transparent; border: 1px solid #ddd; color: #555; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.error-msg { color: #ef4444; font-size: 13px; margin-top: 8px; }

/* Layout */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: #1a1f36; color: #fff; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-header h2 { font-size: 16px; font-weight: 600; }
.sidebar-header span { font-size: 11px; color: #8892b0; letter-spacing: 1px; }
.nav-section { padding: 16px 12px 8px; font-size: 11px; color: #8892b0; text-transform: uppercase; letter-spacing: .5px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; margin: 2px 8px; border-radius: 8px; cursor: pointer; color: #ccd6f6; font-size: 14px; transition: .2s; }
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: #4f6ef7; color: #fff; }
.sidebar-footer { margin-top: auto; padding: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer .user { font-size: 13px; color: #8892b0; margin-bottom: 8px; }

.main { flex: 1; overflow: auto; }
.page-header { padding: 24px 32px 16px; background: #fff; border-bottom: 1px solid #e8e8e8; }
.page-header h1 { font-size: 22px; font-weight: 600; }
.page-header p { color: #888; font-size: 13px; margin-top: 4px; }
.page-content { padding: 24px 32px; }

/* Cards */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stat-card .label { font-size: 13px; color: #888; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; color: #1a1f36; }

.card { background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 20px; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

/* Table */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }
.search-input { padding: 8px 14px; border: 1px solid #ddd; border-radius: 8px; width: 280px; font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px 16px; background: #f8f9fb; font-size: 12px; color: #888; font-weight: 600; border-bottom: 1px solid #eee; }
td { padding: 12px 16px; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
tr:hover td { background: #fafbfc; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #16a34a; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-gray { background: #f3f4f6; color: #6b7280; }
.badge-blue { background: #dbeafe; color: #2563eb; }

.action-btns { display: flex; gap: 6px; }
.action-btn { width: 32px; height: 32px; border: 1px solid #e5e7eb; border-radius: 6px; background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; transition: .2s; }
.action-btn:hover { background: #f3f4f6; border-color: #4f6ef7; }
.link-btn { border: none; background: none; color: #4f6ef7; cursor: pointer; font-size: 13px; padding: 0; text-decoration: underline; }
.link-btn:hover { color: #3d5ce6; }

/* Toggle */
.toggle-row { display: flex; justify-content: space-between; align-items: center; }
.toggle { position: relative; width: 48px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; inset: 0; background: #ccc; border-radius: 26px; cursor: pointer; transition: .3s; }
.toggle .slider:before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .3s; }
.toggle input:checked + .slider { background: #4f6ef7; }
.toggle input:checked + .slider:before { transform: translateX(22px); }

/* Bot cards */
.bot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.bot-card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid #eee; }
.bot-card h3 { font-size: 15px; margin-bottom: 8px; }
.bot-card .meta { font-size: 12px; color: #888; margin-bottom: 12px; }
.bot-card .token-field { background: #f8f9fb; padding: 8px 12px; border-radius: 6px; font-family: monospace; font-size: 12px; margin-bottom: 12px; word-break: break-all; }
.bot-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Template preview */
.template-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.template-card { background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.template-card .preview { background: #e8edf5; padding: 20px; min-height: 200px; }
.template-card .preview .chat {
  background: #fff;
  border-radius: 12px;
  padding: 0;
  max-width: 280px;
  margin: 0 auto;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  overflow: hidden;
}
.template-card .preview .chat .preview-img-wrap {
  width: 100%;
  margin: 0;
  line-height: 0;
  overflow: hidden;
  background: #dbe3ef;
}
.template-card .preview .chat .preview-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 200px;
  object-fit: contain;
  object-position: center center;
  margin: 0;
  border-radius: 0;
  background: #fff;
}
.template-card .preview .chat .preview-img-placeholder {
  font-size: 12px;
  color: #888;
  background: #f0f2f5;
  padding: 28px 12px;
  text-align: center;
  line-height: 1.4;
}
.template-card .preview .chat .msg {
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
  padding: 12px 16px 0;
}
.template-card .preview .chat .btn-preview {
  display: block;
  text-align: center;
  padding: 8px;
  background: #4f6ef7;
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  margin: 12px 16px 16px;
}
.template-card .preview .chat .preview-meta {
  margin: 0 16px 12px;
  font-size: 11px;
  color: #888;
}
.template-card .info { padding: 16px; }
.template-card .info h4 { font-size: 14px; margin-bottom: 8px; }
.template-card .info .detail { font-size: 12px; color: #888; line-height: 1.8; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: #fff; border-radius: 12px; padding: 24px; width: 480px; max-width: 90vw; max-height: 85vh; overflow-y: auto; }
.modal h3 { margin-bottom: 16px; }
.modal .form-group { margin-bottom: 12px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Device config */
.device-card { border-top: 3px solid #4f6ef7; }
.device-value { font-size: 20px; font-weight: 600; margin: 8px 0; }
.device-desc { font-size: 13px; color: #888; line-height: 1.6; }
.device-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; padding-top: 16px; border-top: 1px solid #f0f0f0; }

/* Info banner */
.info-banner { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; padding: 12px 16px; font-size: 13px; color: #1e40af; margin-bottom: 16px; line-height: 1.6; }

/* Contacts page */
.breadcrumb { font-size: 13px; color: #888; margin-bottom: 8px; }
.contact-stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 20px; }
.contact-stat { background: #fff; border-radius: 8px; padding: 12px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.contact-stat .num { font-size: 20px; font-weight: 700; }
.contact-stat .lbl { font-size: 11px; color: #888; }

/* Quick select */
.quick-select { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.quick-btn { padding: 4px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 11px; cursor: pointer; background: #f8f9fb; }
.quick-btn:hover { border-color: #4f6ef7; color: #4f6ef7; }

/* Toast */
.app-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 2000;
  min-width: 180px;
  max-width: 360px;
  padding: 14px 22px;
  border-radius: 10px;
  color: #fff;
  font-size: 15px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.22);
  opacity: 0;
  transform: translate(-50%, -46%);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.app-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}
.app-toast.success { background: #16a34a; }
.app-toast.error { background: #dc2626; }

@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .template-grid { grid-template-columns: 1fr; }
  .sidebar { width: 200px; }
}
