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

:root {
  --bg: #f7f5f0;
  --white: #ffffff;
  --ink: #1a1c2e;
  --ink2: #2e3048;
  --blue: #1b3fa0;
  --blue-light: #e8edf9;
  --blue-mid: #c2ccf0;
  --sage: #4a7c6f;
  --sage-light: #e6f0ed;
  --amber: #b85c1a;
  --amber-light: #faeee4;
  --border: #e0ddd6;
  --border2: #ede9e2;
  --muted: #8c8a82;
  --shadow: 0 1px 3px rgba(26,28,46,0.06), 0 4px 16px rgba(26,28,46,0.04);
  --shadow-lg: 0 4px 24px rgba(26,28,46,0.1), 0 1px 4px rgba(26,28,46,0.06);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Figtree', sans-serif;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 420px 1fr;
  grid-template-rows: auto 1fr;
}

/* ══════════════════════════════════════════
   RESPONSIVE — MOBILE & TABLET
   ══════════════════════════════════════════ */

/* ── Mobile tab bar ── */
.mobile-tabs {
  display: none;
  grid-column: 1 / -1;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 40;
}
.mobile-tab {
  flex: 1;
  font-family: 'Figtree', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 11px 8px;
  text-align: center;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.mobile-tab.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Tablet (≤ 900px) ── */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }

  .topbar { grid-column: 1; padding: 0 20px; }
  .topbar-hint { display: none; }

  .sidebar {
    grid-column: 1;
    max-height: none;
    height: auto;
    position: relative;
    top: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 22px 20px 32px;
  }

  .output-area {
    grid-column: 1;
    height: auto;
    padding: 24px 20px 40px;
  }

  .result-topbar { flex-wrap: wrap; gap: 10px; }
}

/* ── Mobile (≤ 650px) ── */
@media (max-width: 650px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 1fr;
    height: 100dvh;
    overflow: hidden;
  }

  /* Topbar: compact */
  .topbar {
    height: 48px;
    padding: 0 14px;
  }
  .logo-name { font-size: 17px; }

  /* Mobile tabs: visible */
  .mobile-tabs {
    display: flex;
    top: 48px;
  }

  /* Sidebar: scrollable panel, hidden by default */
  .sidebar {
    padding: 18px 14px 28px;
    height: calc(100dvh - 48px - 40px); /* minus topbar + tabs */
    overflow-y: auto;
    position: static;
    border-bottom: none;
  }
  .sidebar.hidden { display: none; }

  /* Output area */
  .output-area {
    padding: 16px 12px 32px;
    height: calc(100dvh - 48px - 40px);
    overflow-y: auto;
  }
  .output-area.hidden { display: none; }

  /* Section spacing */
  .section { margin-bottom: 20px; }

  /* Prevent iOS zoom on inputs */
  input[type="text"],
  input[type="date"],
  textarea,
  select,
  .tag-input {
    font-size: 1rem;
    padding: 10px 12px;
  }
  select { padding-right: 34px; }
  textarea { min-height: 90px; font-size: 1rem; }

  /* Tags wrap: bigger */
  .tags-wrap { min-height: 46px; padding: 7px 9px; }
  .tag { font-size: 12px; padding: 4px 9px 4px 11px; }

  /* Row 2: single col on very narrow */
  .row-2 { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Generate button: bigger */
  .btn-generate { padding: 14px 20px; font-size: 15px; }

  /* Empty state: smaller */
  .empty-state { min-height: 280px; gap: 12px; }
  .empty-title { font-size: 18px; }
  .empty-desc { font-size: 12px; }

  /* Loading: smaller */
  .loading-state { min-height: 280px; }

  /* Result topbar: stack on mobile */
  .result-topbar {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 18px;
  }
  .result-actions { flex-wrap: wrap; gap: 6px; }
  .btn-action { font-size: 11px; padding: 6px 11px; }

  /* CR Document */
  .cr-header { padding: 20px 18px; }
  .cr-meeting-title { font-size: 1.3rem; margin-bottom: 14px; }
  .cr-meta { gap: 10px; }
  .cr-meta-item { font-size: 11px; }

  .cr-body { padding: 20px 16px; }
  .cr-section { margin-bottom: 20px; }
  .cr-section-title { font-size: 9px; margin-bottom: 10px; }

  .cr-list-item { font-size: 13px; padding: 9px 11px; }
  .cr-text { font-size: 13px; }

  /* Participant chips: smaller */
  .participant-chip { font-size: 12px; padding: 5px 10px; gap: 6px; }
  .participant-avatar { width: 20px; height: 20px; font-size: 9px; }

  /* Action badges: wrap */
  .action-owner, .action-deadline { display: inline-flex; margin: 3px 4px 0 0; }

  /* CR Footer */
  .cr-footer {
    padding: 14px 18px;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .cr-footer-note { font-size: 10px; }
}

/* ── Very small (≤ 380px) ── */
@media (max-width: 380px) {
  .topbar { padding: 0 10px; }
  .logo-name { font-size: 15px; }
  .sidebar { padding: 14px 10px 24px; }
  .output-area { padding: 12px 10px 28px; }
  .row-2 { grid-template-columns: 1fr; }
  .cr-body { padding: 16px 12px; }
  .cr-header { padding: 16px 14px; }
}

/* Print */
@media print {
  .topbar, .sidebar, .result-topbar, .mobile-tabs { display: none !important; }
  body { display: block; background: white; }
  .output-area { padding: 0; height: auto; overflow: visible; }
  .cr-doc { box-shadow: none; border: none; }
}

/* Topbar */
.topbar {
  grid-column: 1 / -1;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.logo-name {
  font-family: 'Instrument Serif', serif;
  font-size: 20px;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.logo-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 20px;
}

.topbar-right { display: flex; align-items: center; gap: 16px; }

.topbar-hint { font-size: 12px; color: var(--muted); }

/* Sidebar */
.sidebar {
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 28px 28px 40px;
  overflow-y: auto;
  height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
}

.section { margin-bottom: 28px; }

.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border2);
}

