/**
 * ChatFooter Component
 * Input area for sending messages and managing file attachments
 * 
 * Dependencies: chat-tokens.css
 */

/* ============================================
   FOOTER CONTAINER
   ============================================ */

.chat-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
  background: var(--chat-surface-primary);
  border-top: 1px solid var(--chat-border-primary);
  padding: var(--chat-space-sm) 0;
  z-index: var(--chat-z-fixed);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}

/* ============================================
   FILE ATTACHMENTS
   ============================================ */

.attached-files {
  display: none;
  padding: var(--chat-space-sm) var(--chat-space-lg);
  flex-wrap: wrap;
  gap: var(--chat-space-sm);
  max-width: min(var(--chat-layout-content-max-width), 92vw);
  margin: 0 auto var(--chat-space-sm) auto;
}

.attached-files.has-files {
  display: flex;
}

.file-item {
  display: flex;
  align-items: center;
  gap: var(--chat-space-sm);
  padding: var(--chat-space-sm) var(--chat-space-md);
  background: var(--chat-surface-secondary);
  border: 1px solid var(--chat-border-primary);
  border-radius: var(--chat-radius-md);
  font-size: var(--chat-font-size-sm);
}

.file-icon {
  font-size: 1.2rem;
}

.file-name {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  color: var(--chat-text-secondary);
  font-size: var(--chat-font-size-sm);
}

.remove-file {
  all: unset;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--chat-text-secondary);
  padding: 0 var(--chat-space-xs);
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-file:hover {
  color: var(--chat-status-error);
}

/* ============================================
   FOOTER INPUT WRAPPER
   ============================================ */

.footer-input-wrapper {
  max-width: min(var(--chat-layout-content-max-width), 92vw);
  margin: 0 auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

/* ============================================
   INPUT BAR
   ============================================ */

.input-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.35rem 0.6rem;
  background: var(--chat-surface-primary);
  border: 1px solid var(--chat-border-primary);
  border-radius: var(--chat-radius-2xl);
  flex: 1;
  min-width: 0;
}

.input-bar:focus-within {
  /* Focus border removed */
}

.input-bar.readonly {
  opacity: 0.6;
  pointer-events: none;
}

/* ============================================
   FILE BUTTON
   ============================================ */

.file-btn {
  all: unset;
  cursor: pointer;
  padding: 0.35rem;
  border-radius: var(--chat-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-text-secondary);
  height: 20px;
  width: 20px;
}

.file-btn:hover {
  background: var(--chat-surface-tertiary);
  color: var(--chat-brand-primary);
}

.file-btn .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
}

/* ============================================
   TEXT INPUT
   ============================================ */

#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--chat-font-family-base);
  font-size: var(--chat-font-size-md);
  line-height: 1.5;
  padding: 0.45rem 0.6rem;
  border-radius: var(--chat-radius-md);
  background: transparent;
  color: var(--chat-text-primary);
  max-height: 40vh;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--chat-border-primary) transparent;
}

#input.is-scroll {
  overflow-y: auto;
}

#input::-webkit-scrollbar {
  width: 6px;
}

#input::-webkit-scrollbar-track {
  background: transparent;
}

#input::-webkit-scrollbar-thumb {
  background: var(--chat-border-primary);
  border-radius: 3px;
}

#input::-webkit-scrollbar-thumb:hover {
  background: var(--chat-text-secondary);
}

#input::placeholder {
  color: var(--chat-text-tertiary);
  font-weight: 400;
}

/* ============================================
   ACTION BUTTONS
   ============================================ */

.send-btn {
  background: var(--chat-brand-primary);
  color: white;
  font-weight: var(--chat-font-weight-semibold);
  border: none;
  border-radius: var(--chat-radius-lg);
  padding: 0.5rem 1.2rem;
  cursor: pointer;
  font-size: var(--chat-font-size-md);
  line-height: 1.5;
}

.send-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.export-tables-btn {
  background: var(--chat-brand-primary);
  color: white;
  font-weight: var(--chat-font-weight-semibold);
  border: none;
  border-radius: var(--chat-radius-lg);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: var(--chat-font-size-md);
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: opacity 0.2s, background 0.2s;
}

.export-tables-btn:hover {
  opacity: 0.9;
  background: var(--chat-brand-primary-dark, var(--chat-brand-primary));
}

.export-tables-btn .material-symbols-outlined {
  font-size: 18px;
  line-height: 1;
}

