/* ChatFlow / Email Solutions — shared UI styles
   Pairs with Tailwind CDN. Defines theme tokens + reusable components. */

:root {
  --c-bg: #f6f8fb;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;
  --c-border: #e6eaf0;
  --c-border-strong: #d4dae3;
  --c-text: #0f172a;
  --c-text-soft: #334155;
  --c-muted: #64748b;
  --c-primary: #1c75bc;        /* Email Solutions brand blue */
  --c-primary-dark: #155d96;
  --c-primary-soft: #e7f1fa;
  --c-accent: #8dc63f;          /* Email Solutions brand green */
  --c-warn: #f59e0b;
  --c-danger: #ef4444;
  --c-sidebar: #0b1220;
  --c-sidebar-2: #0f172a;
  --c-sidebar-text: #aeb9ca;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10), 0 2px 8px rgba(15, 23, 42, 0.05);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--c-text); letter-spacing: -0.01em; }

a { color: var(--c-primary-dark); }

/* Refined scrollbars */
* { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #94a3b8; background-clip: content-box; }

/* App shell */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.app-sidebar {
  background: linear-gradient(180deg, var(--c-sidebar-2) 0%, var(--c-sidebar) 100%);
  color: var(--c-sidebar-text);
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}
.app-main { display: flex; flex-direction: column; min-width: 0; }
.app-header {
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--c-border);
  padding: 14px 28px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.app-header h1 { font-size: 20px; font-weight: 700; margin: 0; }
.app-content { padding: 28px; flex: 1; }

/* Sidebar */
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 20px; color: #fff; font-weight: 700; font-size: 16px;
}
.brand-logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #10b981);
  display: grid; place-items: center; color: white; font-weight: 700;
}
.brand-img {
  width: 100%; max-width: 150px; height: auto; display: block;
  margin: 2px auto 4px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: #5d6b82; padding: 18px 12px 6px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px; color: var(--c-sidebar-text);
  text-decoration: none; font-size: 13px; cursor: pointer; font-weight: 500;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.05s var(--ease);
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav-item:active { transform: scale(0.99); }
.nav-item.active {
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark));
  color: #fff; box-shadow: 0 4px 12px rgba(21, 93, 150, 0.35);
}
.nav-item .badge { margin-left: auto; background: rgba(255, 255, 255, 0.12); padding: 1px 7px; border-radius: 10px; font-size: 11px; }

/* Cards */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

