:root {
  --bg: #eef0f3;
  --card-bg: #ffffff;
  --section-bg: #f4f5f7;
  --border: #e2e5ea;
  --text: #1f2937;
  --text-strong: #111827;
  --muted: #6b7280;
  --primary: #1f6cf2;
  --primary-hover: #155bd6;
  --gradient-btn: linear-gradient(90deg, #1f66e0 0%, #6cc9ec 100%);
  --gradient-btn-hover: linear-gradient(90deg, #1656c4 0%, #58bce4 100%);
  --credit-bg: #f59e0b;
  --ghost-text: #1f2937;
  --notice-bg: #eef4ff;
  --notice-border: #cdddff;
  --success: #047857;
  --success-bg: #d1fae5;
  --error: #b91c1c;
  --error-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Sukhumvit Set",
               "Sarabun", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

.page-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 24px 28px 32px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

/* === Back button === */

.back-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-strong);
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.back-btn:hover { background: #f8f9fb; }
.back-arrow { font-size: 16px; }

/* === Header === */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-strong);
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.ghost-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--ghost-text);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ghost-btn:hover:not(:disabled) { background: #f5f7fa; }
.ghost-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.action-btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, filter 0.15s ease;
  background: var(--gradient-btn);
}

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

.record-btn.recording { background: var(--error); }
.record-btn.recording:hover { background: #991b1b; filter: none; }

.credit-badge {
  background: var(--credit-bg);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 10px;
  min-width: 28px;
  text-align: center;
}

.icon { font-size: 14px; }

/* === Settings row === */

.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.settings-label {
  font-size: 14px;
  color: var(--text-strong);
}

.info-dot {
  color: var(--muted);
  font-size: 13px;
}

.setting-chip {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-strong);
}

.setting-chip:hover { background: #f5f7fa; }
.gear-icon { color: var(--primary); }

.credit-info {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
}

.credit-info strong {
  color: var(--text-strong);
  font-weight: 600;
}

/* === Notice banner === */

.notice-banner {
  margin-top: 16px;
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-strong);
  display: flex;
  gap: 10px;
  align-items: center;
}

.notice-icon {
  color: var(--primary);
  font-size: 16px;
}

/* === Accordion sections === */

.accordion {
  margin-top: 14px;
  background: var(--section-bg);
  border-radius: 8px;
  border: 1px solid transparent;
  overflow: hidden;
}

.accordion summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-strong);
  user-select: none;
}

.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::marker { content: ""; }

.acc-toggle {
  width: 18px;
  height: 18px;
  position: relative;
  flex-shrink: 0;
}

.acc-toggle::before,
.acc-toggle::after {
  content: "";
  position: absolute;
  background: var(--text-strong);
  left: 50%;
  top: 50%;
}

.acc-toggle::before {
  width: 14px;
  height: 2px;
  transform: translate(-50%, -50%);
}

.acc-toggle::after {
  width: 2px;
  height: 14px;
  transform: translate(-50%, -50%);
  transition: opacity 0.15s ease;
}

.accordion[open] .acc-toggle::after {
  opacity: 0;
}

.acc-body {
  padding: 0 18px 18px;
}

.acc-body textarea,
.acc-body input[type="date"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

/* Leave room at the bottom of the textarea so the floating copy button
   doesn't overlap typed content. */
.acc-body .textarea-wrap textarea {
  padding-bottom: 56px;
}

.acc-body textarea {
  resize: none;            /* height is managed by autoResize() in app.js */
  overflow: hidden;        /* no scrollbar — textarea grows with content */
  min-height: 60px;
}

/* === Generating watermark (appears inside textarea during AI call) === */

.textarea-wrap {
  position: relative;
}

.loading-overlay {
  position: absolute;
  top: 12px;
  left: 14px;
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  animation: generating-pulse 1.6s ease-in-out infinite;
}

.loading-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  /* fill="currentColor" on the SVG paths inherits the pulsing blue
     defined by @keyframes generating-pulse on the parent. */
}

.processing .loading-overlay { display: inline-flex; }

/* Keep the textarea looking like a normal input box; just hide its text
   and placeholder so the overlay reads cleanly on top. */
.processing .textarea-wrap textarea {
  color: transparent;
  caret-color: transparent;
}

.processing .textarea-wrap textarea::placeholder {
  color: transparent;
}

@keyframes generating-pulse {
  0%, 100% { color: #6c8fea; opacity: 0.85; }
  50%      { color: #1f6cf2; opacity: 1;    }
}

/* === Floating "Copy all message" FAB (bottom-right of viewport) === */

.primary-btn.fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 40;
  padding: 14px 26px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #1f2937;       /* black */
  border-radius: 12px;
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.28),
    0 4px 8px rgba(0, 0, 0, 0.14);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.primary-btn.fab:hover:not(:disabled) {
  background: #111827;
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.34),
    0 6px 12px rgba(0, 0, 0, 0.18);
  transform: translateY(-1px);
}

/* === Per-box copy button — anchored inside the textarea, bottom-left === */