.export-tables-text {
  white-space: nowrap;
}

/* ============================================
   EXPORT DROPDOWN
   ============================================ */

.export-dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.export-btn {
  all: unset;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--chat-radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-brand-primary);
  color: white;
  transition: opacity 0.2s, background 0.2s;
  width: 40px;
  height: 40px;
  box-sizing: border-box;
}

.export-btn:hover {
  opacity: 0.9;
  background: var(--chat-brand-primary-dark, var(--chat-brand-primary));
}

.export-btn .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
}

.export-dropdown-menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  right: 0;
  background: var(--chat-surface-primary);
  border: 1px solid var(--chat-border-primary);
  border-radius: var(--chat-radius-lg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 240px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
  z-index: 1000;
  overflow: hidden;
}

.export-dropdown-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.export-option {
  all: unset;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: var(--chat-font-size-md);
  color: var(--chat-text-primary);
  transition: background 0.15s;
  width: 100%;
  box-sizing: border-box;
}

.export-option:hover {
  background: var(--chat-surface-secondary);
}

.export-option:first-child {
  border-top-left-radius: var(--chat-radius-lg);
  border-top-right-radius: var(--chat-radius-lg);
}

.export-option:last-child {
  border-bottom-left-radius: var(--chat-radius-lg);
  border-bottom-right-radius: var(--chat-radius-lg);
}

.export-option .material-symbols-outlined {
  font-size: 20px;
  color: var(--chat-text-secondary);
}

.export-option:hover .material-symbols-outlined {
  color: var(--chat-brand-primary);
}

.export-option span:not(.material-symbols-outlined) {
  flex: 1;
  white-space: nowrap;
}

.end-btn {
  background: transparent;
  color: var(--chat-status-error);
  font-weight: var(--chat-font-weight-semibold);
  border: 2px solid var(--chat-status-error);
  border-radius: var(--chat-radius-lg);
  padding: 0.5rem 1.2rem;
  cursor: pointer;
  font-size: var(--chat-font-size-md);
  line-height: 1.5;
}

.end-btn:hover {
  background: var(--chat-status-error);
  color: white;
}

/* ============================================
   CHAT LAYOUT INTEGRATION
   ============================================ */

.footer-container {
  background: var(--chat-surface-primary);
  border-top: 1px solid var(--chat-border-primary);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
  padding: var(--chat-space-lg) 0;
}

.footer-container > * {
  max-width: var(--chat-layout-content-max-width);
  margin: 0 auto;
  padding-left: var(--chat-space-4xl);
  padding-right: var(--chat-space-4xl);
}

.footer-container .chat-footer-form {
  display: flex;
  gap: var(--chat-space-md);
  align-items: center;
}

.footer-container textarea {
  background: var(--chat-bg-tertiary);
  border: 1px solid var(--chat-border-primary);
  border-radius: var(--chat-radius-md);
  padding: var(--chat-space-lg) var(--chat-space-xl);
  font-size: var(--chat-font-size-md);
}

.footer-container textarea:focus {
  background: var(--chat-surface-primary);
  /* Focus border removed */
  outline: none;
}

.footer-container button {
  border-radius: var(--chat-radius-md);
  padding: 0.65rem 1.5rem;
  font-weight: var(--chat-font-weight-semibold);
  font-size: var(--chat-font-size-md);
  line-height: 1.6;
}

.footer-container .send-btn {
  background: var(--chat-brand-primary);
  color: white;
  border: none;
}

.footer-container .send-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.footer-container .end-btn {
  background: transparent;
  border: 2px solid var(--chat-status-error);
  color: var(--chat-status-error);
}

.footer-container .end-btn:hover {
  background: var(--chat-status-error);
  color: white;
}

/* ============================================
   DARK MODE
   ============================================ */

body.dark-mode .chat-footer {
  background: var(--chat-dark-surface-primary);
  border-top-color: var(--chat-dark-border-primary);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
}

body.dark-mode .input-bar {
  background: var(--chat-dark-surface-light);
  border-color: var(--chat-dark-border-primary);
}

body.dark-mode .footer-input-wrapper {
  /* Inherits from parent */
}

body.dark-mode .input-bar:focus-within {
  /* Focus border removed */
}

body.dark-mode .file-item {
  background: var(--chat-dark-surface-primary);
  border-color: var(--chat-dark-border-primary);
}

body.dark-mode #input {
  color: var(--chat-dark-text-primary);
}

