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

:root {
  --sage: #8B9E7E;
  --sage-light: #E8EDE4;
  --sage-wash: #F4F7F2;
  --charcoal: #2C2C2C;
  --warm-gray: #6B6B6B;
  --cream: #FAFAF7;
  --soft-amber: #C4A97D;
  --amber-light: #F5EFE5;
  --deep-green: #3D5A3A;
  --red: #D4644A;
  --red-light: #FEF2F0;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  color: var(--charcoal);
  background: var(--cream);
  line-height: 1.6;
}

/* ─── NAV ─── */
#app-nav {
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 100;
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid #eeeee8;
  padding: 16px 0;
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
  color: var(--deep-green);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-links a {
  font-size: 13px;
  font-weight: 600;
  color: var(--warm-gray);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  transition: all 0.15s;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--deep-green);
  background: var(--sage-light);
}

.nav-links .nav-user {
  font-size: 12px;
  color: var(--sage);
  font-weight: 500;
  margin-right: 8px;
}

/* ─── MAIN ─── */
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 90px 32px 60px;
  min-height: 100vh;
}

/* ─── PAGE HEADER ─── */
.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 32px;
  letter-spacing: -0.5px;
  color: var(--charcoal);
  margin-bottom: 6px;
}

.page-header p {
  font-size: 15px;
  color: var(--warm-gray);
}

/* ─── CARDS ─── */
.card {
  background: white;
  border-radius: 14px;
  padding: 28px;
  border: 1px solid #eeeee8;
  margin-bottom: 16px;
}

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

.card-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--sage);
}

/* ─── STAT CARDS ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: white;
  border-radius: 14px;
  padding: 24px;
  border: 1px solid #eeeee8;
  text-align: center;
}

.stat-number {
  font-family: 'DM Serif Display', serif;
  font-size: 36px;
  color: var(--deep-green);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-number.amber { color: var(--soft-amber); }
.stat-number.red { color: var(--red); }

.stat-label {
  font-size: 13px;
  color: var(--warm-gray);
  font-weight: 500;
}

/* ─── FORMS ─── */
.auth-container {
  max-width: 460px;
  margin: 60px auto;
}

.auth-container h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 36px;
  text-align: center;
  margin-bottom: 8px;
}

.auth-container .subtitle {
  text-align: center;
  color: var(--warm-gray);
  font-size: 15px;
  margin-bottom: 36px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--charcoal);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e0e0d8;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  background: white;
  color: var(--charcoal);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(139,158,126,0.12);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

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

.form-section {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--sage);
  margin: 28px 0 16px;
  padding-top: 20px;
  border-top: 1px solid #eeeee8;
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-block;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  text-align: center;
}

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

.btn-primary:hover {
  background: #2d4a2a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(61,90,58,0.25);
}

.btn-secondary {
  background: var(--sage-light);
  color: var(--deep-green);
}

.btn-secondary:hover {
  background: #dce5d7;
}

.btn-outline {
  background: white;
  color: var(--deep-green);
  border: 1.5px solid var(--sage-light);
}

.btn-outline:hover {
  background: var(--sage-light);
}

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

.btn-danger:hover {
  background: #fde4e0;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ─── TABLE ─── */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--warm-gray);
  border-bottom: 2px solid #eeeee8;
}

td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid #f5f5f0;
  vertical-align: middle;
}

tr:hover td {
  background: var(--sage-wash);
}

/* ─── BADGES ─── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}

.badge-upcoming { background: #E8F0FE; color: #3B6BD5; }
.badge-in-progress { background: var(--amber-light); color: #8B6F3A; }
.badge-completed { background: var(--sage-light); color: var(--deep-green); }
.badge-overdue { background: var(--red-light); color: var(--red); }
.badge-high { background: var(--red-light); color: var(--red); }
.badge-medium { background: var(--amber-light); color: #8B6F3A; }
.badge-low { background: var(--sage-light); color: var(--sage); }

.badge-understood { background: var(--sage-light); color: var(--deep-green); }
.badge-partial { background: var(--amber-light); color: #8B6F3A; }
.badge-not-understood { background: var(--red-light); color: var(--red); }

.badge-none { background: var(--sage-light); color: var(--deep-green); }
.badge-light { background: #E8F0FE; color: #3B6BD5; }
.badge-moderate { background: var(--amber-light); color: #8B6F3A; }
.badge-heavy { background: var(--red-light); color: var(--red); }

/* ─── ALERTS ─── */
.alert {
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 20px;
}

.alert-error {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #f0d0c8;
}

.alert-success {
  background: var(--sage-light);
  color: var(--deep-green);
  border: 1px solid #c8d8c0;
}

.alert-info {
  background: #E8F0FE;
  color: #3B6BD5;
  border: 1px solid #c0d0f0;
}

/* ─── EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--warm-gray);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--charcoal);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 24px;
}

/* ─── FILTERS ─── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar select {
  padding: 8px 14px;
  border: 1.5px solid #e0e0d8;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: white;
  color: var(--charcoal);
}

/* ─── RECEIPT CARD ─── */
.receipt {
  background: white;
  border-radius: 14px;
  padding: 28px;
  border: 1px solid #eeeee8;
  margin-bottom: 14px;
}

.receipt-row-app {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 14px;
  border-bottom: 1px solid #f5f5f0;
}

.receipt-row-app:last-child { border-bottom: none; }
.receipt-row-app .key { color: var(--warm-gray); font-weight: 500; }
.receipt-row-app .value { font-weight: 600; }

/* ─── DIGEST CARD ─── */
.digest-card {
  background: var(--charcoal);
  color: white;
  border-radius: 14px;
  padding: 28px;
  margin-bottom: 14px;
}

.digest-card .digest-date {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--sage);
  margin-bottom: 20px;
}

.digest-card .digest-item {
  display: flex;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  align-items: flex-start;
}

.digest-card .digest-item:last-child { border-bottom: none; }

.digest-card .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.digest-card .dot-red { background: #E88B7A; }
.digest-card .dot-amber { background: var(--soft-amber); }
.digest-card .dot-green { background: var(--sage); }

.digest-card .item-text {
  font-size: 14px;
  color: #c0c0c0;
}

.digest-card .item-text strong {
  color: white;
  font-weight: 600;
}

.digest-card .suggestion {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 14px;
  color: var(--sage);
  font-weight: 500;
}

/* ─── SETTINGS ─── */
.setting-group {
  padding: 20px 0;
  border-bottom: 1px solid #f5f5f0;
}

.setting-group:last-child { border-bottom: none; }

.setting-group h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.setting-group p {
  font-size: 13px;
  color: var(--warm-gray);
  margin-bottom: 14px;
}

.radio-group {
  display: flex;
  gap: 12px;
}

.radio-option {
  flex: 1;
  padding: 16px;
  border: 2px solid #e0e0d8;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.radio-option:hover { border-color: var(--sage); }
.radio-option.selected {
  border-color: var(--deep-green);
  background: var(--sage-wash);
}

.radio-option .radio-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.radio-option .radio-desc {
  font-size: 12px;
  color: var(--warm-gray);
}

/* ─── AUTH LINKS ─── */
.auth-link {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--warm-gray);
}

.auth-link a {
  color: var(--deep-green);
  font-weight: 600;
  text-decoration: none;
}

.auth-link a:hover {
  text-decoration: underline;
}

/* ─── LOADING ─── */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--warm-gray);
  font-size: 15px;
}

/* ─── TWO-COL LAYOUT ─── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ─── STATS GRID 5-col ─── */
.stats-grid { grid-template-columns: repeat(5, 1fr); }

/* ─── FILE UPLOAD ─── */
.upload-area {
  border: 2px dashed #d8d8d0;
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--sage-wash);
}

.upload-area:hover, .upload-area.drag-over {
  border-color: var(--sage);
  background: var(--sage-light);
}

.upload-area .upload-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.upload-area .upload-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--charcoal);
  margin-bottom: 4px;
}

.upload-area .upload-hint {
  font-size: 12px;
  color: var(--warm-gray);
}

.upload-previews {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.upload-preview {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e0e0d8;
}

.upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-filename {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 4px;
  background: rgba(0,0,0,0.5);
  color: white;
  font-size: 9px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* ─── WORKSPACE ─── */
.workspace-container {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 150px);
}

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

.ws-header h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 24px;
  letter-spacing: -0.5px;
}

.ws-meta {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--warm-gray);
  margin-top: 4px;
}

