:root {
  --bg-app: #f8fafc;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #2563eb;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --rose: #e11d48;
  --rose-bg: #fff1f2;
  --rose-border: #fecdd3;
  --emerald: #059669;
  --emerald-bg: #ecfdf5;
  --emerald-border: #a7f3d0;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --indigo: #4f46e5;
  --indigo-bg: #eef2ff;
  --indigo-border: #c7d2fe;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

/* App Shell */
.hd-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Left Sidebar */
.hd-sidebar {
  width: 255px;
  min-width: 255px;
  background: var(--bg-sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1e293b;
  user-select: none;
}

.hd-brand {
  padding: 16px 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.hd-brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: #ffffff;
  letter-spacing: -0.01em;
}

.hd-brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}

.hd-compose-wrap {
  padding: 14px 14px 8px;
}

.hd-btn-compose {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, transform 0.08s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

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

.hd-nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 16px;
}

.hd-nav-section {
  margin-top: 16px;
  margin-bottom: 6px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hd-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 7px;
  color: #cbd5e1;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.12s ease, color 0.12s ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.hd-nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #ffffff;
}

.hd-nav-item.active {
  background: rgba(37, 99, 235, 0.24);
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 #3b82f6;
}

.hd-nav-label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hd-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.hd-nav-count {
  font-size: 11.5px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
}

.hd-nav-count.urgent {
  background: #e11d48;
  color: #ffffff;
}

.hd-sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(2, 6, 23, 0.35);
}

.hd-user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.hd-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #ffffff;
  flex-shrink: 0;
}

.hd-avatar-sm {
  width: 24px;
  height: 24px;
  font-size: 10.5px;
}

/* Main Content Area */
.hd-main {
  flex: 1;
  display: flex;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.hd-page-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 28px 34px 60px;
}

.hd-container {
  max-width: 1140px;
  margin: 0 auto;
}