body.dark-mode #input::placeholder {
  color: var(--chat-dark-text-tertiary);
}

body.dark-mode #input::-webkit-scrollbar-thumb {
  background: var(--chat-dark-border-primary);
}

body.dark-mode #input::-webkit-scrollbar-thumb:hover {
  background: var(--chat-dark-text-secondary);
}

body.dark-mode .file-btn:hover {
  background: var(--chat-dark-border-primary);
}

body.dark-mode .footer-container {
  background: var(--chat-dark-surface-primary);
  border-color: var(--chat-dark-border-primary);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
}

body.dark-mode .footer-container textarea {
  background: var(--chat-dark-bg-primary);
  border-color: var(--chat-dark-border-primary);
  color: var(--chat-dark-text-primary);
}

body.dark-mode .footer-container textarea:focus {
  background: var(--chat-dark-bg-secondary);
  /* Focus border removed */
}

body.dark-mode .export-dropdown-menu {
  background: var(--chat-dark-surface-primary);
  border-color: var(--chat-dark-border-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.dark-mode .export-option {
  color: var(--chat-dark-text-primary);
}

body.dark-mode .export-option:hover {
  background: var(--chat-dark-surface-secondary);
}

body.dark-mode .export-option .material-symbols-outlined {
  color: var(--chat-dark-text-secondary);
}

body.dark-mode .export-option:hover .material-symbols-outlined {
  color: var(--chat-brand-primary);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 900px) {
  .footer-input-wrapper {
    max-width: 96vw;
  }

  .file-name {
    max-width: 120px;
  }
}

@media (max-width: 768px) {
  .footer-container > * {
    padding-left: var(--chat-space-2xl);
    padding-right: var(--chat-space-2xl);
  }
}

@media (max-width: 480px) {
  .footer-container > * {
    padding-left: var(--chat-space-lg);
    padding-right: var(--chat-space-lg);
  }
}

/* ============================================
   LEGACY STYLES (from main.css)
   TODO: Refactor to use component tokens
   ============================================ */

/* Footer fixed positioning */
footer {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 0.55rem 1rem 0.5rem 1rem;
  background: linear-gradient(135deg, #fff 0%, #f7faff 100%);
  border-top: 1px solid var(--clr-border);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.07);
  margin-top: auto;
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 100;
  min-width: 0;
  box-sizing: border-box;
  height: var(--footer-height);
  width: 100% !important;
  left: 0;
}

/* File attachments in footer */
.attached-files {
  display: none;
  width: 100%;
  padding: 2px 0 2px 0;
  gap: 0.5rem;
  overflow-x: auto;
  max-height: 90px;
}

.attached-files.has-files {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}

.file-item {
  background: var(--clr-surface-alt);
  border-radius: 12px;
  padding: 0.3rem 0.9rem 0.3rem 0.7rem;
  font-size: 0.99rem;
  display: flex;
  align-items: center;
  gap: 0.42rem;
  border: 1px solid var(--clr-border);
  margin-right: 0.6rem;
  white-space: nowrap;
}

.remove-file {
  background: transparent;
  color: #c44;
  border: none;
  font-size: 1.12rem;
  margin-left: 0.4rem;
  cursor: pointer;
}

.file-extracted {
  overflow-y: auto;
  max-height: 220px;
  background: #f8f7fc;
  border-radius: 8px;
  border: 1px solid #ece6fd;
  margin-top: 0.5em;
  font-size: 0.98em;
  padding: 0.5em 0.8em;
}

.file-extracted {
  overflow-x: auto;
  max-width: 100%;
}

/* Drop zone for drag and drop */
.drop-zone {
  display: none;
  width: 100%;
  min-height: 62px;
  background: #eef6ff;
  color: #344054;
  border: 2px dashed var(--clr-accent);
  border-radius: var(--radius-lg);
  text-align: center;
  font-size: 1.08rem;
  line-height: 60px;
  margin: 0.7rem 0 1.3rem 0;
  transition: border-color 0.18s, background 0.18s;
  cursor: pointer;
  z-index: 150;
  position: relative;
}

.drop-zone.active {
  display: block;
  border-color: #34aaff;
  background: #dbeafe;
  color: #1e40af;
}

/* Input bar legacy styles */
.input-bar {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0.4rem 0;
  padding: 0.25rem 0.6rem;
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 12px rgba(40, 56, 100, 0.08);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-sizing: border-box;
}

.input-bar textarea {
  flex: 1 1 0%;
  min-width: 0;
  min-height: 38px;
  border-radius: 1.5rem;
  border: 1.3px solid #d1d5db;
  background: #fff;
  font-size: 1.1rem;
  line-height: 1.5;
  padding: 0.4rem 0.9rem;
  transition: border-color 0.16s, box-shadow 0.16s;
  box-shadow: none;
  width: 100%;
  margin: 0 0.2rem;
  box-sizing: border-box;
}

.file-btn,
.send-btn {
  flex-shrink: 0;
}

.send-btn {
  background: var(--clr-accent);
  color: #fff;
  border: none;
  border-radius: 1.5rem;
  padding: 0.55rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 500;
  cursor: pointer;
  margin-left: 0.4rem;
  transition: background 0.17s, box-shadow 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.09);
}

.send-btn:hover {
  background: var(--clr-accent-dark);
}

.file-btn {
  background: #e6efff;
  color: var(--clr-accent);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  margin: 0 0.11rem;
  transition: background 0.18s, color 0.15s;
  box-shadow: 0 2px 7px rgba(37, 99, 235, 0.09);
}

.file-btn:hover,
.file-btn:focus {
  background: var(--clr-accent);
  color: #fff;
}

.file-input {
  display: none !important;
}

.input-bar.readonly {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.1);
}

