/* Email Manager — component styles */

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background-color: #FAFAFA; color: #18181B; display: flex; overflow: hidden; height: 100dvh; touch-action: manipulation; }

/* ===== Left: Email List Frame ===== */
.email-frame { width: 50%; min-width: 380px; background: #fff; border-right: 1px solid #E4E4E7; display: flex; flex-direction: column; }
.email-frame-header { padding: 1rem 1.25rem; border-bottom: 1px solid #E4E4E7; flex-shrink: 0; }
.email-frame-header h2 { font-size: 1.15rem; margin-bottom: 0.75rem; }

.email-cards { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.email-card { flex: 1; background-color: #F6F6F7; border: 1px solid #E4E4E7; border-radius: 6px; padding: 0.5rem 0.75rem; text-align: center; }
.email-card-label { font-size: 0.72rem; color: #71717A; text-transform: uppercase; font-weight: 600; margin-bottom: 0.15rem; }
.email-card-value { font-size: 1.1rem; font-weight: 700; }

.index-row { display: flex; gap: 0.5rem; align-items: center; }
.index-row button { white-space: nowrap; }
.status-msg { flex: 1; font-size: 0.82rem; padding: 0.35rem 0.6rem; border-radius: 5px; display: none; min-width: 0; }
.status-msg.show { display: block; }
.status-ok { background: #d4edda; color: #155724; }
.status-loading { background: #fff3cd; color: #856404; }
.status-error { background: #f8d7da; color: #842029; }

.email-table-area { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
table.email-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.email-table th, table.email-table td { border-bottom: 1px solid #EEF0FF; padding: 0.5rem 0.65rem; text-align: left; }
table.email-table th { background-color: #F6F6F7; color: #71717A; font-weight: 700; font-size: 0.75rem; text-transform: uppercase; position: sticky; top: 0; z-index: 1; }
table.email-table tr:hover { background-color: #FAFAFA; }
table.email-table .col-num { width: 32px; text-align: center; }
table.email-table .col-from { width: 140px; }
table.email-table .col-date { width: 150px; }
table.email-table .col-action { width: 48px; text-align: center; }

.subject-link { color: #5B5BD6; cursor: pointer; text-decoration: none; }
.subject-link:hover { text-decoration: underline; }
.subject-cell { max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.from-cell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date-cell { font-size: 0.78rem; color: #71717A; white-space: nowrap; }
.empty-msg { text-align: center; color: #8899aa; padding: 2rem; font-size: 0.9rem; }

button { background-color: #5B5BD6; color: #fff; border: none; border-radius: 6px; padding: 0.5rem 1rem; cursor: pointer; font-weight: 600; font-size: 0.88rem; min-height: 40px; }
button:hover { background: #4a4ac0; }
button:disabled { background: #9b9be0; cursor: not-allowed; }
.btn-green { background-color: #30A46C; }
.btn-green:hover { background: #278a5b; }
.btn-green:disabled { background: #71b893; }
.btn-sm { min-height: 0; padding: 0.2rem 0.5rem; font-size: 0.72rem; border-radius: 4px; }
.btn-sm-delete { background-color: #E5484D; display: none; }
.btn-sm-delete:hover { background: #cc3338; }
.btn-sm-delete.revealed { display: inline-block; }
table.email-table tr.delete-target { background: #fff5f5; }
table.email-table tr.delete-target:hover { background: #fee2e2; }

/* ===== Right: Chat Frame ===== */
.chat-frame { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.frame-toggle { display: none; background: none; border: none; color: #18181B; font-size: 1.5rem; width: 44px; min-height: 44px; padding: 0; cursor: pointer; flex-shrink: 0; }
.frame-toggle:hover { background: none; color: #5B5BD6; }
.frame-overlay { display: none; }

.chat-messages { flex: 1; overflow-y: scroll; -webkit-overflow-scrolling: touch; padding: 1rem 1.5rem; }
.message { max-width: 800px; margin: 0 auto 1rem auto; display: flex; gap: 0.75rem; }
.message-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; flex-shrink: 0; }
.message-user .message-avatar { background-color: #5B5BD6; color: #fff; }
.message-assistant .message-avatar { background: #6c757d; color: #fff; }
.message-body { flex: 1; min-width: 0; }
.message-role { font-size: 0.75rem; font-weight: 700; color: #71717A; margin-bottom: 0.25rem; text-transform: uppercase; }
.message-content { font-size: 0.95rem; line-height: 1.6; }
.message-content p { margin-bottom: 0.5rem; }
.message-content pre { background-color: #F6F6F7; padding: 0.75rem; border-radius: 6px; overflow-x: auto; font-size: 0.85rem; }
.message-content code { background: #EEF0FF; padding: 0.1rem 0.3rem; border-radius: 4px; font-size: 0.85rem; }
.message-content pre code { background: none; padding: 0; }
.message-content .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.message-content table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; font-size: 0.85rem; }
.message-content th, .message-content td { border: 1px solid #E4E4E7; padding: 0.4rem 0.6rem; text-align: left; }
.message-content th { background-color: #F6F6F7; font-weight: 700; }
.message-content tr:hover { background-color: #FAFAFA; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid #E4E4E7; border-top-color: #5B5BD6; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; margin-right: 0.5rem; }

/* Action panel for pending SQL */
.action-panel { max-width: 800px; margin: 0.75rem auto; background: #fffbeb; border: 1px solid #f59e0b; border-radius: 8px; padding: 1rem; }
.action-panel-header { font-size: 0.82rem; font-weight: 700; color: #92400e; margin-bottom: 0.5rem; text-transform: uppercase; }
.action-panel textarea { width: 100%; min-height: 80px; font-family: monospace; font-size: 0.85rem; padding: 0.6rem; border: 1px solid #E4E4E7; border-radius: 6px; resize: vertical; background: #fff; }
.action-panel-buttons { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.action-panel-buttons button { min-height: 38px; padding: 0.45rem 1.2rem; font-size: 0.85rem; }
.btn-execute { background: #dc2626; }
.btn-execute:hover { background: #b91c1c; }
.btn-cancel-action { background: #6b7280; }
.btn-cancel-action:hover { background: #4b5563; }
.action-panel-result { margin-top: 0.5rem; font-size: 0.85rem; padding: 0.4rem 0.6rem; border-radius: 5px; display: none; }
.action-panel-result.show { display: block; }
.action-result-ok { background: #d4edda; color: #155724; }
.action-result-error { background: #f8d7da; color: #842029; }

.sample-questions { max-width: 800px; margin: 0 auto; display: flex; gap: 0.5rem; flex-wrap: wrap; padding: 0.5rem 0; }
.sample-btn { background: #EEF0FF; color: #5B5BD6; border: 1px solid #E4E4E7; border-radius: 20px; padding: 0.4rem 0.8rem; font-size: 0.82rem; cursor: pointer; font-weight: 500; min-height: 0; }
.sample-btn:hover { background-color: #E4E4E7; }

.chat-input-area { padding: 0.75rem 1.5rem; border-top: 1px solid #E4E4E7; background: #fff; flex-shrink: 0; }
.chat-input-wrapper { max-width: 800px; margin: 0 auto; display: flex; gap: 0.5rem; }
.chat-input-wrapper input { flex: 1; padding: 0.6rem 0.8rem; border: 1px solid #E4E4E7; border-radius: 6px; font-size: 16px; outline: none; }
.chat-input-wrapper input:focus { border-color: #5B5BD6; }
.chat-input-wrapper button { min-height: 40px; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 2000; justify-content: center; align-items: center; padding: 1rem; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 720px; max-height: 85dvh; display: flex; flex-direction: column; box-shadow: 0 8px 30px rgba(0,0,0,0.2); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid #E4E4E7; gap: 0.75rem; }
.modal-header h2 { font-size: 1.05rem; flex: 1; min-width: 0; word-break: break-word; }
.modal-close { background: none; border: none; font-size: 1.5rem; color: #71717A; cursor: pointer; min-height: 0; padding: 0; line-height: 1; width: auto; flex-shrink: 0; }
.modal-close:hover { color: #18181B; background: none; }
.modal-meta { padding: 0.5rem 1.25rem; font-size: 0.82rem; color: #71717A; border-bottom: 1px solid #EEF0FF; }
.modal-meta span { margin-right: 1.5rem; }
.modal-body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; font-size: 0.92rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.modal-attachments { padding: 0.75rem 1.25rem; border-top: 1px solid #E4E4E7; font-size: 0.85rem; }
.modal-attachments h3 { font-size: 0.82rem; color: #71717A; text-transform: uppercase; margin-bottom: 0.4rem; }
.attach-item { display: inline-flex; align-items: center; gap: 0.4rem; background: #EEF0FF; padding: 0.3rem 0.6rem; border-radius: 4px; margin: 0.2rem 0.3rem 0.2rem 0; text-decoration: none; color: #5B5BD6; font-weight: 600; }
.attach-item:hover { background-color: #E4E4E7; }
.attach-size { color: #8899aa; font-weight: 400; font-size: 0.78rem; }

/* Modal tabs */
.modal-tabs { display: flex !important; border-bottom: 2px solid #E4E4E7; padding: 0 1.25rem; gap: 4px; }
.modal-tab { background: #F6F6F7 !important; border: 1px solid #E4E4E7 !important; border-bottom: none !important; border-radius: 6px 6px 0 0 !important; padding: 0.45rem 1rem !important; font-size: 0.82rem !important; font-weight: 600; color: #71717A !important; cursor: pointer; width: auto !important; flex-shrink: 0; margin-bottom: -2px; transition: background 150ms, color 150ms; }
.modal-tab.active { background: #fff !important; color: #5B5BD6 !important; border-color: #E4E4E7 !important; border-bottom: 2px solid #fff !important; }
.modal-tab:hover:not(.active) { background: #EEEEFF !important; color: #3F3F46 !important; }
.modal-tab-pane { overflow: hidden; }
.translate-bar { display: flex !important; flex-direction: row !important; align-items: center !important; gap: 8px; padding: 0.5rem 1.25rem; border-bottom: 1px solid #F4F4F5; background: #FAFAFA; }
.translate-select { font-size: 0.82rem; padding: 5px 10px; border: 1px solid #D4D4D8; border-radius: 5px; width: auto !important; flex-shrink: 0; background: #fff; }
.translate-btn { font-size: 0.78rem !important; font-weight: 600; padding: 5px 16px !important; background: #5B5BD6 !important; color: #fff !important; border: none !important; border-radius: 5px !important; cursor: pointer; width: auto !important; flex-shrink: 0; transition: background 150ms; }
.translate-btn:hover { background: #4B4BC0 !important; }
.translate-btn:disabled { background: #A1A1AA !important; cursor: not-allowed; }
.translate-status { font-size: 0.72rem; color: #30A46C; font-style: italic; }

@media (max-width: 767px) {
  body { flex-direction: column; }
  .chat-frame { order: 1; flex: 1; }
  .email-frame { order: 2; }
  .frame-toggle { display: flex; align-items: center; justify-content: center; }
  .email-frame {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; min-width: 0; max-height: 85dvh;
    border-right: none; border-top: 1px solid #E4E4E7;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15); z-index: 1000;
    transform: translateY(100%); transition: transform 0.3s ease;
  }
  .email-frame.open { transform: translateY(0); }
  .email-frame-header { padding: 0.75rem 1rem; }
  .email-frame-header h2 { font-size: 1rem; margin-bottom: 0.5rem; }
  .frame-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 999; }
  .frame-overlay.active { display: block; }
  table.email-table { font-size: 0.78rem; }
  table.email-table th, table.email-table td { padding: 0.35rem 0.5rem; }
  table.email-table .col-date { display: none; }
  .date-cell { display: none; }
  .nav-menu { right: auto; left: 0; }
  .chat-messages { padding: 0.75rem 1rem; }
  .message { gap: 0.5rem; }
  .message-avatar { width: 28px; height: 28px; font-size: 0.75rem; }
  .chat-input-area { padding: 0.5rem 0.75rem; padding-bottom: calc(0.5rem + env(safe-area-inset-bottom)); }
  .sample-questions { padding: 0.5rem 1rem; }
  .modal { max-height: 90dvh; }
  .modal-header h2 { font-size: 0.95rem; }
}
