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

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e2e5ea;
  --border-focus: #6366f1;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
  --transition: 150ms ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.save-status {
  font-size: 0.8rem;
  color: var(--success);
  font-weight: 500;
  transition: color var(--transition);
}

.save-status.unsaved {
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow);
}

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

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

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

/* Main */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 1px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Panels */
.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.panel-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.panel-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Search */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  transition: border-color var(--transition);
  min-width: 220px;
}

.search-box:focus-within {
  border-color: var(--border-focus);
}

.search-box svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  border: none;
  outline: none;
  font-size: 0.85rem;
  width: 100%;
  background: transparent;
  color: var(--text);
}

/* Messages Grid */
.messages-grid {
  display: grid;
  gap: 16px;
}

.message-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color var(--transition);
}

.message-card:focus-within {
  border-color: var(--border-focus);
}

.message-card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.message-card textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.6;
  color: var(--text);
  resize: vertical;
  min-height: 60px;
  transition: border-color var(--transition);
  background: var(--bg);
}

.message-card textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  background: var(--surface);
}

/* Entries */
.entries-list {
  display: grid;
  gap: 16px;
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.entry-card:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.entry-header:hover {
  background: #f0f1f5;
}

.entry-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.entry-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.entry-answer {
  font-weight: 600;
  font-size: 0.95rem;
}

.entry-media-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 4px;
}

.chevron {
  transition: transform var(--transition);
  color: var(--text-muted);
}

.entry-card.open .chevron {
  transform: rotate(180deg);
}

.entry-body {
  display: none;
  padding: 20px;
}

.entry-card.open .entry-body {
  display: block;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field.full-width {
  grid-column: 1 / -1;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--transition), background var(--transition);
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  background: var(--surface);
}

.field textarea {
  resize: vertical;
  min-height: 52px;
  line-height: 1.5;
}

.field-row {
  display: flex;
  gap: 16px;
}

.field-row .field {
  flex: 1;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: transform 300ms ease;
  z-index: 200;
  pointer-events: none;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* Dialog */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0;
  max-width: 400px;
  width: 90%;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.dialog-content {
  padding: 24px;
}

.dialog-content h3 {
  font-size: 1.05rem;
  margin-bottom: 8px;
}

.dialog-content p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 640px) {
  header {
    padding: 12px 16px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  main {
    padding: 16px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .panel-header {
    flex-direction: column;
  }

  .search-box {
    min-width: 0;
    width: 100%;
  }

  .field-row {
    flex-direction: column;
    gap: 16px;
  }
}
