/* ── Reset & Variables ── */

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

:root {
  --bg: #FAF8F4;
  --surface: #FFFFFF;
  --text: #1a1a1a;
  --text-secondary: #5c5c5c;
  --border: #e2dfd9;
  --border-focus: #1B2A4A;
  --accent: #1B2A4A;
  --accent-hover: #2a3d63;

  --score-low: #3a7d44;
  --score-low-bg: #eef6ef;
  --score-mild: #b8860b;
  --score-mild-bg: #fdf6e3;
  --score-moderate: #c95d1e;
  --score-moderate-bg: #fef0e6;
  --score-high: #a82020;
  --score-high-bg: #fce8e8;

  --warning-accent: #c0910a;
  --warning-bg: #fffcf0;
  --warning-border: #ecdba0;
  --info-accent: #1B2A4A;
  --info-bg: #f4f6fa;
  --info-border: #cdd4e0;

  --font-display: 'Newsreader', 'Georgia', serif;
  --font-body: 'Lexend', sans-serif;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Base ── */

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding: 32px 24px 64px;
}

/* ── Header ── */

header {
  position: relative;
  text-align: center;
  margin-bottom: 36px;
  max-width: 1120px;
  margin-left: auto;
  margin-right: auto;
}

.logo {
  height: 48px;
  width: auto;
  margin-bottom: 12px;
}

h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(28px, 5vw, 36px);
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--accent);
}

.subtitle {
  font-size: 14px;
  font-weight: 300;
  color: var(--text-secondary);
  margin-top: 8px;
  letter-spacing: 0.01em;
}

/* ── Two-column layout ── */

.layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 32px;
  max-width: 1120px;
  margin: 0 auto;
  align-items: start;
}

main {
  min-width: 0;
}

/* ── Sidebar ── */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 24px;
}

.sidebar-card {
  border-radius: 10px;
  padding: 20px;
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--border);
  background: var(--surface);
  animation: sidebarFadeIn 0.5s var(--ease-out) both;
}

.sidebar-card:nth-child(2) {
  animation-delay: 0.1s;
}

@keyframes sidebarFadeIn {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

.sidebar-card--warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  border-left-color: var(--warning-accent);
}

.sidebar-card--warning .sidebar-card-icon {
  color: var(--warning-accent);
}

.sidebar-card--warning .sidebar-card-title {
  color: #7a6400;
}

.sidebar-card--info {
  background: var(--info-bg);
  border-color: var(--info-border);
  border-left-color: var(--info-accent);
}

.sidebar-card--info .sidebar-card-icon {
  color: var(--info-accent);
}

.sidebar-card--info .sidebar-card-title {
  color: var(--info-accent);
}

.sidebar-card-icon {
  margin-bottom: 10px;
  line-height: 1;
}

.sidebar-card-title {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.sidebar-card-list {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-secondary);
}

.sidebar-card-list li::marker {
  color: var(--border);
}

.sidebar-card--warning .sidebar-card-list li::marker {
  color: var(--warning-border);
}

.sidebar-card--info .sidebar-card-list li::marker {
  color: var(--info-border);
}

.sidebar-card-list strong {
  font-weight: 500;
  color: var(--text);
}

/* ── Instructions card in main column ── */

main > .sidebar-card {
  margin-bottom: 20px;
  animation: resultsFadeIn 0.4s var(--ease-out) both;
}

/* ── Form ── */

form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.textarea-wrap {
  position: relative;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.textarea-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(27, 42, 74, 0.08);
}

textarea {
  display: block;
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 20px;
  padding-bottom: 36px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.75;
  color: var(--text);
  background: transparent;
  resize: vertical;
  min-height: 260px;
  outline: none;
}

textarea::placeholder {
  color: #b5b0a8;
  font-style: italic;
}

.char-count {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-size: 11px;
  font-weight: 400;
  color: #b5b0a8;
  pointer-events: none;
  transition: color 0.15s ease;
}

/* ── Context panel ── */

.context-panel {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.context-panel[open] {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(27, 42, 74, 0.05);
}

.context-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  list-style: none;
  transition: color 0.15s ease;
}

.context-toggle::-webkit-details-marker {
  display: none;
}

.context-toggle::marker {
  content: '';
}

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

.context-chevron {
  flex-shrink: 0;
  transition: transform 0.25s var(--ease-out);
  color: var(--text-secondary);
}

.context-panel[open] .context-chevron {
  transform: rotate(90deg);
}

.context-badge {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 100px;
  margin-left: 2px;
}

.context-fields {
  padding: 0 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: contextReveal 0.3s var(--ease-out) both;
}

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

.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

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

.field-group label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.field-group select {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235c5c5c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding: 9px 32px 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-group select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(27, 42, 74, 0.08);
}

.field-group select:hover {
  border-color: #c5c1ba;
}

.field-group textarea {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  resize: vertical;
  min-height: 72px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-group textarea::placeholder {
  color: #b5b0a8;
  font-style: italic;
  font-family: var(--font-body);
}

.field-group textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(27, 42, 74, 0.08);
}

/* ── Buttons ── */

.btn-row {
  display: flex;
  gap: 10px;
}

#analyse-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 14px 24px;
  border: none;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background-color: var(--accent);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
  overflow: hidden;
}

#analyse-btn:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

#analyse-btn:active:not(:disabled) {
  transform: scale(0.985);
}

#analyse-btn:disabled {
  cursor: not-allowed;
}