.copy-row {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: inline-block;
  z-index: 2;
}

.copy-row[hidden] { display: none; }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-strong);
  cursor: pointer;
  transition: background 0.15s ease;
}

.copy-btn:hover { background: #f5f7fa; }

.copy-btn .copy-icon { color: var(--text-strong); }

.copy-toast {
  position: absolute;
  left: 16px;
  bottom: calc(100% + 6px);
  padding: 6px 14px;
  background: #1f2937;
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.copy-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* === Copy-all preview — floating right-side card, NOT a full overlay === */

#copy-modal {
  /* Override the .modal-overlay full-screen behavior. Anchor the panel
     to the bottom-right corner, directly in front of the FAB. */
  background: transparent;
  backdrop-filter: none;
  inset: auto;
  bottom: 28px;
  right: 28px;
  display: block;
  padding: 0;
  z-index: 60;        /* above the FAB (z-index: 40) */
  width: 440px;
  max-width: calc(100vw - 56px);

  /* Hidden by default; slides in horizontally from the right when .open is added. */
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 28px));
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1),
              opacity 0.18s ease;
}

#copy-modal.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.copy-modal {
  position: relative;
  width: 100%;
  padding: 32px 28px 28px;
  text-align: left;
  box-shadow:
    0 24px 60px rgba(15, 23, 42, 0.25),
    0 6px 12px rgba(15, 23, 42, 0.08);
}

.copy-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.copy-success-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.copy-modal-title {
  margin: 0 0 24px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-strong);
  text-align: center;
}

.copy-modal-subtitle {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
}

.copy-modal-preview {
  background: var(--section-bg);
  border-radius: 10px;
  padding: 16px 18px;
  max-height: 360px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text);
}

/* === Hidden study-date label kept compact === */

.hidden-meta {
  margin-top: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.hidden-meta label {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.hidden-meta input[type="date"] {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

/* === Primary action === */

.primary-btn {
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.primary-btn:hover:not(:disabled) { background: var(--primary-hover); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form-actions {
  margin-top: 22px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* === Status bar === */

.status-bar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  min-width: 240px;
  max-width: 90vw;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  background: var(--info-bg);
  color: var(--info);
  text-align: center;
}

.status-bar.visible { opacity: 1; }
.status-bar.info    { background: var(--info-bg);    color: var(--info); }
.status-bar.success { background: var(--success-bg); color: var(--success); }
.status-bar.error   { background: var(--error-bg);   color: var(--error); }

/* === Recording modal === */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 22px 28px 24px;
  width: 560px;
  max-width: 100%;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-strong);
}

.modal-close {
  background: transparent;
  border: 0;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover { background: #f5f7fa; color: var(--text-strong); }

.recorder-waveform-wrap {
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 4px;
}

.waveform-canvas {
  width: 100%;
  height: 60px;
  display: block;
}

.recorder-timeline {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin: 4px 0 22px;
  font-variant-numeric: tabular-nums;
}

.recorder-timeline .time-left  { text-align: left;  color: var(--muted); font-size: 14px; }
.recorder-timeline .time-right { text-align: right; color: var(--muted); font-size: 14px; }
.recorder-timeline .time-current {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-strong);
  padding: 0 16px;
}

.recorder-controls {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-bottom: 18px;
}

.rec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-strong);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.rec-btn:hover:not(:disabled) { background: #f5f7fa; }
.rec-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.rec-stop {
  background: #f15a4a;
  color: #fff;
  border-color: #f15a4a;
  min-width: 160px;
}

.rec-stop:hover:not(:disabled) {
  background: #de4839;
  border-color: #de4839;
}

.rec-pause { min-width: 160px; }

.rec-icon { font-size: 14px; line-height: 1; }

.recorder-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.rec-submit {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.rec-submit:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

@media (max-width: 640px) {
  .page-header { flex-direction: column; align-items: stretch; }
  .header-actions { justify-content: flex-start; }
  .credit-info { margin-left: 0; }
  .modal-card { padding: 18px 18px 20px; }
  .recorder-timeline .time-current { font-size: 24px; }
  .rec-stop, .rec-pause { min-width: 120px; }
}

/* === Logged-in user chip === */

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  align-self: center;
}

/* === Login page === */

.login-container {
  max-width: 420px;
  padding-top: 64px;
}

.login-card {
  padding: 32px 28px;
}

.login-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-strong);
  text-align: center;
}

.login-subtitle {
  margin: 0 0 20px;
  color: var(--muted);
  text-align: center;
}

.login-form {
  display: flex;
  flex-direction: column;
}

.login-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.login-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  margin-bottom: 16px;
  font-family: inherit;
}

.login-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 108, 242, 0.12);
}

.login-btn {
  margin-top: 4px;
  width: 100%;
  padding: 11px 18px;
}

.login-hint {
  margin: -6px 0 14px;
  font-size: 12px;
  color: var(--muted);
}

.form-error {
  margin: 0 0 14px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  background: var(--error-bg);
  color: var(--error);
}
