:root {
  --primary: #d4838a;
  --primary-dark: #b86670;
  --bg: #faf6f5;
  --sidebar-bg: #2d2426;
  --sidebar-text: #f4e9e8;
  --card-bg: #ffffff;
  --text: #3d2f31;
  --muted: #888;
  --border: #ead8d6;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5d0d4 0%, #faf6f5 100%);
}
.login-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  width: 360px;
}
.login-box h1 {
  margin: 0 0 8px;
  font-size: 22px;
  color: var(--primary-dark);
}
.login-box .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
}

/* Layout with sidebar */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 24px 0;
  flex-shrink: 0;
}
.sidebar .logo {
  padding: 0 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 16px;
  font-weight: 600;
}
.sidebar .nav-item {
  display: block;
  padding: 12px 24px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.2s;
}
.sidebar .nav-item:hover { background: rgba(255,255,255,0.05); }
.sidebar .nav-item.active {
  background: var(--primary);
  color: white;
}

.main {
  flex: 1;
  padding: 32px;
  overflow-x: auto;
}
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.main-header h1 { margin: 0; font-size: 24px; }

/* Cards */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 8px;
}
.card-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--primary-dark);
}

/* Stat grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* Form */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input, .field textarea, .field select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #eee; color: var(--text); }
.btn-secondary:hover { background: #ddd; }
.btn-danger { background: #d9534f; color: white; }
.btn-danger:hover { background: #b94440; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Table */
.table {
  width: 100%;
  background: white;
  border-collapse: collapse;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th {
  background: #f8f0ef;
  font-weight: 600;
  color: var(--text);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover { background: #fcf5f4; }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  background: #e0e0e0;
  color: #555;
}
.badge.active { background: #d4eed4; color: #2d6d2d; }
.badge.inactive { background: #f0d4d4; color: #8a2929; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: white;
  padding: 24px;
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
}
.modal-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #2d2426;
  color: white;
  padding: 12px 20px;
  border-radius: 6px;
  z-index: 200;
  display: none;
}
.toast.show { display: block; animation: slideIn 0.3s; }
.toast.error { background: #d9534f; }
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* Quick reply chips */
.qr-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.qr-chip {
  background: #f0e0e0;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.qr-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}

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

/* Image preview */
.img-preview {
  max-width: 200px;
  max-height: 200px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-top: 8px;
}

/* ===== Wide modal with two-column layout ===== */
.modal-wide {
  max-width: 1100px;
  width: 95%;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
}

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

/* ===== Quick Reply editor ===== */
.qr-editor {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.qr-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qr-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.qr-card-main {
  flex: 1;
  min-width: 0;
}

.qr-card-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.qr-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 11px;
}

.qr-card-value {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.qr-type-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
}
.qr-type-message  { background: #d4eed4; color: #2d6d2d; }
.qr-type-postback { background: #d4dbf0; color: #2d3f80; }
.qr-type-uri      { background: #f0e0d4; color: #804020; }

.qr-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.btn-icon {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover:not(:disabled) { background: #f5f5f5; }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-icon-danger { color: #b94440; }
.btn-icon-danger:hover:not(:disabled) { background: #fee; }

/* Inline QR form */
.qr-form-card {
  background: white;
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 12px;
  margin-top: 8px;
}
.qr-form-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.qr-form-card input, .qr-form-card select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

/* ===== LINE phone preview ===== */
.preview-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}

.phone-mockup {
  background: #7a90b0;
  border-radius: 24px;
  padding: 12px 8px 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.phone-header {
  background: white;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  color: #333;
  margin-bottom: 8px;
}

.phone-body {
  background: #8da4c1;
  min-height: 360px;
  border-radius: 4px;
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  padding: 10px 12px;
  border-radius: 12px;
  max-width: 78%;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bot-bubble {
  background: white;
  align-self: flex-start;
  color: #333;
}

.bubble-image {
  max-width: 100%;
  border-radius: 6px;
  display: block;
}

.qr-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  padding: 0 4px;
}

.qr-chip-preview {
  background: white;
  color: #2c5282;
  border: 1px solid #cbd5e0;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