#analyse-btn.loading .btn-label {
  opacity: 0;
}

#analyse-btn.loading .btn-loading {
  opacity: 1;
}

.btn-loading {
  position: absolute;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.btn-loading .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  animation: dotPulse 1s ease-in-out infinite;
}

.btn-loading .dot:nth-child(2) { animation-delay: 0.15s; }
.btn-loading .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.btn-clear {
  padding: 14px 24px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  background-color: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.btn-clear:hover {
  border-color: var(--accent);
  color: var(--accent);
  background-color: #f5f3ef;
}

.btn-clear:active {
  transform: scale(0.985);
}

/* ── Results ── */

.results {
  margin-top: 32px;
  animation: resultsFadeIn 0.5s var(--ease-out) both;
}

.results.hidden {
  display: none;
  animation: none;
}

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

.results-header {
  text-align: center;
  padding: 28px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}

.score-ring {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  animation: scoreReveal 0.6s var(--ease-spring) both;
  animation-delay: 0.15s;
}

@keyframes scoreReveal {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.score-value {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  transition: color 0.3s ease;
}

.score-max {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  color: var(--text-secondary);
}

.score-label {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Score colour states */
.score-low .score-value { color: var(--score-low); }
.score-low .results-header { background: var(--score-low-bg); border-color: #c8deca; }

.score-mild .score-value { color: var(--score-mild); }
.score-mild .results-header { background: var(--score-mild-bg); border-color: #e8ddb8; }

.score-moderate .score-value { color: var(--score-moderate); }
.score-moderate .results-header { background: var(--score-moderate-bg); border-color: #e8d0bd; }

.score-high .score-value { color: var(--score-high); }
.score-high .results-header { background: var(--score-high-bg); border-color: #e8c0c0; }

/* ── Findings ── */

.findings {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.finding {
  padding: 16px 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  animation: findingSlideIn 0.4s var(--ease-out) both;
}

.finding:first-child {
  border-radius: 10px 10px 0 0;
}

.finding:last-child {
  border-radius: 0 0 10px 10px;
}

.finding:only-child {
  border-radius: 10px;
}

.finding:nth-child(1) { animation-delay: 0.25s; }
.finding:nth-child(2) { animation-delay: 0.35s; }
.finding:nth-child(3) { animation-delay: 0.45s; }
.finding:nth-child(4) { animation-delay: 0.55s; }
.finding:nth-child(5) { animation-delay: 0.65s; }

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

.finding-quote {
  display: block;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  padding-left: 14px;
  border-left: 2.5px solid var(--border);
  margin-bottom: 8px;
}

.finding-reason {
  display: block;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
}

/* ── Results caveat ── */

.results-caveat {
  margin-top: 12px;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 400;
  font-style: italic;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
}

/* ── Error ── */

.error-message {
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: 10px;
  background: var(--score-high-bg);
  border: 1.5px solid #e8c0c0;
  color: var(--score-high);
  font-size: 13px;
  font-weight: 400;
  text-align: center;
  animation: resultsFadeIn 0.3s var(--ease-out) both;
}

.error-message.hidden {
  display: none;
  animation: none;
}

/* ── Empty state (no findings) ── */

.findings-empty {
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}

/* ── Auth ── */

.hidden {
  display: none !important;
}

.login-container {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  background: var(--accent);
  overflow: hidden;
}

.login-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 80%, rgba(42, 61, 99, 0.7) 0%, transparent 70%),
    radial-gradient(ellipse 60% 50% at 80% 20%, rgba(27, 42, 74, 0.5) 0%, transparent 60%),
    radial-gradient(ellipse 100% 100% at 50% 50%, rgba(15, 23, 42, 0.3) 0%, transparent 80%);
  opacity: 1;
  pointer-events: none;
}

.login-card {
  position: relative;
  text-align: center;
  background: var(--surface);
  border-radius: 16px;
  padding: 52px 44px 44px;
  max-width: 400px;
  width: calc(100% - 48px);
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.04),
    0 20px 40px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  animation: loginCardIn 0.6s var(--ease-out) both;
  animation-delay: 0.1s;
}

@keyframes loginCardIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-logo {
  height: 52px;
  width: auto;
  margin-bottom: 24px;
}

.login-card h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin-bottom: 6px;
}

.login-description {
  font-size: 14px;
  font-weight: 300;
  color: var(--text-secondary);
  margin-bottom: 32px;
  line-height: 1.5;
}

.sign-in-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 32px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text);
  background-color: var(--surface);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.sign-in-btn:hover {
  background-color: #f8f7f5;
  border-color: #c5c1ba;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.sign-in-btn:active {
  transform: scale(0.985);
}

.google-icon {
  flex-shrink: 0;
}

.login-footer {
  font-size: 12px;
  font-weight: 300;
  color: var(--text-secondary);
  margin-top: 16px;
  line-height: 1.4;
}

.sign-out-btn {
  position: absolute;
  top: 32px;
  right: 24px;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.sign-out-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Responsive ── */

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    max-width: 640px;
  }

  .sidebar {
    order: -1;
    position: static;
  }
}

@media (max-width: 560px) {
  body {
    padding: 24px 16px 48px;
  }

  .sign-out-btn {
    position: static;
    margin-top: 12px;
  }

  .sidebar {
    flex-direction: column;
  }

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

  .login-card {
    padding: 40px 28px 32px;
    width: calc(100% - 32px);
  }

  .login-logo {
    height: 44px;
  }
}
