/* ==========================================================================
   Sayan Frontend -- Aiuken Solutions
   Strategic Autonomous Orchestrator -- Interface Styles
   ========================================================================== */

/* --- Reset and Base --- */

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

:root {
  --color-bg-primary: #0a0f1a;
  --color-bg-secondary: #111827;
  --color-bg-tertiary: #1a2235;
  --color-bg-input: #1e293b;
  --color-bg-hover: #243047;
  --color-accent: #00e5ff;
  --color-accent-dim: rgba(0, 229, 255, 0.15);
  --color-accent-glow: rgba(0, 229, 255, 0.3);
  --color-text-primary: #e2e8f0;
  --color-text-secondary: #94a3b8;
  --color-text-muted: #64748b;
  --color-border: #1e293b;
  --color-border-accent: rgba(0, 229, 255, 0.2);
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-user-bg: #1a3a5c;
  --color-agent-bg: #1a2235;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
}

/* --- App Layout --- */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 860px;
  margin: 0 auto;
}

/* --- Header --- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  width: 40px;
  height: 40px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-accent);
  flex-shrink: 0;
}

.header-text h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.header-subtitle {
  font-size: 12px;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.status-online {
  background: var(--color-success);
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.5);
}

.status-offline {
  background: var(--color-text-muted);
}

.status-error {
  background: var(--color-error);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.status-label {
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* --- Chat Container --- */

.chat-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.transcript::-webkit-scrollbar {
  width: 6px;
}

.transcript::-webkit-scrollbar-track {
  background: transparent;
}

.transcript::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.transcript::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* --- Messages --- */

.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: messageIn 200ms ease-out;
}

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

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-agent {
  align-self: flex-start;
}

.message-system {
  align-self: center;
  max-width: 90%;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-user .message-avatar {
  background: var(--color-user-bg);
  color: var(--color-accent);
  border: 1px solid var(--color-border-accent);
}

.message-agent .message-avatar {
  background: var(--color-accent-dim);
  color: var(--color-accent);
  border: 1px solid var(--color-border-accent);
}

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.message-user .message-content {
  background: var(--color-user-bg);
  border: 1px solid rgba(0, 229, 255, 0.1);
  color: var(--color-text-primary);
}

.message-agent .message-content {
  background: var(--color-agent-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
}

.message-system .message-content {
  background: transparent;
  border: 1px solid var(--color-border);
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 13px;
  padding: 12px 20px;
}

.message-content p {
  margin-bottom: 6px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.message-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 3px;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

/* --- Typing Indicator --- */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--color-text-muted);
  border-radius: var(--radius-full);
  animation: typingPulse 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingPulse {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* --- Input Bar --- */

.input-bar {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 8px 8px 14px;
  transition: border-color var(--transition-fast);
}

.input-wrapper:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-dim);
}

.input-field {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  padding: 4px 0;
}

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

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

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-icon:hover:not(:disabled) {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.btn-icon:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-send:not(:disabled) {
  color: var(--color-accent);
}

.btn-send:hover:not(:disabled) {
  background: var(--color-accent-dim);
  color: var(--color-accent);
}

.btn-icon.recording {
  color: var(--color-error);
  animation: recordingPulse 1.5s ease-in-out infinite;
}

@keyframes recordingPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 0;
}

.char-count {
  font-size: 11px;
  color: var(--color-text-muted);
}

.powered-by {
  font-size: 11px;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

/* --- Responsive --- */

@media (max-width: 640px) {
  #app {
    max-width: 100%;
  }

  .header {
    padding: 10px 14px;
  }

  .transcript {
    padding: 14px;
    gap: 12px;
  }

  .message {
    max-width: 92%;
  }

  .input-bar {
    padding: 10px 14px 14px;
  }

  .header-subtitle {
    display: none;
  }
}

/* --- Selection --- */

::selection {
  background: var(--color-accent-dim);
  color: var(--color-text-primary);
}
