/* style.css — Pivotus AI Chat — Diamond Edition */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* =========================================================
   DESIGN TOKENS
   ========================================================= */
:root {
  /* Accent palette */
  --accent:        #4F6EF7;
  --accent-dark:   #3B5BF5;
  --accent-light:  rgba(79, 110, 247, 0.10);
  --accent-glow:   rgba(79, 110, 247, 0.22);
  --accent-grad:   linear-gradient(135deg, #4F6EF7 0%, #7C3AED 100%);

  /* Surfaces */
  --bg-app:        #EFF1FA;
  --bg-surface:    rgba(255, 255, 255, 0.97);
  --bg-header:     rgba(255, 255, 255, 0.99);
  --bg-ai-msg:     #FFFFFF;
  --bg-input:      #FFFFFF;

  /* Text */
  --text-primary:  #0F172A;
  --text-secondary:#475569;
  --text-muted:    #94A3B8;
  --text-inverse:  #FFFFFF;

  /* Borders */
  --border:        rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.38);

  /* Shadows */
  --shadow-xs:  0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-sm:  0 2px 8px  rgba(15, 23, 42, 0.08);
  --shadow-md:  0 6px 20px rgba(79, 110, 247, 0.14);
  --shadow-lg:  0 16px 48px rgba(79, 110, 247, 0.20);

  /* Auth gradient */
  --bg-auth: linear-gradient(145deg, #1E1B4B 0%, #312E81 45%, #4338CA 100%);

  /* Motion */
  --ease-out:  cubic-bezier(0.22, 1, 0.36, 1);
  --ease-std:  cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast:    150ms;
  --t-std:     250ms;
  --t-slow:    400ms;
}

/* =========================================================
   GLOBAL RESET + ANTI-ALIASING
   Root fix for iframe pixelation: force subpixel AA everywhere
   ========================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  /* Prevent browser from inflating text inside iframes */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-app);
  overflow: hidden;

  /* Critical: forces GPU-composited text rendering in iframe contexts */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'kern' 1, 'liga' 1;
}

/* Crisp profile pictures and icons at any DPI */
img {
  image-rendering: -webkit-optimize-contrast;
}

/* GPU-accelerated canvas for Chart.js — prevents iframe blur */
canvas {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* =========================================================
   AUTH SCREEN
   ========================================================= */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100%;
  background: var(--bg-auth);
  position: relative;
  overflow: hidden;
}

/* Ambient glow orbs */
.auth-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 60% at 80% 10%, rgba(99, 102, 241, 0.28) 0%, transparent 70%),
    radial-gradient(ellipse 50% 50% at 15% 90%, rgba(167, 139, 250, 0.18) 0%, transparent 70%);
  pointer-events: none;
}

.auth-card {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow:
    0 28px 72px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  padding: 48px 40px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  animation: cardEntrance var(--t-slow) var(--ease-out) both;
}

.auth-logo {
  font-size: 54px;
  margin-bottom: 18px;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.35));
  animation: floatLogo 3.2s ease-in-out infinite;
  will-change: transform;
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.6px;
  margin-bottom: 10px;
}

/* Status line — updated dynamically by initGoogleSignIn() */
#signin-status {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.65);
  line-height: 1.55;
  margin-bottom: 28px;
  min-height: 22px; /* prevent layout shift during status change */
  transition: color var(--t-std) var(--ease-std);
}

.auth-card code {
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.88);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  letter-spacing: 0.02em;
}

#google-signin-btn {
  display: flex;
  justify-content: center;
  min-height: 44px;
  transition: opacity var(--t-std) var(--ease-std);
}

.auth-footer {
  margin-top: 24px !important;
  margin-bottom: 0 !important;
  font-size: 11.5px !important;
  color: rgba(255, 255, 255, 0.35) !important;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* =========================================================
   CHAT SCREEN LAYOUT
   ========================================================= */
.chat-screen {
  display: flex;
  height: 100vh;
  width: 100%;
}

#container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--bg-surface);
  overflow: hidden;
}

/* =========================================================
   HEADER
   ========================================================= */
.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  min-height: 52px;
  flex-shrink: 0;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.header h1 {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.25px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast) var(--ease-std),
              color var(--t-fast) var(--ease-std),
              transform var(--t-fast) var(--ease-std),
              border-color var(--t-fast) var(--ease-std);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(79, 110, 247, 0.3);
  transform: scale(1.10);
}

.icon-btn:active {
  transform: scale(0.93);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
  flex-shrink: 0;
  object-fit: cover;
}

.user-name {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96px;
}

/* =========================================================
   CHAT AREA
   ========================================================= */
.chat-area {
  flex: 1;
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-app);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

/* =========================================================
   MESSAGE BUBBLES
   ========================================================= */
