html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  background: #222;
  color: #fff;
  font-family: Arial, sans-serif;
  box-sizing: border-box;
}


#table-toolbar {
  position: fixed;              
  top: 0;
  left: 0;
  right: 0;
  min-width: 0;
  background: #222;
  padding: 10px 0 10px 0;
  border-bottom: 1px solid #444;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0;
  z-index: 100;                 
}
#table-toolbar button {
  background: #333;
  color: #fff;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 0 16px; 
  height: 38px; 
  min-width: 0;
  font-size: 15px;
  line-height: 38px; 
  cursor: pointer;
  transition: background 0.2s;
  margin-left: 8px;
  margin-right: 0;
  white-space: nowrap;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;         
}
#table-toolbar button:hover {
  background: #444;
}
#table-toolbar button:first-child {
  margin-left: 16px; 
}
#table-toolbar .toolbar-spacer {
  flex: 1;
}
#saveTableBtn,
#cancelTableBtn {
  margin-left: 8px;
  
}


#table-toolbar button:last-child {
  margin-right: 16px; 
}

#table-toolbar input[type="file"] {
  display: none;
}


#table-editor {
  width: 100%;
  min-height: calc(100vh - 120px);
  padding: 76px 0 10px 0;   
  box-sizing: border-box;
  margin-left: 23px; 
}

.editor-table {
  width: auto;                
  min-width: 0;
  border-collapse: collapse;
  background: #333;
  color: #fff;
  table-layout: auto;         
  position: relative;         
  z-index: 1;                 
}
.editor-table td {
  min-width: 100px;      
  height: 26px;          
  padding: 2px 16px;     
  line-height: 1.1;
  vertical-align: middle;
  word-break: break-word;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  position: relative;
  background: transparent;
  border: 1px solid #888;
  box-sizing: border-box;
  transition: background 0.2s;
  z-index: 1; 
}
.editor-table td[contenteditable="true"] {
  border: 3px solid #888 !important; 
  background: #222;
  height: 26px; 
  overflow: hidden; 
  max-height: 26px; 
}


.editor-table.light-mode td[contenteditable="true"] {
  border: 3px solid #000 !important; 
  background: #fff !important; 
}
.editor-table td input {
  width: 100%;
  background: #222;
  color: #fff;
  border: 1px solid #555;
  padding: 4px;
}
.editor-table td.add {
  color: #4af;
  font-weight: bold;
  text-align: center;
  cursor: pointer;
  background: #222;
}


.editor-table .cell-coord {
  position: absolute;
  top: 2px;
  right: 6px;
  font-size: 11px;
  color: yellow;
  opacity: 0.9;
  pointer-events: none;
  background: #111;
  padding: 1px 4px;
  border-radius: 3px;
}


.editor-table tr:first-child td.header-cell {
  background: #555 !important; 
  font-weight: bold !important; 
}

.editor-table tr:first-child td.header-cell[contenteditable="true"] {
  border: 3px solid #888 !important; 
  background: #444 !important; 
}


.editor-table.light-mode tr:first-child td.header-cell[contenteditable="true"] {
  border: 3px solid #000 !important; 
  background: #555 !important; 
}


.editor-table.light-mode tr:first-child td.header-cell {
  color: #fff !important; 
  font-weight: bold !important; 
}


#xlsxInput {
  display: none;
}


.ai-chat-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}


.ai-input-capsule {
  display: flex;
  align-items: center;
  background: #292929;
  border-radius: 50px;
  padding: 8px 12px 8px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  border: 2px solid transparent;
  background-clip: padding-box;
  position: relative;
  transition: all 0.3s ease;
}

.ai-input-capsule::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  border-radius: 50px;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57, #ff9ff3, #54a0ff);
  background-size: 400% 400%;
  animation: gradientShift 3s ease infinite;
  z-index: -1;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.ai-input-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aee6ff;
  margin-right: 12px;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.ai-input-icon:hover {
  background: rgba(174, 230, 255, 0.1);
  color: #4ecdc4;
  transform: scale(1.1);
}

.ai-input {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 16px;
  outline: none;
  width: 200px;
  padding: 8px 0;
  padding-right: 60px; 
}

