/* ============================================
   Hamiz GPT - Book Creator
   Main Stylesheet
   ============================================ */

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

:root {
  --bg-primary: #f8f7f4;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0ede8;
  --bg-sidebar: #1a1a2e;
  --bg-sidebar-hover: #16213e;
  --bg-sidebar-active: #0f3460;
  --bg-input: #ffffff;
  --bg-message-user: #0f3460;
  --bg-message-ai: #ffffff;
  --bg-modal: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #4a4a6a;
  --text-muted: #8a8aaa;
  --text-sidebar: #c8c8e8;
  --text-sidebar-muted: #7878a8;
  --text-on-user: #ffffff;
  --text-link: #0f3460;
  --border-color: #e0ddd8;
  --border-sidebar: #2a2a4a;
  --accent-primary: #0f3460;
  --accent-secondary: #e94560;
  --accent-success: #2d7a4f;
  --accent-warning: #c4841a;
  --accent-danger: #c0392b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.16);
  --sidebar-width: 280px;
  --topbar-height: 60px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.2s ease;
  --font: 'Cairo', 'Segoe UI', sans-serif;
}

.dark-mode {
  --bg-primary: #0d0d1a;
  --bg-secondary: #12122a;
  --bg-tertiary: #1a1a30;
  --bg-sidebar: #0a0a18;
  --bg-sidebar-hover: #12122a;
  --bg-sidebar-active: #1a1a40;
  --bg-input: #1a1a30;
  --bg-message-user: #1a3a6a;
  --bg-message-ai: #12122a;
  --bg-modal: #1a1a30;
  --text-primary: #e8e8f8;
  --text-secondary: #a8a8c8;
  --text-muted: #6868a0;
  --text-sidebar: #c8c8e8;
  --text-sidebar-muted: #6868a0;
  --text-on-user: #ffffff;
  --text-link: #6a9fd8;
  --border-color: #2a2a4a;
  --border-sidebar: #1a1a3a;
  --accent-primary: #4a7fd8;
  --accent-secondary: #e94560;
  --accent-success: #3a9a60;
  --accent-warning: #e0a020;
  --accent-danger: #e05040;
  --shadow-sm: 0 1px 3px 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);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--accent-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

body { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ============================================ Sidebar */
.sidebar {
  width: var(--sidebar-width); min-width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden;
  transition: transform 0.25s ease;
  border-left: 1px solid var(--border-sidebar); z-index: 100;
}
.sidebar:not(.open) { width: 0; min-width: 0; overflow: hidden; }

.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border-sidebar); flex-shrink: 0; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 22px; }
.logo-text { font-size: 16px; font-weight: 700; color: #ffffff; letter-spacing: 0.5px; }
.sidebar-actions { display: flex; gap: 6px; }

.sidebar-auth, .sidebar-user { padding: 12px 16px; border-bottom: 1px solid var(--border-sidebar); flex-shrink: 0; }


.btn-auth-help {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 6px;
    border-radius: var(--radius-sm);
    text-align: center;
    display: none;
}



.btn-login { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 10px 16px; background: #4285f4; color: #ffffff; border: none; border-radius: var(--radius-md); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: background var(--transition); }
.btn-login:hover { background: #3b78e7; }

.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.user-info { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text-sidebar); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout { background: transparent; border: 1px solid #e9456060; color: #e94560; padding: 5px 12px; border-radius: var(--radius-sm); font-family: var(--font); font-size: 12px; cursor: pointer; flex-shrink: 0; }

.sessions-list-header { padding: 12px 16px 8px; font-size: 11px; font-weight: 700; color: var(--text-sidebar-muted); letter-spacing: 1px; text-transform: uppercase; flex-shrink: 0; }
.sessions-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.sessions-list::-webkit-scrollbar { width: 4px; }
.sessions-list::-webkit-scrollbar-thumb { background: var(--border-sidebar); border-radius: 2px; }
.sessions-empty { padding: 16px; text-align: center; color: var(--text-sidebar-muted); font-size: 13px; }

.session-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-radius: var(--radius-md); cursor: pointer; transition: background var(--transition); gap: 8px; margin-bottom: 2px; }
.session-item:hover { background: var(--bg-sidebar-hover); }
.session-item.active { background: var(--bg-sidebar-active); }
.session-item-content { flex: 1; overflow: hidden; }
.session-item-title { font-size: 13px; font-weight: 600; color: var(--text-sidebar); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item-meta { font-size: 11px; color: var(--text-sidebar-muted); margin-top: 2px; }
.session-item-delete { background: transparent; border: none; color: var(--text-sidebar-muted); cursor: pointer; padding: 4px; border-radius: var(--radius-sm); opacity: 0; transition: opacity var(--transition); flex-shrink: 0; display: flex; }
.session-item:hover .session-item-delete { opacity: 1; }
.session-item-delete:hover { color: #e94560; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border-sidebar); display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.btn-settings, .btn-theme { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: transparent; border: none; border-radius: var(--radius-md); color: var(--text-sidebar); font-family: var(--font); font-size: 13px; cursor: pointer; width: 100%; text-align: right; transition: background var(--transition); }
.btn-settings:hover, .btn-theme:hover { background: var(--bg-sidebar-hover); }

/* ============================================ Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; background: var(--bg-primary); min-width: 0; }

/* ============================================ Topbar */
.topbar { height: var(--topbar-height); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); flex-shrink: 0; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; overflow: hidden; }
.topbar-title { font-size: 16px; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-left { display: flex; align-items: center; gap: 10px; flex-shrink: 0; flex-wrap: wrap; }

.btn-mode { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-tertiary); color: var(--text-secondary); font-family: var(--font); font-size: 13px; cursor: pointer; transition: all var(--transition); }
.btn-mode.active { background: var(--accent-primary); color: #ffffff; border-color: var(--accent-primary); }
.btn-mode:hover:not(.active) { background: var(--border-color); }

.btn-export, .btn-export-pdf { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--accent-secondary); color: #ffffff; border: none; border-radius: var(--radius-md); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-export:hover, .btn-export-pdf:hover { opacity: 0.88; }
.btn-export-pdf { background: var(--accent-primary); }

/* ============================================ Book Info Banner */
.book-info-banner { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; background: linear-gradient(135deg, #0f346015, #e9456010); border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.book-mode-indicator { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.page-counter { font-size: 13px; font-weight: 700; color: var(--accent-primary); background: var(--bg-secondary); padding: 4px 12px; border-radius: 20px; border: 1px solid var(--border-color); }

/* ============================================ Thinking Indicator */
.thinking-indicator { display: flex; align-items: center; gap: 12px; padding: 12px 20px; flex-shrink: 0; animation: fadeIn 0.3s ease; }
.thinking-dots { display: flex; align-items: center; gap: 5px; }
.thinking-dots span { width: 8px; height: 8px; background: var(--accent-primary); border-radius: 50%; animation: thinkBounce 1.4s ease-in-out infinite; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinkBounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1.2); opacity: 1; } }
.thinking-text { font-size: 13px; color: var(--text-muted); font-weight: 600; animation: textPulse 2.5s ease-in-out infinite; }
@keyframes textPulse { 0%, 100% { opacity: 0.7; } 50% { opacity: 1; } }

/* ============================================ Chat Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 20px; }
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

.welcome-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; flex: 1; padding: 40px 20px; min-height: 300px; }
.welcome-icon { font-size: 56px; margin-bottom: 16px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.welcome-title { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-bottom: 10px; }
.welcome-desc { font-size: 15px; color: var(--text-secondary); max-width: 420px; margin-bottom: 24px; line-height: 1.7; }
.welcome-tips { display: flex; flex-direction: column; gap: 10px; max-width: 440px; width: 100%; }
.tip { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 12px 16px; font-size: 13px; color: var(--text-secondary); text-align: right; }
.tip strong { color: var(--accent-primary); }

/* Message Bubbles */
.message { display: flex; flex-direction: column; max-width: 80%; animation: msgIn 0.25s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.message.user { align-self: flex-start; }
.message.ai { align-self: flex-end; max-width: 88%; }
.message-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; color: var(--text-muted); }
.message.user .message-header { flex-direction: row; }
.message.ai .message-header { flex-direction: row-reverse; }
.message-role-icon { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
.message.user .message-role-icon { background: var(--accent-primary); color: white; }
.message.ai .message-role-icon { background: linear-gradient(135deg, #0f3460, #e94560); color: white; }

.message-bubble { padding: 16px 20px; border-radius: var(--radius-lg); font-size: 14.5px; line-height: 1.8; word-break: break-word; }
.message.user .message-bubble { background: var(--bg-message-user); color: var(--text-on-user); border-bottom-right-radius: var(--radius-sm); white-space: pre-wrap; }
.message.ai .message-bubble { background: var(--bg-message-ai); color: var(--text-primary); border: 1px solid var(--border-color); border-bottom-left-radius: var(--radius-sm); box-shadow: var(--shadow-sm); letter-spacing: 0.01em; }

.page-badge { display: inline-flex; align-items: center; gap: 6px; background: linear-gradient(135deg, var(--accent-primary), #1a4a80); color: #ffffff; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; margin-bottom: 10px; }

.message-actions { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity var(--transition); }
.message:hover .message-actions { opacity: 1; }
.message.ai .message-actions { justify-content: flex-end; }
.btn-copy, .btn-delete-msg { padding: 4px 10px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-secondary); font-family: var(--font); font-size: 11px; cursor: pointer; transition: all var(--transition); }
.btn-copy:hover { background: var(--border-color); }
.btn-delete-msg { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-delete-msg:hover { background: #fff0f0; border-color: #ffcdd2; color: #c0392b; }
.dark-mode .btn-delete-msg:hover { background: rgba(192,57,43,0.15); color: #ff6b6b; }

.streaming-cursor::after { content: '▋'; display: inline; animation: blink 0.8s step-end infinite; color: var(--accent-primary); }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ============================================ Code Blocks */
.code-block-wrapper { margin: 12px 0; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border-color); }
.code-block-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; background: #1e2a3a; border-bottom: 1px solid #2a3a5a; }
.code-lang { font-size: 11px; font-weight: 700; color: #90cdf4; text-transform: uppercase; letter-spacing: 0.5px; }
.btn-copy-code { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: #e2e8f0; border-radius: 6px; padding: 3px 10px; font-size: 11px; cursor: pointer; font-family: var(--font); transition: background 0.2s; }
.btn-copy-code:hover { background: rgba(255,255,255,0.2); }
.code-block { margin: 0; padding: 14px 16px; background: #1a2332; overflow-x: auto; font-size: 13px; line-height: 1.6; }
.code-block code { font-family: 'Fira Code', 'Courier New', monospace; }
.inline-code { background: var(--bg-tertiary); border: 1px solid var(--border-color); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; }
.dark-mode .inline-code { background: #2a2a4a; border-color: #3a3a5a; }

/* Markdown helpers */
.md-para { margin: 0 0 8px; }
.md-para:last-child { margin-bottom: 0; }
.md-h2 { font-size: 18px; font-weight: 700; margin: 18px 0 10px; color: var(--text-primary); border-bottom: 1px solid var(--border-color); padding-bottom: 6px; }
.md-h3 { font-size: 16px; font-weight: 700; margin: 14px 0 8px; color: var(--text-primary); }
.md-h4 { font-size: 14.5px; font-weight: 700; margin: 12px 0 6px; color: var(--text-primary); }
.md-list { padding-right: 22px; margin: 8px 0; }
.md-list li { margin-bottom: 5px; line-height: 1.7; }
.md-ol { list-style: arabic-indic; }
.md-hr { border: none; border-top: 1px solid var(--border-color); margin: 16px 0; }
.md-blockquote { border-right: 3px solid var(--accent-primary); padding: 8px 14px; margin: 10px 0; background: var(--bg-tertiary); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-secondary); font-size: 14px; }
.dark-mode .md-blockquote { background: rgba(255,255,255,0.04); }

/* Markdown Tables */
.md-table-wrap { overflow-x: auto; margin: 12px 0; border-radius: var(--radius-md); border: 1px solid var(--border-color); }
.md-table { width: 100%; border-collapse: collapse; font-size: 13.5px; direction: rtl; }
.md-table th { padding: 10px 14px; background: var(--bg-tertiary); font-weight: 700; text-align: right; border-bottom: 2px solid var(--border-color); color: var(--text-primary); white-space: nowrap; }
.md-table td { padding: 9px 14px; border-bottom: 1px solid var(--border-color); text-align: right; color: var(--text-secondary); }
.md-table tbody tr:last-child td { border-bottom: none; }
.md-table tbody tr:hover { background: var(--bg-tertiary); }
.dark-mode .md-table th { background: rgba(255,255,255,0.06); }
.dark-mode .md-table tbody tr:hover { background: rgba(255,255,255,0.03); }

/* ============================================ Source Links */
.source-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; margin: 8px 0; background: #f0fff4; border: 1px solid #9ae6b4; border-radius: var(--radius-md); font-size: 12px; }
.dark-mode .source-links { background: rgba(45,122,79,0.1); border-color: rgba(79,200,122,0.3); }
.source-label { font-weight: 700; color: var(--accent-success); margin-left: 8px; }
.source-link { background: rgba(45,122,79,0.1); padding: 3px 10px; border-radius: 20px; color: var(--accent-success); font-size: 11px; font-weight: 600; transition: background 0.2s; }
.source-link:hover { background: rgba(45,122,79,0.2); text-decoration: none; }

/* Search indicator */
.search-indicator { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 8px 14px; margin: 8px 0; background: #ebf8ff; border: 1px solid #90cdf4; border-radius: var(--radius-md); font-size: 12px; color: #1a4a70; animation: fadeIn 0.3s ease; }
.dark-mode .search-indicator { background: rgba(144,205,244,0.1); border-color: rgba(144,205,244,0.3); color: #7ecfff; }
.search-query { background: rgba(144,205,244,0.3); padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============================================ Input Area */
.input-area { padding: 16px 20px 20px; background: var(--bg-secondary); border-top: 1px solid var(--border-color); flex-shrink: 0; }
.input-area.drag-over { background: rgba(15,52,96,0.06); outline: 2px dashed var(--accent-primary); outline-offset: -4px; border-radius: var(--radius-md); }

.attachment-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; padding: 10px 12px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); }
.attachment-preview.hidden { display: none; }

.btn-attach { position: relative; display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-md); color: var(--text-secondary); cursor: pointer; transition: all var(--transition); flex-shrink: 0; }
.btn-attach:hover { background: var(--border-color); color: var(--text-primary); }
.btn-attach.has-attachments { background: rgba(15,52,96,0.08); border-color: var(--accent-primary); color: var(--accent-primary); }
.attach-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; background: var(--accent-primary); color: #fff; font-size: 10px; font-weight: 700; border-radius: 20px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

.att-chip { display: flex; align-items: center; gap: 8px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 6px 10px; }
.att-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.att-chip-name { font-size: 12px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.att-chip-size { font-size: 10px; color: var(--text-muted); }
.att-chip-remove { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 0 4px; line-height: 1; }
.att-chip-remove:hover { color: #c0392b; }

.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.msg-att-image { border-radius: var(--radius-md); overflow: hidden; max-width: 280px; }
.msg-att-img { display: block; max-width: 280px; max-height: 200px; object-fit: cover; border-radius: var(--radius-md); }
.msg-att-file { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-md); font-size: 12px; color: var(--text-secondary); }
.msg-att-size { font-size: 10px; color: var(--text-muted); }

.input-container { display: flex; align-items: flex-end; gap: 10px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: var(--radius-xl); padding: 10px 10px 10px 16px; transition: border-color var(--transition), box-shadow var(--transition); }
.input-container:focus-within { border-color: var(--accent-primary); box-shadow: 0 0 0 3px rgba(15,52,96,0.12); }
.dark-mode .input-container:focus-within { box-shadow: 0 0 0 3px rgba(74,127,216,0.15); }

.user-input { flex: 1; background: transparent; border: none; outline: none; font-family: var(--font); font-size: 14.5px; color: var(--text-primary); resize: none; max-height: 180px; overflow-y: auto; line-height: 1.6; direction: auto; }
.user-input::placeholder { color: var(--text-muted); }

.btn-send { width: 40px; height: 40px; background: var(--accent-primary); color: #ffffff; border: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all var(--transition); flex-shrink: 0; }
.btn-send:hover { background: #1a4a80; transform: scale(1.06); }
.btn-send:disabled { background: var(--border-color); cursor: not-allowed; transform: none; }

.input-footer { display: flex; align-items: center; justify-content: space-between; padding-top: 8px; }
.input-footer-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.input-footer-right { display: flex; align-items: center; gap: 8px; }

.model-badge, .provider-badge, .key-badge { font-size: 11px; font-weight: 600; color: var(--text-muted); background: var(--bg-tertiary); padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border-color); }
.key-badge { color: #2d7a4f; background: rgba(45,122,79,0.08); border-color: rgba(45,122,79,0.25); transition: all 0.3s ease; }
.key-badge.switched { animation: keySwitch 1.5s ease; }
@keyframes keySwitch { 0% { background: rgba(45,122,79,0.25); transform: scale(1.1); } 100% { background: rgba(45,122,79,0.08); transform: scale(1); } }
.web-search-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: #1a5f99; background: #dbeeff; padding: 3px 10px; border-radius: 20px; border: 1px solid #90cdf4; }
.dark-mode .web-search-badge { color: #7ecfff; background: rgba(144,205,244,0.12); border-color: rgba(144,205,244,0.3); }
.input-hint { font-size: 11px; color: var(--text-muted); }

/* Settings shortcut button */
.btn-settings-shortcut { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 50%; color: var(--text-muted); cursor: pointer; transition: all var(--transition); }
.btn-settings-shortcut:hover { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }

/* ============================================ Buttons */
.btn-icon { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; background: transparent; border: none; border-radius: var(--radius-sm); color: var(--text-sidebar); cursor: pointer; transition: background var(--transition); }
.btn-icon:hover { background: var(--bg-sidebar-hover); }
.main-content .btn-icon { color: var(--text-secondary); }
.main-content .btn-icon:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.btn-icon-sm { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; background: transparent; border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-secondary); cursor: pointer; }
.btn-icon-sm:hover { background: var(--bg-tertiary); }

/* ============================================ Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; animation: fadeIn 0.15s ease; }
.modal { background: var(--bg-modal); border-radius: var(--radius-lg); width: 100%; max-width: 520px; max-height: 85vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slideUp 0.2s ease; border: 1px solid var(--border-color); }
.modal-sm { max-width: 380px; }
.modal-wide { max-width: 680px; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.modal-header h3 { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }
.modal-body p { color: var(--text-secondary); font-size: 14px; line-height: 1.7; }
.modal-footer { display: flex; align-items: center; justify-content: flex-start; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border-color); flex-shrink: 0; }

/* ============================================ Settings Form */
.settings-section { margin-bottom: 28px; }
.settings-section:last-child { margin-bottom: 0; }
.settings-section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border-color); }
.settings-field { margin-bottom: 16px; }
.settings-field:last-child { margin-bottom: 0; }
.settings-field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.settings-input-short { width: 100px; }
.settings-input, .settings-select, .settings-textarea { width: 100%; padding: 10px 14px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); font-family: var(--font); font-size: 14px; color: var(--text-primary); outline: none; transition: border-color var(--transition); }
.settings-input:focus, .settings-select:focus, .settings-textarea:focus { border-color: var(--accent-primary); }
.settings-textarea { resize: vertical; direction: rtl; }
.settings-hint { display: block; margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.input-with-toggle { display: flex; gap: 8px; align-items: center; }
.input-with-toggle .settings-input { flex: 1; }

/* Provider tabs */
.provider-tabs { display: flex; gap: 8px; }
.provider-tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px; border: 2px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-primary); color: var(--text-secondary); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.provider-tab:hover { border-color: var(--accent-primary); }
.provider-tab.active { border-color: var(--accent-primary); background: rgba(15,52,96,0.07); color: var(--accent-primary); }
.dark-mode .provider-tab.active { background: rgba(74,127,216,0.12); color: #7ecfff; }
.provider-tab-logo { width: 26px; height: 26px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; flex-shrink: 0; }
.provider-logo-gemini { background: linear-gradient(135deg, #4285f4, #34a853); color: #fff; }
.provider-logo-deepseek { background: linear-gradient(135deg, #1a1a2e, #16213e); color: #7ecfff; border: 1px solid #2a3a5e; }

/* API Key Pool */
.api-key-pool-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.api-key-pool-count { font-size: 11px; font-weight: 700; color: var(--accent-primary); background: rgba(15,52,96,0.08); padding: 2px 10px; border-radius: 20px; }
.api-key-pool-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.api-key-pool-empty { font-size: 12px; color: var(--text-muted); text-align: center; padding: 12px; background: var(--bg-primary); border: 1px dashed var(--border-color); border-radius: var(--radius-md); }
.api-key-pool-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--radius-md); cursor: pointer; transition: border-color var(--transition); }
.api-key-pool-item:hover { border-color: var(--accent-primary); }
.api-key-pool-item.active { border-color: #34a853; background: rgba(52,168,83,0.04); }
.api-key-pool-item-left { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.api-key-status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-active { background: #34a853; box-shadow: 0 0 0 3px rgba(52,168,83,0.2); }
.dot-idle { background: var(--border-color); }
.api-key-pool-item-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); }
.api-key-pool-item-value { font-size: 12px; font-family: monospace; color: var(--text-muted); }
.api-key-pool-item-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.api-key-tag-active { font-size: 10px; font-weight: 700; color: #34a853; background: rgba(52,168,83,0.1); padding: 2px 8px; border-radius: 20px; }
.btn-activate-key { font-size: 11px; padding: 3px 10px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-secondary); font-family: var(--font); cursor: pointer; transition: all var(--transition); }
.btn-activate-key:hover { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }
.btn-remove-key { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; background: transparent; border: none; border-radius: 6px; color: var(--text-muted); cursor: pointer; font-size: 16px; }
.btn-remove-key:hover { color: #c0392b; background: #fff0f0; }
.dark-mode .btn-remove-key:hover { background: rgba(192,57,43,0.15); color: #ff6b6b; }

.api-key-add-row { display: flex; gap: 8px; align-items: stretch; }
.api-key-add-input-wrap { flex: 1; }
.btn-add-key { display: flex; align-items: center; gap: 6px; padding: 8px 14px; background: var(--accent-primary); color: #fff; border: none; border-radius: var(--radius-md); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn-add-key:hover { background: #1a4a80; }

/* Model Cards */
.model-cards-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.model-card { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 2px solid var(--border-color); border-radius: var(--radius-md); cursor: pointer; transition: all var(--transition); background: var(--bg-primary); }
.model-card:hover { border-color: var(--accent-primary); }
.model-card.selected { border-color: var(--accent-primary); background: rgba(15,52,96,0.08); }
.dark-mode .model-card.selected { background: rgba(74,127,216,0.12); }
.model-card-name { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.model-card-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.model-card-badge { display: inline-block; margin-top: 4px; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; width: fit-content; }
.badge-free { background: #2d7a4f20; color: var(--accent-success); }
.badge-fast { background: #c4841a20; color: var(--accent-warning); }
.badge-powerful { background: rgba(15,52,96,0.15); color: var(--accent-primary); }

/* Toggle */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--border-color); margin-bottom: 14px; }
.toggle-info { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.toggle-title { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.toggle-desc { font-size: 11px; color: var(--text-muted); line-height: 1.5; }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider { position: absolute; inset: 0; background: var(--border-color); border-radius: 24px; transition: background 0.25s; }
.toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; background: #fff; border-radius: 50%; top: 3px; left: 3px; transition: transform 0.25s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-switch input:checked + .toggle-slider { background: var(--accent-primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

.highlight-box-inline { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: 8px; font-size: 12px; line-height: 1.6; margin: 8px 0; }
.highlight-box-inline.info { background: #ebf8ff; border: 1px solid #90cdf4; color: #1a4a70; }
.dark-mode .highlight-box-inline.info { background: rgba(144,205,244,0.08); border-color: rgba(144,205,244,0.25); color: #7ecfff; }

.date-awareness-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); padding: 8px 0 4px; }

/* ============================================ Buttons */
.btn-primary { padding: 10px 22px; background: var(--accent-primary); color: #ffffff; border: none; border-radius: var(--radius-md); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-primary:hover { opacity: 0.88; }
.btn-secondary { padding: 10px 22px; background: transparent; color: var(--text-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-secondary:hover { background: var(--bg-tertiary); }
.btn-danger { padding: 10px 22px; background: var(--accent-danger); color: #ffffff; border: none; border-radius: var(--radius-md); font-family: var(--font); font-size: 14px; font-weight: 600; cursor: pointer; }

/* ============================================ Toast */
.toast-container { position: fixed; bottom: 24px; left: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); box-shadow: var(--shadow-md); font-size: 13px; color: var(--text-primary); pointer-events: all; animation: toastIn 0.25s ease; max-width: 300px; transition: opacity 0.3s, transform 0.3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.toast.success { border-right: 3px solid var(--accent-success); }
.toast.error { border-right: 3px solid var(--accent-danger); }
.toast.info { border-right: 3px solid var(--accent-primary); }

.error-message { display: flex; align-items: flex-start; gap: 10px; padding: 14px 18px; background: rgba(192,57,43,0.08); border: 1px solid rgba(192,57,43,0.25); border-radius: var(--radius-md); color: var(--accent-danger); font-size: 13px; }

/* ============================================ Book Info */
.btn-book-info { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-tertiary); color: var(--text-secondary); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-book-info:hover { background: var(--accent-primary); color: #ffffff; border-color: var(--accent-primary); }

.book-info-intro { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }
.book-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.book-info-field { display: flex; flex-direction: column; gap: 6px; }
.book-info-field-full { grid-column: 1 / -1; }
.book-info-field-header { display: flex; align-items: center; justify-content: space-between; }
.book-info-field-header label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.btn-copy-field { padding: 3px 9px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-muted); font-family: var(--font); font-size: 11px; cursor: pointer; transition: all var(--transition); }
.btn-copy-field:hover { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }

.book-info-ai-section { display: flex; align-items: center; gap: 14px; padding: 16px; background: linear-gradient(135deg, rgba(15,52,96,0.05), rgba(233,69,96,0.05)); border: 1px solid var(--border-color); border-radius: var(--radius-md); margin-bottom: 20px; }
.btn-generate-meta { display: flex; align-items: center; gap: 8px; padding: 10px 18px; background: linear-gradient(135deg, var(--accent-primary), #1a4a80); color: #ffffff; border: none; border-radius: var(--radius-md); font-family: var(--font); font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.btn-generate-meta:disabled { opacity: 0.5; cursor: not-allowed; }
.book-info-ai-hint { font-size: 12px; color: var(--text-muted); }

.book-tools-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.book-tool-card { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-primary); }
.book-tool-icon { font-size: 24px; flex-shrink: 0; }
.book-tool-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.book-tool-info strong { font-size: 13px; color: var(--text-primary); }
.book-tool-info span { font-size: 11px; color: var(--text-muted); }
.btn-tool { padding: 7px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); font-family: var(--font); font-size: 12px; font-weight: 600; color: var(--text-secondary); cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.btn-tool:hover { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }
.btn-tool:disabled { opacity: 0.5; }

.toc-result-section { border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 16px; margin-bottom: 16px; background: var(--bg-primary); }
.toc-textarea { font-family: var(--font); font-size: 13px; line-height: 1.8; direction: rtl; }

/* ============================================ Auto Build & Quick Book */
.btn-auto-build { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border: none; border-radius: var(--radius-md); background: linear-gradient(135deg, #2d7a4f, #3a9a60); color: #ffffff; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-auto-build:hover { opacity: 0.88; }
.btn-auto-build.running { background: linear-gradient(135deg, #c0392b, #e05040); animation: pulseBuild 1.5s ease-in-out infinite; }
@keyframes pulseBuild { 0%, 100% { box-shadow: 0 0 0 0 rgba(192,57,43,0.4); } 50% { box-shadow: 0 0 0 6px rgba(192,57,43,0); } }

.btn-quick-book { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-tertiary); color: var(--text-secondary); font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all var(--transition); }
.btn-quick-book:hover { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }

.auto-build-progress-bar { height: 3px; background: var(--border-color); flex-shrink: 0; overflow: hidden; }
.auto-build-progress-fill { height: 100%; background: linear-gradient(90deg, #2d7a4f, #3a9a60); width: 0%; transition: width 0.5s ease; }

.btn-resume-build { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 12px auto; padding: 10px 22px; background: linear-gradient(135deg, #2d7a4f, #3a9a60); color: #ffffff; border: none; border-radius: var(--radius-md); font-family: var(--font); font-size: 14px; font-weight: 700; cursor: pointer; animation: fadeIn 0.3s ease; transition: opacity 0.2s, transform 0.2s; box-shadow: 0 2px 8px rgba(45,122,79,0.3); }
.btn-resume-build:hover { opacity: 0.9; transform: scale(1.03); }

.quick-book-note { display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px; background: rgba(15,52,96,0.07); border-radius: var(--radius-md); font-size: 12px; color: var(--text-secondary); line-height: 1.6; margin-top: 4px; }

/* ============================================ Responsive */
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; right: 0; height: 100dvh; transform: translateX(0); transition: transform 0.25s ease; box-shadow: var(--shadow-lg); z-index: 200; }
  .sidebar:not(.open) { transform: translateX(100%); width: var(--sidebar-width); min-width: var(--sidebar-width); }
  .sidebar-open-btn { display: flex !important; }

  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-title { font-size: 14px; }
  .topbar-left .btn-mode span, .topbar-left .btn-quick-book span, .topbar-left .btn-auto-build span, .topbar-left .btn-book-info span, .topbar-left .btn-export span, .topbar-left .btn-export-pdf span { display: none; }
  .btn-mode, .btn-quick-book, .btn-auto-build, .btn-book-info, .btn-export, .btn-export-pdf { padding: 8px; min-width: 36px; justify-content: center; }

  .chat-messages { padding: 14px 10px; }
  .message { max-width: 94%; }
  .message.ai { max-width: 98%; }

  .input-area { padding: 10px 10px 14px; }
  .input-container { padding: 8px 8px 8px 12px; }
  .input-hint { display: none; }

  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal { max-width: 100%; max-height: 90dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-sm, .modal-wide { max-width: 100%; }

  .book-info-grid { grid-template-columns: 1fr; }
  .book-tools-row { grid-template-columns: 1fr; }
  .book-info-ai-section { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .sidebar { width: 100vw !important; min-width: unset !important; }
  .sidebar:not(.open) { width: 100vw !important; }
  .model-cards-grid { grid-template-columns: 1fr; }
  .topbar { height: 52px; padding: 0 8px; }
  .topbar-title { font-size: 13px; max-width: 120px; }
  .input-area { padding: 8px 8px 12px; }
  .input-container { padding: 6px 6px 6px 10px; gap: 6px; }
  .btn-send { width: 36px; height: 36px; }
  .message { max-width: 97%; }
  .message.ai { max-width: 100%; }
  .chat-messages { padding: 10px 8px; gap: 14px; }
  .modal-overlay { padding: 0; }
  .modal { max-height: 92dvh; border-radius: 18px 18px 0 0; }
  .modal-body { padding: 14px; }
}

/* Scrollbar global */
* { scrollbar-width: thin; scrollbar-color: var(--border-color) transparent; }