.input-bar.readonly textarea,
.input-bar.readonly button {
  cursor: not-allowed;
}

/* Input auto-grow */
.input-bar textarea {
  flex: 1 1 0%;
  width: 100%;
  min-width: 0;
  min-height: 38px;
  height: auto;
  max-height: 40vh;
  overflow-y: hidden;
  resize: none;
  border-radius: 1.5rem;
  border: 1.3px solid #d1d5db;
  background: #fff;
  font-size: 1.1rem;
  line-height: 1.5;
  padding: 0.4rem 0.9rem;
  transition: border-color 0.16s, box-shadow 0.16s;
  box-shadow: none;
  margin: 0 0.2rem;
  box-sizing: border-box;
  border-radius: 1.5rem !important;
}

.input-bar textarea.is-scroll {
  overflow-y: auto;
}

/* Footer centering like ChatGPT */
footer .input-bar {
  max-width: min(900px, 92vw);
  margin: 0.4rem 0;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--clr-border);
  margin-left: var(--chat-layout-sidebar-width);
}

footer .input-bar:focus-within {
  /* Focus border removed */
}

footer .input-bar textarea {
  height: auto !important;
  max-height: 40vh !important;
  overflow-y: hidden !important;
  resize: none !important;
  outline: none;
}

footer .input-bar textarea.is-scroll {
  overflow-y: auto !important;
}

/* Space for footer in chat */
main#chat::after {
  height: var(--footer-height);
}

/* Dark mode footer */
body.dark-mode footer {
  background: var(--clr-panel) !important;
  border-top: 1px solid var(--clr-border) !important;
  box-shadow: none !important;
}

body.dark-mode .input-bar {
  background: var(--clr-panel);
  border-top: 1px solid var(--clr-border);
  box-shadow: none;
}

body.dark-mode .input-bar textarea {
  background-color: var(--clr-surface);
  color: var(--clr-text);
  border: 1px solid var(--clr-border);
  box-shadow: none;
}

body.dark-mode .input-bar textarea::placeholder {
  color: var(--clr-placeholder);
}

body.dark-mode .input-bar input::placeholder {
  color: var(--clr-placeholder);
}

body.dark-mode .send-btn {
  background-color: var(--clr-accent);
  color: white;
}

body.dark-mode .file-item {
  background-color: var(--clr-panel);
  color: var(--clr-text);
  border: 1px solid var(--clr-border);
}

/* File attachment display styles */
.file-attachment.only-name {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.file-attachment.only-name .file-name {
  font-weight: 600;
  text-decoration: none;
}

.file-attachment.only-name .file-name:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 900px) {
  .input-bar {
    max-width: 98vw;
    min-width: 0;
    padding: 0.7rem 0.3rem;
    gap: 0.45rem;
    flex-direction: column;
    align-items: stretch;
  }

  .send-btn {
    width: 100%;
    margin-left: 0;
    margin-top: 0.7rem;
  }

  .input-bar textarea {
    min-height: 64px;
    font-size: 1.05rem;
    padding: 1.05rem;
  }

  footer .input-bar {
    max-width: 96vw;
  }
}