.ai-input::placeholder {
  color: #888;
}

.ai-send-btn {
  background: transparent;
  border: none;
  color: #aee6ff;
  cursor: pointer;
  padding: 8px;
  margin-left: 4px;
  border-radius: 50%;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-send-btn:hover {
  background: rgba(174, 230, 255, 0.1);
  color: #4ecdc4;
  transform: scale(1.1);
}

.ai-send-btn:disabled {
  color: #555;
  cursor: not-allowed;
  transform: none;
}

.ai-send-btn:disabled:hover {
  background: transparent;
  color: #555;
  transform: none;
}

.ai-char-counter {
  position: absolute;
  right: 65px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #888;
  pointer-events: none;
  user-select: none;
}


.ai-chat-box {
  width: 388px;
  max-height: 500px; 
  background: #222;
  border-radius: 16px;
  border: 1px solid #444;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ai-chat-header {
  background: #333;
  padding: 12px 16px;
  border-bottom: 1px solid #444;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #aee6ff;
  font-weight: 600;
  font-size: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.ai-chat-close {
  background: transparent;
  border: none;
  color: #aee6ff;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.ai-chat-close:hover {
  background: rgba(174, 230, 255, 0.1);
  color: #ff6b6b;
}

.ai-chat-history {
  background: transparent;
  border: none;
  color: #aee6ff;
  cursor: pointer;
  padding: 2px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.ai-chat-history:hover {
  background: rgba(174, 230, 255, 0.1);
  color: #fff;
}

.ai-chat-new {
  background: transparent;
  border: none;
  color: #aee6ff;
  cursor: pointer;
  padding: 2px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.ai-chat-new:hover {
  background: rgba(174, 230, 255, 0.1);
  color: #fff;
}

.ai-chat-messages {
  flex: 1;
  padding: 16px 16px 20px 16px; 
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px; 
  max-height: 350px; 
  scroll-behavior: auto; 
}

.ai-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: #333;
  border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #666;
}


.ai-message {
  padding: 8px 12px;
  border-radius: 12px;
  max-width: 80%;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.4;
}

.ai-message:last-child {
  margin-bottom: 8px; 
}

.ai-message.user {
  background: #333;
  color: #fff;
  border: 1px solid #4ecdc4;
  align-self: flex-end;
  margin-left: auto;
}

.ai-message.ai {
  background: #333;
  color: #fff;
  align-self: flex-start;
  margin-right: auto;
}


.ai-message.loading {
  background: #333;
  color: #aee6ff;
  align-self: flex-start;
  margin-right: auto;
  font-style: italic;
}

.ai-message.loading::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #aee6ff;
  margin-left: 8px;
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0%, 60%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  30% {
    transform: scale(1.2);
    opacity: 1;
  }
}

.ai-chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #888;
  font-size: 16px;
  text-align: center;
  padding: 48px 0 32px 0;
  opacity: 0.85;
  pointer-events: none;
  user-select: none;
}
.ai-chat-welcome svg {
  margin-bottom: 12px;
  stroke: #888;
}


.ai-message .loader {
  display: inline-block;
  margin-left: 12px;
  margin-right: 12px;
  vertical-align: middle;
  font-size: 3px; 
  transform: scale(0.5) translateY(-8px); 
}


.loader, .loader:before, .loader:after {
  border-radius: 50%;
  width: 2.5em;
  height: 2.5em;
  animation-fill-mode: both;
  animation: bblFadInOut 1.8s infinite ease-in-out;
}
.loader {
  color: #FFF;
  font-size: 7px;
  position: relative;
  text-indent: -9999em;
  transform: translateZ(0);
  animation-delay: -0.16s;
}
.loader:before,
.loader:after {
  content: '';
  position: absolute;
  top: 0;
}
.loader:before {
  left: -3.5em;
  animation-delay: -0.32s;
}
.loader:after {
  left: 3.5em;
}

@keyframes bblFadInOut {
  0%, 80%, 100% { box-shadow: 0 2.5em 0 -1.3em }
  40% { box-shadow: 0 2.5em 0 0 }
}