@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  --bg-dark: #181e2e;
  --bg-card: #202738;
  --bg-surface: #262f45;
  --bg-hover: #2d3855;
  --gold: #c9a84c;
  --gold-light: #e8c97a;
  --gold-dim: rgba(201, 168, 76, 0.15);
  --blue-accent: #4a90d9;
  --green: #3dd68c;
  --red: #f06464;
  --text-primary: #e8eaf0;
  --text-secondary: #9aa5bb;
  --text-muted: #6e7d96;
  --border: rgba(201, 168, 76, 0.15);
  --border-subtle: rgba(255,255,255,0.10);
  --shadow: 0 20px 60px rgba(0,0,0,0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at 20% 20%, rgba(74, 144, 217, 0.10) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(201, 168, 76, 0.09) 0%, transparent 55%);
  min-height: 100vh;
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 30px 20px;
  line-height: 1.6;
}

/* ── Layout ─────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 900px;
  animation: fadeUp 0.5s ease both;
}

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

/* ── Page Header ─────────────────────────────────── */
.page-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 50px 30px 40px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.page-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.page-header .logo-mark {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
}

.page-header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.page-header h1 span {
  color: var(--gold);
}

.page-header p {
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 300;
}

/* ── Section Title ───────────────────────────────── */
h2.section-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 10px;
}

h2.section-title .icon {
  color: var(--gold);
  font-size: 1.1rem;
}

/* ── Navbar ──────────────────────────────────────── */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 24px;
}

.navbar .brand {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.3px;
}

.user-greeting {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.88rem;
}

.user-greeting .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gold-dim);
  border: 1px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: 600;
}

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

/* ── Buttons ─────────────────────────────────────── */
.btn, button[type="submit"] {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.btn-primary, button[type="submit"] {
  background: var(--gold);
  color: #0d1117;
  font-weight: 600;
}
.btn-primary:hover, button[type="submit"]:hover {
  background: var(--gold-light);
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(201,168,76,0.35);
}

.btn {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.btn:hover {
  background: var(--bg-hover);
  border-color: var(--gold);
  color: var(--gold);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(61, 214, 140, 0.1);
  color: var(--green);
  border: 1px solid rgba(61, 214, 140, 0.25);
}
.btn-secondary:hover {
  background: rgba(61, 214, 140, 0.18);
  box-shadow: 0 6px 20px rgba(61, 214, 140, 0.2);
  transform: translateY(-1px);
}

.btn-danger {
  background: rgba(240, 100, 100, 0.1);
  color: var(--red);
  border: 1px solid rgba(240, 100, 100, 0.2);
}
.btn-danger:hover {
  background: rgba(240, 100, 100, 0.18);
  transform: translateY(-1px);
}

.btn-lg {
  padding: 14px 32px;
  font-size: 1rem;
}

button[type="submit"] {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  justify-content: center;
}

/* ── Cards ───────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
  transition: var(--transition);
}
.card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

/* ── Auth card (login/register) ──────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at 30% 30%, rgba(74,144,217,0.12) 0%, transparent 55%),
    radial-gradient(ellipse at 70% 70%, rgba(201,168,76,0.10) 0%, transparent 55%);
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 44px 40px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.45s ease both;
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo .mark {
  font-size: 2rem;
  display: block;
  margin-bottom: 6px;
}
.auth-logo h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
}
.auth-logo h1 span { color: var(--gold); }
.auth-logo p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-top: 4px;
}

/* ── Forms ───────────────────────────────────────── */
.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 13px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  color: var(--text-primary);
  transition: var(--transition);
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  background: var(--bg-hover);
  box-shadow: 0 0 0 3px var(--gold-dim);
}

textarea {
  min-height: 140px;
  resize: vertical;
  line-height: 1.6;
}

.input-with-icon {
  position: relative;
}
.input-with-icon .input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
  pointer-events: none;
}
.input-with-icon input {
  padding-left: 42px;
}