.message {
  max-width: 88%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.65;
  animation: msgIn var(--t-std) var(--ease-out) both;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--accent-grad);
  color: var(--text-inverse);
  border-bottom-right-radius: 5px;
  box-shadow: var(--shadow-md);
}

.message.assistant {
  align-self: flex-start;
  background: var(--bg-ai-msg);
  color: var(--text-primary);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  max-width: 96%;
}

/* =========================================================
   TABLE — premium data rendering
   ========================================================= */
.message.assistant table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 10px 0;
  font-size: 12.5px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  font-variant-numeric: tabular-nums;
}

.message.assistant th {
  background: linear-gradient(180deg, #F5F7FF 0%, #EFF1FA 100%);
  color: var(--text-secondary);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.message.assistant td {
  padding: 7px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.10);
  color: var(--text-primary);
}

.message.assistant tr:nth-child(even) td {
  background: rgba(239, 241, 250, 0.45);
}

.message.assistant tr:last-child td {
  border-bottom: none;
}

.message.assistant tr:hover td {
  background: var(--accent-light);
  transition: background var(--t-fast);
}

/* Inline text styling in AI responses */
.message.assistant strong { color: var(--accent); font-weight: 600; }

.message.assistant h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.2px;
}

.message.assistant ul,
.message.assistant ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message.assistant li { margin-bottom: 4px; }

/* =========================================================
   CHART CANVAS — P1-6
   ========================================================= */
.chart-canvas {
  margin-top: 14px;
  max-height: 220px;
  width: 100% !important;
  border-radius: 8px;
}

/* =========================================================
   LOADING INDICATOR — P2-10
   ========================================================= */
.loading-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-ai-msg);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  align-self: flex-start;
  box-shadow: var(--shadow-xs);
  max-width: 100px;
  animation: msgIn var(--t-std) var(--ease-out) both;
}

.loading-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
}

.loading-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: loadingPulse 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

.loading-label {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* =========================================================
   PROMPT CHIPS — P2-9
   ========================================================= */
.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface);
}

.chip {
  background: var(--accent-light);
  border: 1px solid rgba(79, 110, 247, 0.2);
  border-radius: 20px;
  color: var(--accent);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  padding: 5px 13px;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease-std);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.chip:hover {
  background: rgba(79, 110, 247, 0.17);
  border-color: rgba(79, 110, 247, 0.38);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px var(--accent-glow);
}

.chip:active { transform: translateY(0); }

/* =========================================================
   INPUT AREA
   ========================================================= */
.input-area {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  background: var(--bg-surface);
}

.input-area input {
  flex: 1;
  padding: 10px 16px;
  border-radius: 24px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-input);
  outline: none;
  font-size: 13.5px;
  font-family: 'Inter', sans-serif;
  color: var(--text-primary);
  transition: border-color var(--t-std) var(--ease-std),
              box-shadow var(--t-std) var(--ease-std);
  min-width: 0;
  box-shadow: var(--shadow-xs);
  -webkit-font-smoothing: antialiased;
}

.input-area input::placeholder { color: var(--text-muted); }

.input-area input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-glow);
}

.input-area input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.send-button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent-grad);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: transform var(--t-fast) var(--ease-std),
              box-shadow var(--t-fast) var(--ease-std);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.send-button:hover:not(:disabled) {
  transform: scale(1.09);
  box-shadow: 0 6px 18px var(--accent-glow);
}

.send-button:active:not(:disabled) { transform: scale(0.94); }

.send-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

/* =========================================================
   KEYFRAMES
   ========================================================= */
@keyframes cardEntrance {
  from { opacity: 0; transform: translateY(22px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

@keyframes floatLogo {
  0%, 100% { transform: translateY(0);    }
  50%       { transform: translateY(-7px); }
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

@keyframes loadingPulse {
  0%, 80%, 100% { opacity: 0.22; transform: scale(0.72); }
  40%           { opacity: 1;    transform: scale(1.0);  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   RESPONSIVE — Looker Studio embed (min 300px)
   ========================================================= */
@media (max-width: 500px) {
  .message { max-width: 95%; font-size: 13px; }
  .auth-card { padding: 32px 24px; }
  .chip { font-size: 11.5px; padding: 4px 11px; }
  .user-name { display: none; }
}

@media (max-width: 350px) {
  .header h1 { font-size: 13px; }
  .avatar { display: none; }
  .header-user { display: none; }
  .header-actions { gap: 2px; }
  .icon-btn { width: 26px; height: 26px; font-size: 12px; }
  .prompt-chips { display: none !important; }
  .input-area input { font-size: 12.5px; padding: 8px 12px; }
  .send-button { width: 34px; height: 34px; }
  .chart-canvas { max-height: 160px; }
}
