/* ========================================
   Character Memo App - Styles
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&family=Inter:wght@400;600&display=swap');

:root {
  --bg-primary: #0f0f13;
  --bg-secondary: #1a1a24;
  --bg-tertiary: #24243a;
  --bg-input: #1e1e2e;
  --text-primary: #e4e4ef;
  --text-secondary: #9898b0;
  --text-muted: #5e5e7a;
  --border-color: #2e2e48;
  --accent: #7c6ff7;
  --accent-hover: #9389f7;
  --accent-dim: rgba(124, 111, 247, 0.12);
  --danger: #f76c6c;
  --danger-hover: #f99;
  --scrollbar-track: #1a1a24;
  --scrollbar-thumb: #2e2e48;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --radius: 10px;
  --transition: 0.2s ease;
  --sidebar-width: 280px;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: 'Noto Sans JP', 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

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

/* ========================================
   Sidebar
   ======================================== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
}

.sidebar.open {
  transform: translateX(0);
}

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

.sidebar-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.78rem;
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.thread-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.thread-item:hover {
  background: var(--bg-tertiary);
}

.thread-item.active {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
}

.thread-item.active .thread-item-name {
  color: var(--accent-hover);
  font-weight: 700;
}

.thread-item-icon {
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 0.5;
}

.thread-item-name {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--transition);
}

.thread-item-actions {
  display: none;
  gap: 2px;
  flex-shrink: 0;
}

.thread-item:hover .thread-item-actions {
  display: flex;
}

.thread-item-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 5px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}

.thread-item-actions button:hover {
  color: var(--text-primary);
  background: var(--border-color);
}

.thread-item-actions button.delete-thread:hover {
  color: var(--danger);
}

/* ========================================
   Header
   ======================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ========================================
   Buttons (shared)
   ======================================== */
.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  transition: background var(--transition), transform var(--transition);
}

.btn:active {
  transform: scale(0.96);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-icon {
  padding: 6px 10px;
  font-size: 1.1rem;
  line-height: 1;
}

/* ========================================
   Log Area (conversation display)
   ======================================== */
.log-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.log-entry {
  margin-bottom: 16px;
  position: relative;
}


.log-entry .char-name {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.log-entry .char-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

.log-entry .entry-actions {
  position: absolute;
  top: 0;
  right: 0;
  display: none;
  gap: 4px;
}

.log-entry:hover .entry-actions {
  display: flex;
}

.entry-actions button {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}

.entry-actions button:hover {
  color: var(--text-primary);
  background: var(--border-color);
}

.entry-actions button.delete-btn:hover {
  color: var(--danger);
}

/* -- inline edit -- */
.edit-textarea {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.7;
  resize: vertical;
  min-height: 60px;
}

.edit-textarea:focus {
  outline: none;
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* -- empty state -- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 8px;
  user-select: none;
}

.empty-state .icon {
  font-size: 2.5rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
}

/* ========================================
   Input Bar
   ======================================== */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.char-select {
  appearance: none;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 10px 32px 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  min-width: 120px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239898b0' viewBox='0 0 16 16'%3E%3Cpath d='M1.5 5.5l6.5 6.5 6.5-6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--transition);
}

.char-select:focus {
  outline: none;
  border-color: var(--accent);
}

.text-input {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  min-height: 42px;
  max-height: 140px;
  line-height: 1.5;
  transition: border-color var(--transition);
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.send-btn {
  padding: 10px 20px;
  flex-shrink: 0;
}

/* ========================================
   Modal (Character Settings)
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background var(--transition);
}

.modal-close:hover {
  background: var(--bg-tertiary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* -- character list in modal -- */
.char-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.char-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  transition: background var(--transition);
}

.char-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.char-item-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
}

.char-item-actions {
  display: flex;
  gap: 4px;
}

.char-item-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition);
}

.char-item-actions button:hover {
  color: var(--text-primary);
}

.char-item-actions button.delete-char:hover {
  color: var(--danger);
}

/* -- add character form -- */
.add-char-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-char-form input[type="text"] {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition);
}

.add-char-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.add-char-form input[type="color"] {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
  padding: 0;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 600px) {
  .app-header {
    padding: 12px 16px;
  }

  .log-area {
    padding: 16px;
  }

  .input-bar {
    padding: 12px 16px;
    flex-wrap: wrap;
  }

  .char-select {
    min-width: 100px;
  }

  .text-input {
    min-width: 0;
  }

  .sidebar {
    width: 85%;
  }
}