/* CSS Variables for easy customization */
:root {
  --bg-main: #f5f5f5;
  --bg-pane: #ffffff;
  --bg-header: #f0f0f0;
  --border-color: #e0e0e0;
  --text-primary: #333333;
  --text-secondary: #666666;
  --accent-color: #4a90e2;
  --accent-hover: #357abd;
  --border-radius: 8px;
  --grid-col-left: 1fr;
  --grid-col-center: 1.15fr;
  --grid-col-right: 1fr;
  --grid-min-left: 200px;
  --grid-min-center: 260px;
  --grid-min-right: 220px;
  --header-height: 50px;
  --navbar-height: 60px;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 4px 8px rgba(0, 0, 0, 0.15);
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  margin: 0;
  background-color: var(--bg-main);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* 頂部導航欄 */
.top-navbar {
  position: fixed;
  inset-inline: 0;
  top: 0;
  height: var(--navbar-height);
  background-color: rgba(248, 250, 252, 0.95);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-inline: 20px;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.navbar-center {
  flex: 0;
  display: flex;
  margin-left: auto;
  margin-right: 12px;
}

.navbar-nav {
  display: flex;
  gap: 28px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(229, 231, 235, 0.9);
}

/* 突顯 (NEW) Homework nav item */
.nav-item-homework {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-item-homework .nav-badge {
  font-size: 14px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  background: #4a90e2;
  color: #ffffff;
  letter-spacing: 0.06em;
}

.nav-item-homework .nav-label {
  font-weight: 600;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.navbar-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.navbar-icon img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.navbar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.navbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.navbar-nav {
  display: flex;
  gap: 36px;
  align-items: center;
}

.nav-item {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 18px;
  font-weight: bold;
  padding: 8px 12px;
  border-radius: var(--border-radius);
  transition: all 0.2s ease;
}

.nav-item:hover {
  background-color: var(--bg-header);
  color: var(--accent-color);
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-dropdown {
  position: relative;
}

.account-btn {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.account-btn:hover {
  background-color: var(--bg-header);
  border-color: var(--accent-color);
}

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background-color: var(--bg-pane);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-hover);
  min-width: 150px;
  display: none;
  flex-direction: column;
  z-index: 1001;
}

.account-menu.show {
  display: flex;
}

.account-menu-item {
  background-color: transparent;
  border: none;
  color: var(--text-primary);
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s ease;
}

.account-menu-item:hover {
  background-color: var(--bg-header);
}

.account-menu-item:first-child {
  border-top-left-radius: var(--border-radius);
  border-top-right-radius: var(--border-radius);
}

.account-menu-item:last-child {
  border-bottom-left-radius: var(--border-radius);
  border-bottom-right-radius: var(--border-radius);
}

/* 三欄：左（Step-by-Step Guidelines + Question Analysis）、中（圖片）、右（chat）*/
.main-grid-container {
  display: grid;
  grid-template-columns:
    minmax(var(--grid-min-left), var(--grid-col-left))
    minmax(var(--grid-min-center), var(--grid-col-center))
    minmax(var(--grid-min-right), var(--grid-col-right));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  grid-template-areas:
    "analysis  homework chat"
    "guidelines homework chat";
  gap: clamp(8px, 1vw, 12px);
  height: calc(100vh - var(--navbar-height) - 16px);
  margin-top: calc(var(--navbar-height) + 8px);
  padding: 10px 16px 16px;
  overflow: hidden;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  position: relative; /* 讓拖拽手柄可以絕對定位 */
}

.pane-1 { /* Homework 圖片：中間欄，直向佔兩格 */
  grid-area: homework;
}

.pane-2 { /* Question Analysis：左上 */
  grid-area: analysis;
}

.pane-3 { /* Step-by-Step Guidelines：左下 */
  grid-area: guidelines;
}

.pane-4 { /* Chat box：右邊佔滿上下 */
  grid-area: chat;
}

/* 網格窗格基礎樣式 - 填滿所屬格，不獨立縮放 */
.grid-pane {
  background-color: var(--bg-pane);
  display: flex;
  flex-direction: column;
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  box-sizing: border-box;
  resize: none;
  min-width: 220px;
  min-height: 160px;
}
/* 禁用內建 resize 手柄，統一交由 grid 伸縮 */
.grid-pane::-webkit-resizer {
  display: none;
}

/* 確保窗格內容可以正確滾動 */
.pane-content {
  overflow: auto;
  min-width: 0;
  min-height: 0;
}

.main-grid-container > .grid-pane {
  min-width: 0;
  min-height: 0;
}

/* 中間欄左右拖拽手柄 */
.grid-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12px;
  margin-left: -6px;
  cursor: col-resize;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.grid-resizer::before {
  content: '';
  width: 2px;
  height: 40px;
  background: var(--border-color);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.03);
}

@media (max-width: 1100px) {
  .main-grid-container {
    grid-template-columns:
      minmax(180px, 1fr)
      minmax(220px, 1.1fr)
      minmax(180px, 1fr);
  }
}

/* 窗格標題欄 */
.pane-header {
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pane-header h3 {
  margin: 0;
  font-size: 20px;
  font-weight: bold;
  color: var(--text-primary);
}

/* 窗格內容區域 */
.pane-content {
  flex: 1;
  overflow: auto;
  padding: 16px;
  min-height: 0;
}

/* 自定義滾動條 */
.pane-content::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.pane-content::-webkit-scrollbar-track {
  background: var(--bg-header);
}

.pane-content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.pane-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* 象限1: 左上 - Original Homework */
.homework-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
}

.upload-btn {
  background-color: var(--accent-color);
  border: none;
  color: white;
  padding: 12px 24px;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  margin-bottom: 16px;
}

.upload-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

.homework-image-container {
  width: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  flex: 1;
}

.homework-image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

/* 象限2: 右上 - Question Analysis */
.analysis-content {
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 14px;
}

.analysis-content p {
  margin: 0;
}

/* 象限3: 左下 - Solving Guidelines */
.guidelines-content {
  color: var(--text-primary);
  line-height: 1.8;
  font-size: 14px;
}

.guidelines-content ol {
  margin: 0;
  padding-left: 20px;
}

.guidelines-content li {
  margin-bottom: 8px;
}

/* 象限4: 右下 - AI Chat */
.chat-pane-content {
  display: flex;
  flex-direction: column;
  padding: 0;
  height: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 85%;
}

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

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background-color: var(--accent-color);
  color: white;
}

.message.ai .message-avatar {
  background-color: var(--bg-header);
  color: var(--text-primary);
}

.message-content {
  background-color: var(--bg-header);
  border-radius: 12px;
  padding: 12px 16px;
  position: relative;
  word-wrap: break-word;
  max-width: 100%;
}

.message.user .message-content {
  background-color: #e3f2fd;
  color: var(--text-primary);
}

.message.ai .message-content {
  background-color: var(--bg-header);
  color: var(--text-primary);
}

.message-text {
  line-height: 1.5;
  font-size: 14px;
}

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  text-align: right;
}

.message.ai .message-time {
  text-align: left;
}

.chat-input-area {
  border-top: 1px solid var(--border-color);
  padding: 12px 16px;
  background-color: var(--bg-pane);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 圖標工具欄樣式 */
.icon-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 8px;
}

.icon-toolbar-item {
  width: 40px;
  height: 40px;
  background-color: #ffffff;
  border: 2px solid;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.icon-toolbar-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.icon-toolbar-item:active {
  transform: translateY(0);
}

.chat-input-area textarea {
  width: 100%;
  min-height: 60px;
  max-height: 120px;
  resize: vertical;
  font-family: inherit;
  background-color: var(--bg-pane);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  padding: 12px;
  font-size: 14px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}

.chat-input-area textarea:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

.chat-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.status.error {
  color: #d32f2f;
}

.status.success {
  color: #2e7d32;
}

.input-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-actions button {
  background-color: var(--accent-color);
  border: none;
  color: white;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background-color var(--transition-fast),
    box-shadow var(--transition-fast), transform var(--transition-fast);
}

/* 專門覆蓋 chat 入面嘅 send-btn 樣式（要放喺 .chat-actions button 後面） */
.chat-actions .send-btn {
  background-color: #ffffff;
  color: #111827;              /* icon 用黑色 */
  border: 1px solid var(--border-color);
  padding: 7px 12px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
}

/* 保證飛機 path 一定有顏色 */
.chat-actions .send-btn svg path {
  fill: #111827 !important;
  stroke: #111827 !important;
  stroke-width: 1;
}


.chat-actions .send-btn svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;          /* 跟住上面嘅 color 走 → 黑色 */
}


.chat-actions .send-btn:hover {
  background-color: #f3f4f6 !important;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.chat-actions button:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.chat-actions button:active {
  transform: translateY(0);
}

.voice-btn {
  background-color: #ff6b6b;
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
  min-width: 40px;
}

.voice-btn:hover {
  background-color: #ff5252;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.chat-icon-btn {
  background-color: #ffffff;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.chat-icon-btn:hover {
  background-color: #f3f4f6;
  box-shadow: var(--shadow-sm);
}

.send-btn {
  background-color: #ffffff;
  color: #111827;           /* icon 用 currentColor，會變黑 */
  border: 1px solid var(--border-color);
  padding: 7px 12px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
}

.send-btn svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;       /* 用 button color，方便之後改色 */
}

