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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1e1e1e;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-muted: #888;
  --accent: #25D366;
  --accent-hover: #1fb855;
  --danger: #e54545;
  --warning: #f5a623;
  --success: #25D366;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #111 0%, #0a0a0a 70%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo {
  color: var(--accent);
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.login-card button:hover {
  background: var(--accent-hover);
}

.error {
  background: rgba(229, 69, 69, 0.1);
  border: 1px solid rgba(229, 69, 69, 0.3);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 16px;
  font-size: 14px;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-weight: 600;
  font-size: 16px;
}

.btn-logout {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.2s;
}

.btn-logout:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Dashboard */
.dashboard {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

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

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

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 12px 20px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

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

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover { border-color: var(--text-muted); }

.btn-danger {
  background: none;
  color: var(--danger);
  border: 1px solid rgba(229, 69, 69, 0.3);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover { background: rgba(229, 69, 69, 0.1); }

.btn-small {
  background: none;
  color: var(--accent);
  border: 1px solid rgba(37, 211, 102, 0.3);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.btn-small:hover { background: rgba(37, 211, 102, 0.1); }

/* Add Form */
.add-form {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.add-form input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  flex: 1;
  min-width: 140px;
}

.add-form input:focus { border-color: var(--accent); }

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

.data-table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--surface-2); }

/* Status badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-active { background: rgba(37, 211, 102, 0.15); color: var(--success); }
.badge-inactive { background: rgba(136, 136, 136, 0.15); color: var(--text-muted); }
.badge-completed { background: rgba(37, 211, 102, 0.15); color: var(--success); }
.badge-failed { background: rgba(229, 69, 69, 0.15); color: var(--danger); }
.badge-pending { background: rgba(245, 166, 35, 0.15); color: var(--warning); }
.badge-processing { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }

/* Pagination */
.pagination {
  text-align: center;
  padding: 16px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 { font-size: 16px; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* Media Grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.media-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
  grid-column: 1 / -1;
}

.media-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.media-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.media-time {
  color: var(--text-muted);
  font-size: 12px;
}

.media-card-body {
  padding: 12px;
}

.media-card-body audio {
  width: 100%;
}

.media-card-body video {
  width: 100%;
  max-height: 280px;
  border-radius: 8px;
  background: #000;
}

.media-card-body img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.media-card-body img:hover {
  opacity: 0.85;
}

.media-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px 10px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Chat View */
.chat-container {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  height: 70vh;
  background: var(--surface);
}

.chat-list {
  width: 300px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.chat-list-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.chat-list-header h3 { font-size: 15px; }

.chat-list-items {
  overflow-y: auto;
  flex: 1;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--surface-2); border-left: 3px solid var(--accent); }

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-phone {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-item-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-detail-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.chat-detail-name { font-size: 15px; }
.chat-detail-phone { font-size: 12px; color: var(--text-muted); margin-left: 8px; font-weight: 400; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}

.chat-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 16px;
  font-size: 14px;
}

.chat-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

.chat-bubble.incoming {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble.outgoing {
  align-self: flex-end;
  background: #0b3d20;
  border: 1px solid #1a5c35;
  border-bottom-right-radius: 4px;
}

.chat-bubble-type {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--accent);
}

.chat-bubble-content {
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.chat-bubble-content.expandable {
  cursor: pointer;
}

.chat-bubble-content.collapsed {
  max-height: 100px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, #000 60%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent 100%);
}

.chat-bubble-expand {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  margin-top: 4px;
}

.chat-bubble-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.chat-bubble audio {
  width: 100%;
  max-width: 280px;
}

.chat-bubble video {
  width: 100%;
  max-width: 320px;
  border-radius: 8px;
  background: #000;
}

.chat-bubble img {
  max-width: 280px;
  max-height: 200px;
  border-radius: 8px;
  cursor: pointer;
}

.chat-bubble .badge {
  margin-left: 6px;
  vertical-align: middle;
}

.chat-date-separator {
  text-align: center;
  padding: 8px 0;
}

.chat-date-separator span {
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 8px;
}

/* Responsive */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .add-form { flex-direction: column; }
  .add-form input { width: 100%; }
  .data-table { font-size: 13px; }
  .data-table th, .data-table td { padding: 8px 10px; }
  .chat-container { flex-direction: column; height: 80vh; }
  .chat-list { width: 100%; min-width: unset; max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
  .chat-bubble { max-width: 90%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .dashboard { padding: 16px; }
}