/* KPI tile */
.kpi {
  position: relative; overflow: hidden;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.kpi::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--c-primary), var(--c-accent));
  opacity: 0; transition: opacity 0.15s var(--ease);
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi:hover::before { opacity: 1; }
.kpi-label { color: var(--c-muted); font-size: 12px; font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 12px; margin-top: 6px; }
.kpi-delta.up { color: var(--c-accent); }
.kpi-delta.down { color: var(--c-danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.05s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--c-primary); color: #fff; box-shadow: 0 2px 8px rgba(28, 117, 188, 0.3); }
.btn-primary:hover { background: var(--c-primary-dark); box-shadow: 0 4px 14px rgba(21, 93, 150, 0.4); }
.btn-secondary { background: var(--c-surface); color: var(--c-text-soft); border-color: var(--c-border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--c-surface-2); border-color: #c2cad6; }
.btn-ghost { background: transparent; color: var(--c-text-soft); }
.btn-ghost:hover { background: var(--c-surface-2); }
.btn-danger { background: var(--c-danger); color: #fff; box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--c-border); }
.tbl th { color: var(--c-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; background: var(--c-surface-2); }
.tbl thead th:first-child { border-top-left-radius: var(--radius-sm); }
.tbl thead th:last-child { border-top-right-radius: var(--radius-sm); }
.tbl tbody tr { transition: background 0.12s var(--ease); }
.tbl tbody tr:hover td { background: var(--c-primary-soft); }
.tbl tbody tr:last-child td { border-bottom: none; }

/* Pill / badge */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill-green { background: #d1fae5; color: #065f46; }
.pill-yellow { background: #fef3c7; color: #92400e; }
.pill-red { background: #fee2e2; color: #991b1b; }
.pill-blue { background: #dbeafe; color: #1e40af; }
.pill-gray { background: #f1f5f9; color: #475569; }
.pill-purple { background: #ede9fe; color: #5b21b6; }

/* Forms */
.form-row { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--c-text-soft); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm); font-size: 13px; background: #fff; font-family: inherit; color: var(--c-text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.form-input:hover, .form-select:hover, .form-textarea:hover { border-color: #c2cad6; }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(28, 117, 188, 0.15);
}
.form-input::placeholder, .form-textarea::placeholder { color: #9aa6b8; }
.form-help { font-size: 11px; color: var(--c-muted); margin-top: 5px; }

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

/* Wireframe sketch helpers */
.sketch-box {
  border: 2px dashed #cbd5e1; border-radius: 8px;
  padding: 24px; color: var(--c-muted); text-align: center;
  background: repeating-linear-gradient(45deg, #f8fafc 0 10px, #f1f5f9 10px 20px);
}
.dot-online { width: 8px; height: 8px; border-radius: 50%; background: #10b981; display: inline-block; }
.dot-away { background: #f59e0b; }
.dot-offline { background: #94a3b8; }

/* Avatar */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  display: inline-grid; place-items: center; color: white; font-weight: 600; font-size: 12px;
  box-shadow: var(--shadow-xs);
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }

/* Chat bubbles — WhatsApp style */
.bubble {
  max-width: 70%; padding: 6px 9px 5px; border-radius: 8px;
  font-size: 14px; line-height: 1.4;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  overflow-wrap: anywhere; word-break: break-word;
}
.bubble-in { background: #ffffff; color: #111b21; border-top-left-radius: 0; }
.bubble-out { background: #d9fdd3; color: #111b21; margin-left: auto; border-top-right-radius: 0; }
.bubble-meta { font-size: 11px; color: #667781; margin: 2px 0 0; }
.tick-read { color: #53bdeb; }

/* Layout helpers */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.spacer { flex: 1; }

/* Auth pages */
.auth-shell {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #155d96 0%, #1c75bc 50%, #8dc63f 100%);
  padding: 20px;
}
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: var(--radius-lg); padding: 36px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25); }

/* Inbox layout — contact detail panel is hidden until toggled via the contact name */
.inbox { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 60px); }
.inbox.show-detail { grid-template-columns: 320px 1fr 320px; }
.inbox-list { border-right: 1px solid var(--c-border); background: #fff; overflow-y: auto; }
.inbox-thread { display: flex; flex-direction: column; background: var(--c-surface-2); min-width: 0; min-height: 0; overflow: hidden; }
.inbox-detail { display: none; border-left: 1px solid var(--c-border); background: #fff; overflow-y: auto; padding: 20px; }
.inbox.show-detail .inbox-detail { display: block; }
.thread-contact-name { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.thread-contact-name:hover { color: var(--c-primary); }
.thread-contact-name .chev { font-size: 11px; color: var(--c-muted); transition: transform 0.15s var(--ease); }
.inbox.show-detail .thread-contact-name .chev { transform: rotate(180deg); }
.conv-item { padding: 12px 16px; border-bottom: 1px solid var(--c-border); cursor: pointer; transition: background 0.12s var(--ease); }
.conv-item:hover { background: var(--c-surface-2); }
.conv-item.active { background: var(--c-primary-soft); border-left: 3px solid var(--c-primary); }
.conv-name { font-weight: 600; font-size: 13px; }
.conv-snippet { color: var(--c-muted); font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Flow builder canvas */
.flow-canvas {
  background: #f1f5f9;
  background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
  min-height: 600px; position: relative; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--c-border);
}
.flow-node {
  position: absolute; background: #fff; border: 2px solid var(--c-primary);
  border-radius: 10px; padding: 12px; min-width: 180px;
  box-shadow: var(--shadow); font-size: 12px;
}
.flow-node.start { border-color: #10b981; }
.flow-node.ai { border-color: #8b5cf6; }
.flow-node.condition { border-color: #f59e0b; }
.flow-node.api { border-color: #06b6d4; }
.flow-node.handoff { border-color: #ef4444; }
.flow-node h4 { margin: 0 0 4px; font-size: 12px; }
.flow-node small { color: var(--c-muted); }

/* Notice */
.notice {
  background: #fffbeb; border-left: 4px solid #f59e0b;
  padding: 11px 14px; border-radius: 8px; font-size: 12px; margin-bottom: 16px;
}
.notice-info { background: #eff6ff; border-left-color: #3b82f6; }

/* Hub (master index) */
.hub-hero {
  background: linear-gradient(135deg, #155d96 0%, #1c75bc 55%, #8dc63f 100%);
  color: #fff; padding: 48px 32px; border-radius: var(--radius-lg); margin-bottom: 32px;
  box-shadow: var(--shadow-lg);
}
.hub-section { margin-bottom: 36px; }
.hub-section h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--c-muted); margin-bottom: 12px; font-weight: 600; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.hub-card {
  background: #fff; border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 18px; text-decoration: none; color: var(--c-text);
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}
.hub-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--c-primary); }
.hub-card .h-icon { font-size: 22px; }
.hub-card .h-title { font-weight: 600; font-size: 14px; }
.hub-card .h-desc { font-size: 12px; color: var(--c-muted); }

/* ===========================================================================
   Responsive — tablet & mobile.
   =========================================================================== */

.inbox-back {
  display: none; align-items: center; gap: 4px; margin-bottom: 6px;
  text-decoration: none; color: var(--c-primary); font-size: 13px; font-weight: 600;
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .app-sidebar {
    position: static; height: auto; width: 100%;
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
    padding: 10px 12px;
  }
  .app-sidebar .brand { padding: 4px 10px 4px 4px; }
  .app-sidebar .brand-img { max-width: 132px; padding: 6px 10px; }
  .nav-section { display: none; }
  .nav-item { padding: 6px 10px; font-size: 12px; }
  .app-sidebar > div:last-child {
    margin-top: 0 !important; border-top: none !important;
    margin-left: auto; padding: 4px 8px !important;
  }

  .inbox { grid-template-columns: 300px 1fr; }
  .inbox-detail { display: none; }

  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox:not(.has-selection) .inbox-thread { display: none; }
  .inbox.has-selection .inbox-list { display: none; }
  .inbox-list { border-right: none; }
  .inbox-back { display: inline-flex; }

  .app-content { padding: 16px; }
  .app-header { padding: 12px 16px; }
  .app-header h1 { font-size: 17px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .bubble { max-width: 85%; }
  .auth-card { padding: 24px; }

  .tbl { display: block; overflow-x: auto; white-space: nowrap; }
}

.ch-ico { width:46px;height:46px;border-radius:12px;display:grid;place-items:center;background:var(--c-surface-2);flex-shrink:0; }
.ch-ico svg { display:block; }

.pv-btn { border-top:1px solid #e9edef; padding:9px; text-align:center; font-size:13.5px; color:#1c75bc; font-weight:500; cursor:default; }

/* Floating support button */
.support-fab { position:relative; z-index:60; }
.support-fab > summary { list-style:none; width:40px; height:40px; border-radius:50%; background:#1c75bc; display:grid; place-items:center; cursor:pointer; box-shadow:0 2px 6px rgba(28,117,188,0.3); transition:background 0.15s var(--ease); }
.support-fab > summary svg { width:22px; height:22px; }
.support-fab > summary::-webkit-details-marker { display:none; }
.support-fab > summary:hover, .support-fab[open] > summary { background:var(--c-primary-dark); }
.support-menu { position:absolute; right:0; top:50px; width:260px; background:#fff; border:1px solid var(--c-border); border-radius:14px; box-shadow:0 16px 40px rgba(15,23,42,0.18); overflow:hidden; }
.support-menu-head { padding:11px 14px; border-bottom:1px solid var(--c-border); font-weight:600; font-size:13px; }
.support-item { display:flex; align-items:center; gap:11px; padding:11px 14px; text-decoration:none; color:var(--c-text); border-bottom:1px solid var(--c-border); }
.support-item:last-child { border-bottom:none; }
.support-item:hover { background:var(--c-surface-2); }
.support-ic { width:32px; height:32px; border-radius:8px; display:grid; place-items:center; flex-shrink:0; }
@media (max-width:640px) { .support-fab > summary { width:36px; height:36px; } }