/* 3-Pane Inbox Layout */
.hd-list-pane {
  width: 375px;
  min-width: 330px;
  max-width: 420px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.hd-list-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.hd-list-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.hd-list-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.hd-search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-app);
  font-size: 13px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.hd-search-input:focus {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.hd-conv-list {
  flex: 1;
  overflow-y: auto;
}

.hd-conv-item {
  padding: 13px 15px 13px 14px;
  border-bottom: 1px solid #f1f5f9;
  border-left: 4px solid transparent;
  cursor: pointer;
  transition: background 0.1s ease;
  position: relative;
}

.hd-conv-item:hover {
  background: #f8fafc;
}

.hd-conv-item.selected {
  background: #eff6ff;
}

.hd-conv-item.tone-rose {
  border-left-color: var(--rose);
}

.hd-conv-item.tone-emerald {
  border-left-color: var(--emerald);
}

.hd-conv-item.tone-amber {
  border-left-color: var(--amber);
}

.hd-conv-item.unread {
  background: #fffdfd;
}

.hd-conv-item.unread.selected {
  background: #eff6ff;
}

.hd-conv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.hd-conv-customer {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hd-conv-item.unread .hd-conv-customer {
  font-weight: 800;
}

.hd-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.hd-conv-subject {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}

.hd-conv-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.hd-conv-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
}

/* Status Badges */
.hd-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.hd-badge-rose {
  background: var(--rose-bg);
  color: #be123c;
  border: 1px solid var(--rose-border);
}

.hd-badge-emerald {
  background: var(--emerald-bg);
  color: #047857;
  border: 1px solid var(--emerald-border);
}

.hd-badge-amber {
  background: var(--amber-bg);
  color: #b45309;
  border: 1px solid var(--amber-border);
}

.hd-badge-indigo {
  background: var(--indigo-bg);
  color: #4338ca;
  border: 1px solid var(--indigo-border);
}

.hd-badge-blue {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.hd-badge-slate {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.hd-mailbox-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: #334155;
  background: #f1f5f9;
  padding: 2px 7px;
  border-radius: 5px;
  max-width: 175px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Right Detail Pane */
.hd-detail-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  background: #f8fafc;
}

.hd-detail-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.hd-detail-subject {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 6px;
  line-height: 1.3;
}

.hd-detail-subbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.hd-detail-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.hd-presence-bar {
  background: #fef3c7;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  padding: 7px 22px;
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hd-timeline {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Message Cards */
.hd-msg-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  overflow: hidden;
}

.hd-msg-card.inbound {
  border-left: 4px solid #0ea5e9;
}

.hd-msg-card.outbound {
  background: #f8faff;
  border-color: #dbeafe;
  border-left: 4px solid #4f46e5;
}

.hd-msg-card.internal_note {
  background: #fffbeb;
  border-color: #fde68a;
  border-left: 4px solid #f59e0b;
}

.hd-msg-header {
  padding: 12px 18px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hd-msg-author {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hd-msg-body {
  padding: 16px 20px;
  font-size: 14px;
  line-height: 1.6;
  color: #1e293b;
  overflow-x: auto;
  word-wrap: break-word;
}

.hd-msg-body img {
  max-width: 100%;
  height: auto;
}

.hd-msg-body blockquote {
  margin: 10px 0 0;
  padding-left: 12px;
  border-left: 3px solid #cbd5e1;
  color: #64748b;
}

.hd-msg-attachments {
  padding: 10px 18px 14px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: rgba(248, 250, 252, 0.65);
}

.hd-att-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 7px;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.hd-att-chip:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.hd-event-pill {
  align-self: center;
  background: #e2e8f0;
  color: #475569;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 13px;
  border-radius: 999px;
  max-width: 85%;
  text-align: center;
}

/* Composer */
.hd-composer {
  background: #ffffff;
  border-top: 1px solid var(--border-strong);
  padding: 12px 20px 16px;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.04);
}

.hd-composer.note-mode {
  background: #fffdf4;
  border-top: 2px solid #f59e0b;
}

.hd-composer-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 10px;
}

.hd-tab-btn {
  padding: 6px 13px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.hd-tab-btn.active-reply {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.hd-tab-btn.active-note {
  background: #fef3c7;
  color: #b45309;
  border-color: #fcd34d;
}

.hd-recipients-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.hd-recipient-field {
  flex: 1;
  min-width: 210px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 10px;
}

.hd-recipient-field span {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.hd-recipient-field input {
  border: none;
  background: transparent;
  width: 100%;
  font-size: 12.5px;
  color: var(--text-main);
  outline: none;
}

.hd-editor-box {
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #ffffff;
  overflow: hidden;
}

.hd-editor-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.hd-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.hd-tool-btn {
  padding: 4px 8px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: #334155;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.hd-tool-btn:hover {
  background: #e2e8f0;
}

.hd-rich-area {
  min-height: 95px;
  max-height: 230px;
  overflow-y: auto;
  padding: 11px 14px;
  outline: none;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-main);
}

.hd-rich-area:empty::before {
  content: attr(data-placeholder);
  color: #94a3b8;
  pointer-events: none;
}

.hd-sig-bar {
  margin-top: 8px;
  padding: 7px 11px;
  border-radius: 7px;
  background: #f8fafc;
  border: 1px dashed var(--border-strong);
  font-size: 12px;
  color: var(--text-secondary);
}

.hd-composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 10px;
  flex-wrap: wrap;
}

/* Reusable Forms, Cards, Buttons & Modals */
.hd-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  margin-bottom: 20px;
}

.hd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.14s ease;
  white-space: nowrap;
}

.hd-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.hd-btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.hd-btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.hd-btn-emerald {
  background: #059669;
  color: #ffffff;
}

.hd-btn-emerald:hover:not(:disabled) {
  background: #047857;
}

.hd-btn-amber {
  background: #d97706;
  color: #ffffff;
}

.hd-btn-amber:hover:not(:disabled) {
  background: #b45309;
}

.hd-btn-secondary {
  background: #ffffff;
  border-color: var(--border-strong);
  color: #1e293b;
}

.hd-btn-secondary:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #94a3b8;
}

.hd-btn-danger {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #be123c;
}

.hd-btn-danger:hover:not(:disabled) {
  background: #ffe4e6;
}

.hd-btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.hd-input, .hd-select, .hd-textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  font-size: 13.5px;
  color: var(--text-main);
  font-family: inherit;
  outline: none;
}

.hd-input:focus, .hd-select:focus, .hd-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.hd-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: #334155;
  margin-bottom: 5px;
}

.hd-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.hd-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.hd-table {
  width: 100%;
  border-collapse: collapse;
}

.hd-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.hd-table td {
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.hd-alert {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 13.5px;
  font-weight: 500;
}

.hd-alert-success {
  background: var(--emerald-bg);
  border: 1px solid var(--emerald-border);
  color: #065f46;
}

.hd-alert-error {
  background: var(--rose-bg);
  border: 1px solid var(--rose-border);
  color: #9f1239;
}

/* Modal */
.hd-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}

.hd-modal {
  background: #ffffff;
  border-radius: 14px;
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

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

.hd-modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}

.hd-modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.hd-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.hd-tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 6px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.hd-tag-pill:hover {
  background: #dbeafe;
}

.hd-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #0f172a;
  color: #ffffff;
  padding: 11px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  z-index: 90;
}

@media (max-width: 1024px) {
  .hd-grid-2, .hd-grid-3 {
    grid-template-columns: 1fr;
  }
  .hd-list-pane {
    width: 310px;
    min-width: 270px;
  }
}
