/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: #f5f7fa; color: #1a1a2e; min-height: 100vh; }
a { color: inherit; text-decoration: none; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.loading { text-align: center; padding: 2rem; color: #888; }
.error-msg { background: #fee2e2; border: 1px solid #fca5a5; border-radius: 6px; padding: 0.5rem 1rem; color: #991b1b; font-size: 0.875rem; margin-bottom: 0.75rem; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem; border: none; border-radius: 8px; padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: all 0.15s; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #4338ca; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover:not(:disabled) { background: #d97706; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #4b5563; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-outline { background: transparent; border: 1px solid #d1d5db; color: #374151; }
.btn-outline:hover:not(:disabled) { background: #f3f4f6; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }

/* ── Navbar ───────────────────────────────────────────────────────────────── */
.navbar { background: #fff; border-bottom: 1px solid #e5e7eb; padding: 0 1.5rem; position: sticky; top: 0; z-index: 100; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.navbar-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 0.875rem 0; }
.navbar-brand { font-weight: 700; font-size: 1.125rem; color: #4f46e5; display: flex; align-items: center; gap: 0.5rem; }
.navbar-user { display: flex; align-items: center; gap: 0.75rem; font-size: 0.875rem; color: #6b7280; }
.nav-back { color: #6b7280; margin-right: 0.25rem; }
.nav-back:hover { color: #4f46e5; }

/* ── Container ────────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

/* ── Page Header ──────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.page-header h2 { font-size: 1.25rem; font-weight: 600; }

/* ── Login Page ───────────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-container { width: 100%; max-width: 400px; padding: 1rem; }
.login-card { background: #fff; border-radius: 16px; padding: 2.5rem; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.login-card h1 { text-align: center; font-size: 1.75rem; margin-bottom: 0.25rem; }
.subtitle { text-align: center; color: #6b7280; font-size: 0.875rem; margin-bottom: 1.75rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.375rem; color: #374151; }
.form-group input { width: 100%; padding: 0.625rem 0.875rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.9375rem; outline: none; transition: border-color 0.15s; }
.form-group input:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }

/* ── Conversation Cards ───────────────────────────────────────────────────── */
.conversations-list { display: flex; flex-direction: column; gap: 0.75rem; }
.conv-card { background: #fff; border-radius: 12px; padding: 1.125rem 1.25rem; border: 1px solid #e5e7eb; cursor: pointer; transition: all 0.15s; display: flex; align-items: center; gap: 1rem; }
.conv-card:hover { border-color: #4f46e5; box-shadow: 0 2px 8px rgba(79,70,229,0.12); transform: translateY(-1px); }
.conv-avatar { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }
.conv-avatar.whatsapp { background: #d1fae5; }
.conv-avatar.instagram { background: #fce7f3; }
.conv-avatar.messenger { background: #dbeafe; }
.conv-body { flex: 1; min-width: 0; }
.conv-title { font-weight: 600; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { font-size: 0.8125rem; color: #6b7280; margin-top: 0.2rem; }
.conv-badges { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { padding: 0.25rem 0.625rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-taken { background: #dbeafe; color: #1e40af; }
.badge-closed { background: #d1fae5; color: #065f46; }
.badge-handoff { background: #fee2e2; color: #991b1b; }
.badge-bot { background: #f3f4f6; color: #374151; }

/* ── Search page ─────────────────────────────────────────────────────────────── */
.search-box { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 1.25rem 1.5rem 1rem; margin-bottom: 1.5rem; }
.search-input-row { display: flex; gap: 0.75rem; align-items: center; }
.search-input { flex: 1; padding: 0.625rem 0.875rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.9375rem; outline: none; transition: border-color 0.15s; font-family: inherit; }
.search-input:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.search-channel-select { padding: 0.625rem 0.875rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.875rem; background: #fff; outline: none; cursor: pointer; transition: border-color 0.15s; width: auto; flex-shrink: 0; }
.search-channel-select:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.search-hint { font-size: 0.8125rem; color: #9ca3af; margin-top: 0.75rem; }
.search-hint code { background: #f3f4f6; border-radius: 4px; padding: 0.1rem 0.35rem; font-size: 0.8rem; color: #374151; }
.conv-snippet { font-size: 0.8rem; color: #6b7280; margin-top: 0.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 400px; }
@media (max-width: 640px) { .search-input-row { flex-wrap: wrap; } .search-channel-select { width: 100%; } }

/* ── Inventory module ───────────────────────────────────────────────────────── */
.inv-tabs { display: flex; gap: 0.25rem; margin-bottom: 1.25rem; background: #f3f4f6; border-radius: 10px; padding: 0.25rem; width: fit-content; }
.inv-tab { background: transparent; border: none; padding: 0.5rem 1.25rem; border-radius: 8px; font-size: 0.875rem; font-weight: 500; cursor: pointer; color: #6b7280; transition: all 0.15s; }
.inv-tab.active { background: #fff; color: #4f46e5; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.inv-tab:hover:not(.active) { color: #374151; }
.inv-panel { }
.panel-toolbar { display: flex; justify-content: flex-end; margin-bottom: 1rem; }
.inv-stock-val { font-weight: 600; }
.inv-stock-low { color: #dc2626; }
.inv-stock-toggle { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.375rem; }
.inv-stock-option { flex: 1; min-width: 180px; border: 1px solid #e5e7eb; border-radius: 10px; padding: 0.75rem 1rem; cursor: pointer; display: flex; flex-direction: column; gap: 0.2rem; transition: border-color 0.15s, background 0.15s; }
.inv-stock-option:has(input:checked) { border-color: #4f46e5; background: #eef2ff; }
.inv-stock-option input { display: none; }
.inv-stock-option span { font-size: 0.875rem; font-weight: 600; }
.inv-stock-option small { font-size: 0.78rem; color: #6b7280; }
.recipe-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.recipe-row select { flex: 1; padding: 0.5rem 0.75rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.875rem; background: #fff; }
.recipe-qty-input { width: 90px; padding: 0.5rem 0.75rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.875rem; }
.recipe-unit-label { font-size: 0.8125rem; color: #6b7280; min-width: 55px; }

/* ── Empty / Error State ──────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem; color: #6b7280; font-size: 1rem; }

/* ── Detail Layout ────────────────────────────────────────────────────────── */
.detail-layout { display: grid; grid-template-columns: 300px 1fr; gap: 1.5rem; height: calc(100vh - 68px); overflow: hidden; }
.detail-sidebar { display: flex; flex-direction: column; gap: 1rem; overflow-y: auto; padding-right: 0.25rem; }

/* ── Meta Card ────────────────────────────────────────────────────────────── */
.meta-card { background: #fff; border-radius: 12px; padding: 1.25rem; border: 1px solid #e5e7eb; }
.meta-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.875rem; }
.meta-row { display: flex; justify-content: space-between; font-size: 0.8125rem; padding: 0.375rem 0; border-bottom: 1px solid #f3f4f6; }
.meta-row:last-child { border-bottom: none; }
.meta-label { color: #6b7280; }
.meta-value { font-weight: 500; max-width: 170px; text-align: right; word-break: break-word; }

/* ── Action Buttons ───────────────────────────────────────────────────────── */
.action-buttons { display: flex; flex-direction: column; gap: 0.5rem; }

/* ── Timeline ─────────────────────────────────────────────────────────────── */
.timeline-section { background: #fff; border-radius: 12px; padding: 1.25rem; border: 1px solid #e5e7eb; }
.timeline-section h4 { font-size: 0.875rem; font-weight: 600; color: #374151; margin-bottom: 0.75rem; }
.timeline-item { display: flex; gap: 0.625rem; margin-bottom: 0.625rem; font-size: 0.8125rem; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: #4f46e5; flex-shrink: 0; margin-top: 4px; }
.timeline-content { flex: 1; }
.timeline-status { font-weight: 600; text-transform: capitalize; }
.timeline-time { color: #9ca3af; font-size: 0.75rem; }

/* ── Chat History ─────────────────────────────────────────────────────────── */
.detail-main { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.chat-history { flex: 1; overflow-y: auto; padding: 1rem; background: #fff; border-radius: 12px 12px 0 0; border: 1px solid #e5e7eb; border-bottom: none; min-height: 0; }
.msg { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.msg.user { flex-direction: row; }
.msg.assistant, .msg.agent { flex-direction: row-reverse; }
.msg-bubble { max-width: 70%; padding: 0.625rem 0.875rem; border-radius: 12px; font-size: 0.875rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.msg.user .msg-bubble { background: #f3f4f6; border-bottom-left-radius: 4px; }
.msg.assistant .msg-bubble { background: #4f46e5; color: #fff; border-bottom-right-radius: 4px; }
.msg.agent .msg-bubble { background: #059669; color: #fff; border-bottom-right-radius: 4px; }
.msg-bubble.msg-media { display: flex; flex-direction: column; gap: 0.375rem; }
.media-thumb { max-width: 220px; max-height: 220px; border-radius: 8px; cursor: pointer; object-fit: cover; }
.media-placeholder { font-size: 0.8125rem; opacity: 0.75; }
.msg-meta { font-size: 0.6875rem; color: #9ca3af; margin-top: 0.25rem; }
.msg.user .msg-meta { text-align: left; }
.msg.assistant .msg-meta, .msg.agent .msg-meta { text-align: right; }
.msg-sender { font-size: 0.6875rem; font-weight: 600; color: #6b7280; margin-bottom: 0.125rem; }
.msg.assistant .msg-sender, .msg.agent .msg-sender { text-align: right; }

/* ── Message Input ────────────────────────────────────────────────────────── */
.message-input-area { background: #fff; border-radius: 0 0 12px 12px; border: 1px solid #e5e7eb; padding: 1rem; flex-shrink: 0; }
.message-input-row { display: flex; gap: 0.75rem; align-items: flex-end; }
.message-input-row textarea { flex: 1; border: 1px solid #d1d5db; border-radius: 8px; padding: 0.625rem 0.875rem; font-size: 0.875rem; resize: none; outline: none; transition: border-color 0.15s; font-family: inherit; }
.message-input-row textarea:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }

/* ── Hamburger button ─────────────────────────────────────────────────────── */
.navbar-hamburger {
  display: none;
  background: none;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.375rem 0.5rem;
  cursor: pointer;
  font-size: 1.125rem;
  color: #374151;
  line-height: 1;
  margin-left: auto;
}
.navbar-hamburger:hover { background: #f3f4f6; }

/* ── Responsive: Tablet & Mobile (≤ 768px) ────────────────────────────────── */
@media (max-width: 768px) {
  /* Container padding tighter */
  .container { padding: 1rem 0.875rem; }

  /* Page header: allow wrapping */
  .page-header { flex-wrap: wrap; gap: 0.5rem; }

  /* Navbar: hamburger visible, nav items collapse */
  .navbar { padding: 0 1rem; }
  .navbar-inner { padding: 0.75rem 0; flex-wrap: wrap; gap: 0; }
  .navbar-hamburger { display: inline-flex; align-items: center; }
  .navbar-user {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.75rem 0 0.5rem;
    border-top: 1px solid #e5e7eb;
    margin-top: 0.5rem;
  }
  .navbar-user.open { display: flex; }
  .navbar-user .btn { width: 100%; justify-content: flex-start; padding: 0.625rem 0.875rem; }
  #username-display { padding: 0.25rem 0.25rem; font-weight: 600; color: #374151; font-size: 0.9rem; }

  /* Tables: horizontal scroll on mobile */
  .users-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 0; }
  #clients-table-wrap,
  #users-table-wrap,
  #products-table-wrap,
  #inputs-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Conversation cards */
  .conv-card { padding: 0.875rem 1rem; }
  .conv-snippet { max-width: 100%; }

  /* Detail / chat layout */
  .detail-layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .detail-sidebar { overflow-y: visible; max-height: none; }
  .detail-main { min-height: 450px; }
  .chat-history { max-height: 380px; }
  .msg-bubble { max-width: 88%; }
  .message-input-row { gap: 0.5rem; }

  /* Inventory tabs: full width */
  .inv-tabs { width: 100%; }
  .inv-tab { flex: 1; text-align: center; padding: 0.5rem 0.75rem; }

  /* Search */
  .search-input-row { flex-wrap: wrap; }
  .search-channel-select { width: 100%; }

  /* Login card */
  .login-card { padding: 1.75rem 1.25rem; }

  /* Modal: slide up from bottom on mobile */
  .modal-overlay { padding: 0.5rem; align-items: flex-end; }
  .modal-card { border-radius: 16px 16px 10px 10px; max-height: 92vh; overflow-y: auto; }
}

/* ── Responsive: Small Mobile (≤ 480px) ──────────────────────────────────── */
@media (max-width: 480px) {
  .page-header h2 { font-size: 1.05rem; }
  .conv-badges { flex-direction: column; align-items: flex-end; gap: 0.25rem; }
  .navbar-brand { font-size: 1rem; }
  .login-card { padding: 1.5rem 1rem; }
  .login-card h1 { font-size: 1.5rem; }
  .meta-value { max-width: 130px; }
  .btn-sm { font-size: 0.8rem; }
  /* Stack modal actions vertically */
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
  /* Message send row on tiny screens */
  .message-input-row textarea { min-width: 0; }
}

/* ── Users Table ──────────────────────────────────────────────────────────── */
.users-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; border: 1px solid #e5e7eb; font-size: 0.875rem; }
.users-table th { text-align: left; padding: 0.75rem 1rem; background: #f9fafb; font-size: 0.8125rem; font-weight: 600; color: #374151; border-bottom: 1px solid #e5e7eb; }
.users-table td { padding: 0.8125rem 1rem; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tbody tr:hover { background: #f9fafb; }
.role-badge { padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; text-transform: capitalize; }
.role-admin { background: #ede9fe; color: #5b21b6; }
.role-client-admin { background: #fef3c7; color: #92400e; }
.role-agent { background: #d1fae5; color: #065f46; }
.client-slug { background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 4px; padding: 0.1rem 0.45rem; font-size: 0.8125rem; font-family: monospace; color: #374151; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.375rem; vertical-align: middle; }
.status-dot.active { background: #10b981; }
.status-dot.inactive { background: #9ca3af; }
.muted { color: #9ca3af; font-size: 0.8125rem; }
.field-hint { font-size: 0.75rem; color: #6b7280; margin-top: 0.25rem; }
select { width: 100%; padding: 0.625rem 0.875rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.9375rem; outline: none; transition: border-color 0.15s; background: #fff; }
select:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-card { background: #fff; border-radius: 16px; width: 100%; max-width: 460px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem 0; }
.modal-header h3 { font-size: 1.125rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #9ca3af; line-height: 1; padding: 0; }
.modal-close:hover { color: #374151; }
.modal-card form { padding: 1.25rem 1.5rem 1.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }
