:root {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242b;
  --border: #2a2f38;
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --accent: #4f8cff;
  --accent-hover: #3a7aee;
  --danger: #ff5c5c;
  --success: #24e08a;
  --warning: #fbbc04;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

button {
  appearance: none;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:hover {
  background: var(--border);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

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

button.danger {
  background: rgba(255, 92, 92, 0.15);
  color: var(--danger);
}

button.danger:hover {
  background: rgba(255, 92, 92, 0.25);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input, textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  width: 100%;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

textarea {
  resize: none;
  min-height: 48px;
  max-height: 160px;
  field-sizing: content;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Login */
.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  padding: 32px;
}

.login-box h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.login-box p {
  margin: 0 0 24px;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 16px;
}

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

.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
}

.success {
  color: var(--success);
  font-size: 13px;
  margin-top: 8px;
}

/* Chat */
.chat-layout {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.chat-header .brand {
  font-weight: 700;
  font-size: 17px;
}

.chat-header .user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: min(720px, 92%);
  padding: 14px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .meta {
  font-size: 11px;
  opacity: 0.65;
  margin-top: 6px;
}

.message-text a {
  color: inherit;
  text-decoration: underline;
}

.message-text img.chat-image {
  max-width: 100%;
  max-height: 240px;
  border-radius: 10px;
  margin-top: 8px;
  display: block;
}

.attachments {
  margin-bottom: 10px;
}

.attachment {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  margin-bottom: 6px;
}

.attachment a {
  color: inherit;
  font-weight: 500;
}

.ocr-note {
  font-size: 11px;
  opacity: 0.7;
}

.typing {
  align-self: flex-start;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.typing-dots span {
  animation: blink 1.4s infinite both;
  font-size: 18px;
  line-height: 0;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

.chat-input {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 900px;
  margin: 0 auto;
}

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.attach-btn {
  height: 48px;
  width: 48px;
  padding: 0;
  font-size: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-input textarea {
  flex: 1;
}

.chat-input button.primary {
  height: 48px;
  padding: 0 20px;
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
}

.attachment-chip .remove-attachment {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
}

.attachment-chip .remove-attachment:hover {
  background: rgba(255, 92, 92, 0.3);
}

.drop-zone {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.9);
  display: grid;
  place-items: center;
  z-index: 50;
  border: 4px dashed var(--accent);
}

.drop-zone span {
  font-size: 24px;
  color: var(--accent);
  font-weight: 600;
}

/* Admin */
.admin-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.admin-main {
  flex: 1;
  padding: 20px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar input, .toolbar select {
  width: auto;
  min-width: 160px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.badge.admin { background: rgba(79, 140, 255, 0.15); color: var(--accent); }
.badge.user { background: var(--surface-2); color: var(--text-muted); }
.badge.active { background: rgba(36, 224, 138, 0.12); color: var(--success); }
.badge.blocked { background: rgba(255, 92, 92, 0.12); color: var(--danger); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  width: min(520px, 100%);
  padding: 24px;
}

.modal h2 {
  margin: 0 0 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.hidden {
  display: none !important;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

@media (max-width: 640px) {
  .chat-header, .admin-header {
    padding: 10px 14px;
  }

  .chat-messages {
    padding: 14px;
  }

  .message {
    max-width: 96%;
  }

  .input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .attach-btn {
    width: 100%;
    border-radius: 10px;
  }

  .chat-input button.primary {
    width: 100%;
  }

  table, thead, tbody, th, td, tr {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
  }

  td {
    border: none;
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
  }

  td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 600;
  }
}
