:root {
  --bg-cream: #f8edd1;
  --bg-gold: #efd085;
  --ink: #2c2118;
  --plum: #6a2a7a;
  --olive: #4f6f34;
  --card: #fff8e9;
  --line: #dcc8a0;
  --shadow: 0 18px 45px rgba(78, 49, 11, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Sora", sans-serif;
  color: var(--ink);
  background: linear-gradient(140deg, #f5e5be, #f2d38c 50%, #eed9a3);
  min-height: 100vh;
}

input,
select,
button,
textarea {
  font-family: inherit;
}

.app-bg {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 12% 12%, rgba(79, 111, 52, 0.14), transparent 38%),
    radial-gradient(circle at 85% 20%, rgba(106, 42, 122, 0.18), transparent 42%),
    radial-gradient(circle at 20% 80%, rgba(106, 42, 122, 0.09), transparent 35%);
  pointer-events: none;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 290px;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid rgba(106, 42, 122, 0.22);
  background: rgba(255, 248, 233, 0.72);
  backdrop-filter: blur(7px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.logo {
  width: 66px;
  height: 66px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid var(--line);
}

.brand h1 {
  font-family: "Cormorant Garamond", serif;
  margin: 0;
  font-size: 1.85rem;
  color: var(--plum);
}

.brand p {
  margin: 0;
  font-size: 0.85rem;
  color: #71502c;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-item {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff4de;
  color: #5a3d21;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.menu-item:hover {
  transform: translateX(2px);
  box-shadow: 0 8px 18px rgba(106, 42, 122, 0.08);
}

.menu-item.active {
  background: linear-gradient(90deg, var(--plum), #84439b);
  color: #fff;
  border-color: transparent;
}

.menu-item.accent {
  border-color: rgba(79, 111, 52, 0.35);
  background: linear-gradient(90deg, rgba(79, 111, 52, 0.14), rgba(239, 208, 133, 0.72));
}

.meta-box {
  margin-top: auto;
  background: #fff2d6;
  border: 1px dashed #be9f6f;
  border-radius: 12px;
  padding: 12px;
  font-size: 0.9rem;
  color: #6a4a27;
  line-height: 1.8;
}

.main {
  margin-left: 290px;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.search-wrap {
  flex: 1;
}

#globalSearch,
.filters input,
.filters select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff8eb;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.pill {
  background: #efe2c0;
  color: var(--plum);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
}

.filters {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1.5fr 1fr 0.8fr 1.2fr 1fr auto;
  gap: 10px;
  position: sticky;
  top: 0;
  background: rgba(245, 229, 190, 0.94);
  padding: 10px 0;
  z-index: 4;
}

.btn,
.btn.ghost,
button.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.btn {
  background: linear-gradient(90deg, var(--plum), #8f49a8);
  color: #fff;
}

.btn.ghost {
  background: #fff8eb;
  color: #5d3f22;
  border: 1px solid var(--line);
}

.view {
  display: none;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: block;
}

.cards {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: #6c4e2c;
}

.card .value {
  font-size: 1.45rem;
  color: var(--plum);
  font-weight: 700;
}

.panel {
  margin-top: 14px;
  background: rgba(255, 248, 233, 0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel-head h2 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  color: var(--plum);
  font-size: 1.8rem;
}

.panel-head p {
  margin: 3px 0 0;
  color: #6f5638;
  font-size: 0.9rem;
}

.hero-panel {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.table-wrap {
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf7;
}

.table-wrap.tall {
  max-height: 62vh;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 740px;
}

th,
td {
  border-bottom: 1px solid #efe2c7;
  padding: 10px;
  font-size: 0.88rem;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f6ead0;
  color: #5f4727;
}

tr:hover td {
  background: #fff7e6;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.74rem;
  padding: 3px 8px;
  border: 1px solid #c0a673;
  background: #fff4db;
}

.badge.ok {
  border-color: #7ca662;
  color: #365f1d;
  background: #edf8e6;
}

.badge.no {
  border-color: #d0b07b;
  color: #7a5b2a;
  background: #fff5de;
}

.subject-detail {
  margin-top: 10px;
  border: 1px dashed #d2b57e;
  border-radius: 12px;
  padding: 14px;
  background: #fff8e8;
}

.subject-title {
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--plum);
}

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

.row-actions button,
.row-actions a {
  border: 1px solid var(--line);
  background: #fff5de;
  color: #5b3d23;
  border-radius: 10px;
  padding: 6px 9px;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.8rem;
}

.tabs {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}

.tab {
  border: 1px solid var(--line);
  background: #fff4de;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
}

.tab.active {
  background: var(--olive);
  color: #fff;
  border-color: transparent;
}

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
}

.grid-list {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}

.mini-card {
  background: #fff8e9;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.mini-card h4 {
  margin: 0 0 8px;
  color: #593f23;
  font-size: 0.95rem;
}

.saved-columns {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.simple-list {
  margin: 8px 0 0;
  padding-left: 18px;
  min-height: 180px;
}

.status-line {
  margin-top: 12px;
  color: #6a4b2b;
  font-size: 0.92rem;
}

.material-upload-form,
.mcq-toolbar,
.chat-toolbar {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.material-upload-form select,
.material-upload-form input,
.mcq-toolbar select {
  min-width: 180px;
}

.quiz-box {
  margin-top: 10px;
  padding: 14px;
  border: 1px dashed #bfa06d;
  border-radius: 12px;
  background: #fff9ea;
}

.question {
  font-weight: 600;
  color: #56391f;
  margin-bottom: 10px;
}

.opts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.opts button {
  border: 1px solid var(--line);
  background: #fff5de;
  border-radius: 10px;
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
}

.opts button.correct {
  border-color: #7ca662;
  background: #edf8e6;
}

.opts button.wrong {
  border-color: #c58f6e;
  background: #fff0e7;
}

.thread-list {
  display: grid;
  gap: 8px;
  width: 100%;
}

.thread-item {
  border: 1px solid var(--line);
  background: #fff7e7;
  border-radius: 12px;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 3px;
}

.thread-item.active {
  background: linear-gradient(135deg, #fff0dc, #f2edd9);
  border-color: rgba(79, 111, 52, 0.45);
}

.thread-title {
  font-weight: 600;
  color: #583a21;
}

.thread-subtitle {
  font-size: 0.78rem;
  color: #7a5e3a;
}

.ai-layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 14px;
}

.ai-setup,
.ai-chat-panel {
  margin-top: 0;
}

.mode-group {
  margin: 14px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-pill {
  border: 1px solid var(--line);
  background: #fff4de;
  color: #5d3f22;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.mode-pill.active {
  background: linear-gradient(90deg, var(--olive), #7a944c);
  color: #fff;
  border-color: transparent;
}

.ai-subject-card {
  margin-top: 0;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.86rem;
  font-weight: 600;
  color: #6d4e2d;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  border: 1px solid rgba(106, 42, 122, 0.18);
  background: #fff7e8;
  color: #5a3d21;
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 0.8rem;
}

.composer {
  margin-top: 16px;
}

#aiPrompt {
  min-height: 150px;
}

.composer-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-messages {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 540px;
  max-height: 72vh;
  overflow: auto;
  padding-right: 4px;
}

.message {
  border-radius: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #fff8ea;
}

.message.user {
  align-self: flex-end;
  width: min(86%, 760px);
  background: linear-gradient(120deg, #fff0da, #fff7eb);
}

.message.assistant {
  align-self: stretch;
  background: linear-gradient(135deg, rgba(255, 249, 238, 0.98), rgba(245, 236, 212, 0.95));
}

.message.pending {
  opacity: 0.8;
}

.message-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.message-role {
  font-weight: 700;
  color: var(--plum);
}

.message-role.user-role {
  color: #73471d;
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.65;
  color: #3d2c1c;
}

.message-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.76rem;
  background: #f2e8ca;
  border: 1px solid rgba(106, 42, 122, 0.14);
  color: #5b4021;
}

.context-box {
  margin-top: 10px;
  border: 1px dashed rgba(79, 111, 52, 0.38);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fffdf7;
}

.context-box summary {
  cursor: pointer;
  font-weight: 600;
  color: #4d6e32;
}

.context-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

.context-list li {
  margin-bottom: 6px;
  line-height: 1.45;
}

.placeholder {
  text-align: center;
  color: #72522f;
  padding: 32px 18px;
  border: 1px dashed rgba(106, 42, 122, 0.2);
  border-radius: 16px;
  background: rgba(255, 248, 233, 0.72);
}

.mcq-progress {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: #6a4b2b;
  font-weight: 600;
}

.mcq-option.selected {
  box-shadow: inset 0 0 0 1px rgba(106, 42, 122, 0.16);
}

.mcq-feedback {
  margin-top: 12px;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
}

.mcq-feedback.good {
  background: #edf8e6;
  border: 1px solid #7ca662;
  color: #365f1d;
}

.mcq-feedback.bad {
  background: #fff0e7;
  border: 1px solid #c58f6e;
  color: #7d4528;
}

.mcq-explanation {
  margin-top: 10px;
  line-height: 1.55;
  color: #4a3422;
}

.mcq-summary {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff9ee;
}

.summary-score {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--plum);
}

.summary-percent {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--olive);
  margin-bottom: 8px;
}

.mcq-review-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1200px) {
  .filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ai-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .sidebar {
    position: static;
    width: auto;
    height: auto;
    border-right: none;
  }

  .main {
    margin-left: 0;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

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

@media (max-width: 720px) {
  .main {
    padding: 16px;
  }

  .top {
    flex-direction: column;
    align-items: stretch;
  }

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

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

  .hero-panel {
    flex-direction: column;
    align-items: start;
  }

  .message.user,
  .message.assistant {
    width: 100%;
  }

  .material-upload-form,
  .mcq-toolbar,
  .chat-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}