.send-btn:hover {
  background-color: #f3f4f6;
  box-shadow: var(--shadow-sm);
}

.voice-btn.recording {
  background-color: #4caf50;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* 模態框樣式 */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  background-color: var(--bg-pane);
  margin: 10% auto;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  width: 400px;
  max-width: 90%;
  box-shadow: var(--shadow-hover);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.1em;
}

.close {
  color: var(--text-secondary);
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s ease;
}

.close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 12px;
  background-color: var(--bg-pane);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s ease;
  box-sizing: border-box;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.remember-me,
.agree-terms {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}

.remember-me input,
.agree-terms input {
  width: auto;
  margin-right: 8px;
}

.forgot-password {
  color: var(--accent-color);
  text-decoration: none;
  font-size: 13px;
  transition: color 0.2s ease;
}

.forgot-password:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.login-submit-btn,
.register-submit-btn {
  width: 100%;
  padding: 12px;
  background-color: var(--accent-color);
  border: none;
  border-radius: var(--border-radius);
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.login-submit-btn:hover,
.register-submit-btn:hover {
  background-color: var(--accent-hover);
}

.login-footer,
.register-footer {
  text-align: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.login-footer p,
.register-footer p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.login-footer a,
.register-footer a {
  color: var(--accent-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

.login-footer a:hover,
.register-footer a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* 響應式設計 */
@media (max-width: 768px) {
  .main-grid-container {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, 1fr);
  }
  
  .navbar-center {
    display: none;
  }
  
  .navbar-title {
  font-size: 16px;
}
}

/* 隱藏的元素（保留功能） */
.sources-list-hidden,
.explore-page-hidden,
.request-preview-area-hidden {
  display: none !important;
}

/* History Modal 樣式 */
.history-modal-content {
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.history-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-height: 300px;
  max-height: calc(80vh - 100px);
}

.chat-history {
  padding: 0;
}

.history-item {
  background-color: var(--bg-header);
  border-radius: var(--border-radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
}

.history-item:hover {
  background-color: #f5f5f5;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.history-item.active {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  color: white;
}

.history-item.active .history-title,
.history-item.active .history-preview,
.history-item.active .history-time {
  color: white;
}

.history-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.history-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-size: 14px;
  flex: 1;
}

.history-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 16px;
  transition: all 0.2s ease;
}

.history-delete-btn:hover {
  background-color: rgba(211, 47, 47, 0.1);
  color: #d32f2f;
}

.history-preview {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  color: var(--text-secondary);
  font-size: 11px;
}

.no-history {
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 40px;
  padding: 20px;
}

/* 圖標選擇器樣式 */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.icon-option {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background-color: var(--bg-header);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0 auto;
}

.icon-option:hover {
  background-color: var(--bg-pane);
  border-color: var(--accent-color);
  transform: scale(1.05);
}