.ws-meta span {
  padding: 2px 10px;
  background: var(--sage-light);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--deep-green);
}

.ws-description {
  background: var(--sage-wash);
  border: 1px solid var(--sage-light);
  border-radius: 10px;
  padding: 16px;
  font-size: 14px;
  color: var(--charcoal);
  margin-bottom: 16px;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.ws-images {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.ws-assignment-img {
  max-width: 180px;
  max-height: 140px;
  border-radius: 10px;
  border: 1px solid #e0e0d8;
  cursor: pointer;
  object-fit: cover;
  transition: transform 0.2s;
}

.ws-assignment-img:hover {
  transform: scale(1.05);
}

.workspace-chat {
  flex: 1;
  background: white;
  border: 1px solid #eeeee8;
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
  max-height: 400px;
  overflow-y: auto;
  min-height: 200px;
}

.ws-message {
  display: flex;
  gap: 12px;
  padding: 12px 0;
}

.ws-message + .ws-message {
  border-top: 1px solid #f5f5f0;
}

.ws-message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.ws-message-assistant .ws-message-avatar {
  background: var(--sage-light);
}

.ws-message-user .ws-message-avatar {
  background: #E8F0FE;
}

.ws-message-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--warm-gray);
  margin-bottom: 4px;
}

.ws-message-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--charcoal);
  white-space: pre-wrap;
}

.ws-typing {
  color: var(--warm-gray) !important;
  font-style: italic;
}

.workspace-status {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 13px;
  color: var(--warm-gray);
  font-weight: 600;
}

.workspace-compose {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.workspace-compose textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e0e0d8;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  background: white;
  color: var(--charcoal);
}

.workspace-compose textarea:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(139,158,126,0.12);
}

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

/* ─── WORKSPACE COMPLETION ─── */
.ws-completion-modal {
  background: white;
  border: 2px solid var(--sage);
  border-radius: 14px;
  padding: 28px;
  margin-top: 16px;
}

.ws-completion-modal h3 {
  font-size: 20px;
  margin-bottom: 12px;
}

.ws-completion-modal p {
  font-size: 14px;
  color: var(--warm-gray);
  margin-bottom: 16px;
}

.ws-receipt {
  margin-top: 16px;
}

.ws-receipt-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #eeeee8;
}

.ws-receipt-icon {
  font-size: 40px;
}

.ws-receipt-header h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.ws-receipt-header p {
  font-size: 13px;
  color: var(--warm-gray);
}

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  #app { padding: 80px 16px 40px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .radio-group { flex-direction: column; }
  .nav-links a span.nav-text { display: none; }
  .filter-bar { flex-direction: column; }
  .ws-header { flex-direction: column; }
  .workspace-actions { flex-direction: column; }
  .workspace-chat { max-height: 300px; }
  .workspace-layout { flex-direction: column; }
  .ws-context-panel { max-width: 100%; border-right: none; border-bottom: 1px solid #eeeee8; max-height: 250px; }
}

/* ─── Workspace Layout with Context Panel ─── */
.workspace-layout {
  display: flex;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.workspace-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

/* ─── Assignment Context Panel ─── */
.ws-context-panel {
  width: 320px;
  min-width: 280px;
  max-width: 380px;
  background: var(--sage-wash);
  border: 1px solid #eeeee8;
  border-radius: 14px;
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  flex-shrink: 0;
}

.ws-context-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e0e0d8;
}

.ws-context-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--deep-green);
}

.ws-context-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--warm-gray);
  padding: 0 4px;
  line-height: 1;
}

.ws-context-close:hover {
  color: var(--charcoal);
}

.ws-context-section {
  margin-bottom: 14px;
}

.ws-context-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--warm-gray);
  margin-bottom: 6px;
}

.ws-context-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--charcoal);
  white-space: pre-wrap;
  word-break: break-word;
  background: white;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #eeeee8;
  max-height: 200px;
  overflow-y: auto;
}

.ws-context-text.ws-extracted {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.5;
  background: #fafaf5;
}

.ws-extract-notice {
  text-align: center;
  padding: 8px;
}

.ws-extracting {
  color: var(--sage);
  font-size: 12px;
}

.ws-extract-success {
  color: var(--deep-green);
  font-size: 12px;
}

.ws-extract-fail {
  color: var(--soft-amber);
  font-size: 12px;
}