/* ── Alerts ──────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.9rem;
  line-height: 1.5;
  animation: fadeUp 0.3s ease both;
}

.alert-icon { font-size: 1.1rem; flex-shrink: 0; }

.alert-success {
  background: rgba(61, 214, 140, 0.1);
  border: 1px solid rgba(61, 214, 140, 0.25);
  color: #3dd68c;
}

.alert-error {
  background: rgba(240, 100, 100, 0.1);
  border: 1px solid rgba(240, 100, 100, 0.2);
  color: #f06464;
}

.alert-error a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

.alert-info {
  background: rgba(74, 144, 217, 0.1);
  border: 1px solid rgba(74, 144, 217, 0.25);
  color: #4a90d9;
}

.alert-sub {
  margin-top: 6px;
  font-size: 0.82rem;
  opacity: 0.85;
}

/* ── Thesis Card ─────────────────────────────────── */
.thesis-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.thesis-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(to bottom, var(--gold), transparent);
  border-radius: 3px 0 0 3px;
}
.thesis-card:hover {
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.thesis-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.thesis-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 50px;
  padding: 4px 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.thesis-badge .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
}

.thesis-topic {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
  line-height: 1.4;
}

.thesis-preview {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 16px;
}

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

/* ── Thesis Full View ────────────────────────────── */
.thesis-full-content {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 36px 40px;
  margin: 20px 0;
  font-size: 0.97rem;
  line-height: 1.85;
  color: var(--text-primary);
}
.thesis-full-content br + br {
  content: '';
  display: block;
  margin-top: 10px;
}

.thesis-references-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  margin-top: 24px;
}
.thesis-references-box h4 {
  color: var(--gold);
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  margin-bottom: 12px;
}

/* ── Hero / Landing ──────────────────────────────── */
.hero {
  text-align: center;
  padding: 60px 30px 50px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.hero-mark {
  font-size: 3rem;
  display: block;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.hero h1 {
  font-family: 'Playfair Display', serif;
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 14px;
}
.hero h1 span { color: var(--gold); }
.hero p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 480px;
  margin: 0 auto 30px;
  font-weight: 300;
}
.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Features Grid ───────────────────────────────── */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.feature-item {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: var(--transition);
}
.feature-item:hover {
  border-color: var(--border);
  transform: translateY(-2px);
}
.feature-item .feat-icon {
  font-size: 1.6rem;
  margin-bottom: 8px;
  display: block;
}
.feature-item h4 {
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.feature-item p {
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

/* ── Generate form panel ─────────────────────────── */
.generate-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 24px;
}
.generate-panel h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  color: var(--text-primary);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.generate-panel h2 span { color: var(--gold); }

/* ── Empty state ─────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  border-style: dashed;
}
.empty-state .empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 16px;
  opacity: 0.5;
}
.empty-state h3 {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 8px;
}
.empty-state p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 20px;
}

/* ── Progress/Loading ────────────────────────────── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(24,30,46,0.88);
  backdrop-filter: blur(4px);
  z-index: 1000;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.loading-text strong { color: var(--gold); }

/* ── Auth divider ────────────────────────────────── */
.auth-divider {
  text-align: center;
  margin: 20px 0;
  position: relative;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 30px);
  height: 1px;
  background: var(--border-subtle);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }

.auth-footer {
  text-align: center;
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.auth-footer a {
  color: var(--gold);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}
.auth-footer a:hover { color: var(--gold-light); text-decoration: underline; }

/* ── Misc ────────────────────────────────────────── */
.text-center { text-align: center; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }

.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 28px 0;
}

.tag {
  display: inline-block;
  background: var(--gold-dim);
  color: var(--gold);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Debug info ──────────────────────────────────── */
.debug-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 20px;
  margin-top: 20px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.debug-box h3 { color: var(--gold); margin-bottom: 12px; }
.debug-box p { margin-bottom: 5px; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 600px) {
  body { padding: 16px; }
  .auth-card { padding: 32px 24px; }
  .hero h1 { font-size: 2rem; }
  .navbar { flex-direction: column; gap: 12px; }
  .nav-actions { flex-wrap: wrap; justify-content: center; }
  .thesis-full-content { padding: 24px 20px; }
}
/* ── Paper / thesis rendered tables ─────────────────────────── */
.paper-table-wrap {
  overflow-x: auto;
  margin: 20px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}
.paper-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-card);
}
.paper-table .paper-th {
  background: var(--bg-surface);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 10px 16px;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border-subtle);
  white-space: nowrap;
  text-align: left;
}
.paper-table .paper-th:last-child { border-right: none; }
.paper-table .paper-td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid rgba(255,255,255,0.04);
  color: var(--text-secondary);
  vertical-align: top;
  line-height: 1.55;
}
.paper-table .paper-td:last-child { border-right: none; }
.paper-table .paper-tr-even .paper-td { background: rgba(255,255,255,0.018); }
.paper-table tr:last-child .paper-td { border-bottom: none; }
.paper-table tr:hover .paper-td { background: var(--bg-hover); }