/* Inputs */
.field { margin-bottom: 13px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink2);
  margin-bottom: 5px;
}

input[type="text"],
input[type="date"],
input[type="time"],
textarea,
select {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  font-weight: 400;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(27,63,160,0.08);
  background: var(--white);
}

textarea { line-height: 1.6; min-height: 100px; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%238c8a82' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
  cursor: pointer;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Participants tag input */
.tags-wrap {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 42px;
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.tags-wrap:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(27,63,160,0.08);
  background: var(--white);
}

.tag {
  background: var(--blue-light);
  color: var(--blue);
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px 3px 10px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.tag-remove {
  cursor: pointer;
  opacity: 0.5;
  font-size: 14px;
  line-height: 1;
  transition: opacity 0.1s;
}

.tag-remove:hover { opacity: 1; }

.tag-input {
  border: none;
  background: transparent;
  outline: none;
  font-family: 'Figtree', sans-serif;
  font-size: 13px;
  color: var(--ink);
  min-width: 100px;
  flex: 1;
  padding: 3px 4px;
}

/* Generate button */
.btn-generate {
  width: 100%;
  padding: 13px 20px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: 'Figtree', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.btn-generate:hover { background: var(--blue); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-icon { font-size: 16px; }

/* Output area */
.output-area {
  padding: 36px 40px;
  overflow-y: auto;
  height: calc(100vh - 56px);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  gap: 16px;
  animation: fadeIn 0.4s ease both;
}

.empty-icon {
  width: 64px; height: 64px;
  background: var(--blue-light);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.empty-title {
  font-family: 'Instrument Serif', serif;
  font-size: 22px;
  color: var(--ink);
}

.empty-desc {
  font-size: 13px;
  color: var(--muted);
  max-width: 300px;
  line-height: 1.7;
}

/* Loading */
.loading-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: 20px;
}

.loading-state.visible { display: flex; }
.empty-state.hidden, .result-state.hidden { display: none; }

.loader-ring {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { font-size: 14px; color: var(--muted); }

.loading-steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.loading-step {
  font-size: 12px;
  color: var(--muted);
  opacity: 0;
  animation: stepIn 0.4s ease both;
}

@keyframes stepIn { to { opacity: 1; } }

/* Result */
.result-state {
  display: none;
  animation: fadeUp 0.5s ease both;
}

.result-state.visible { display: block; }

.result-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}

.result-title {
  font-family: 'Instrument Serif', serif;
  font-size: 15px;
  color: var(--ink);
}

.result-actions { display: flex; gap: 8px; }

.btn-action {
  padding: 7px 14px;
  border-radius: 7px;
  font-family: 'Figtree', sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1.5px solid var(--border);
  background: var(--white);
  color: var(--ink2);
}

.btn-action:hover { border-color: var(--blue); color: var(--blue); }
.btn-action.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-action.primary:hover { background: #1530a0; }

/* CR Document */
.cr-doc {
  background: var(--white);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.cr-header {
  background: var(--ink);
  color: #fff;
  padding: 28px 32px;
  position: relative;
  overflow: hidden;
}

.cr-header::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 160px; height: 160px;
  background: rgba(255,255,255,0.04);
  border-radius: 50%;
}

.cr-header::after {
  content: '';
  position: absolute;
  bottom: -20px; right: 60px;
  width: 80px; height: 80px;
  background: rgba(255,255,255,0.03);
  border-radius: 50%;
}

.cr-type {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  margin-bottom: 8px;
}

.cr-meeting-title {
  font-family: 'Instrument Serif', serif;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 400;
  color: #fff;
  margin-bottom: 20px;
  line-height: 1.2;
}

.cr-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.cr-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.55);
}

.cr-meta-icon { font-size: 13px; }

/* CR body */
.cr-body { padding: 32px; }

.cr-section {
  margin-bottom: 28px;
  animation: fadeUp 0.4s ease both;
}

.cr-section:last-child { margin-bottom: 0; }

.cr-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cr-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--blue-light);
}

.cr-text {
  font-size: 14px;
  color: var(--ink2);
  line-height: 1.75;
}

/* Decisions / Actions */
.cr-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cr-list-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--ink2);
  line-height: 1.6;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  border-left: 3px solid transparent;
}

.cr-list-item.decision { border-left-color: var(--blue); }
.cr-list-item.action   { border-left-color: var(--sage); background: var(--sage-light); }
.cr-list-item.point    { border-left-color: var(--border); }

.cr-bullet { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.action-owner {
  display: inline-flex;
  align-items: center;
  background: var(--sage);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}

.action-deadline {
  display: inline-flex;
  align-items: center;
  background: var(--amber-light);
  color: var(--amber);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Participants chips */
.participant-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.participant-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--blue-light);
  color: var(--blue);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

.participant-avatar {
  width: 22px; height: 22px;
  background: var(--blue);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* CR Footer */
.cr-footer {
  padding: 20px 32px;
  border-top: 1px solid var(--border2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
}

.cr-footer-note { font-size: 11px; color: var(--muted); font-style: italic; }
.cr-footer-badge { font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: 0.08em; }

/* Animations */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp  {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
