/* ── Google Fonts ──────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans:wght@400;600;700&family=Inter:wght@400;500;600&display=swap');

/* ── CSS Variables ────────────────────────────────────────────────────────── */
:root {
  --teal:        #1A6B6B;
  --teal-light:  #22888A;
  --teal-dark:   #134F4F;
  --amber:       #E07B39;
  --amber-dark:  #C4661E;
  --charcoal:    #1A1A2E;
  --bg:          #F9F7F4;
  --white:       #FFFFFF;
  --grey-100:    #F2F0ED;
  --grey-200:    #E8E5E0;
  --grey-400:    #9E9B95;
  --grey-600:    #5C5A55;
  --red:         #D63B3B;
  --green:       #2A8A5C;
  --orange:      #D97706;
  --blue:        #2563EB;
  --purple:      #7C3AED;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
  --shadow-md:   0 4px 16px rgba(0,0,0,.10);
  --radius:      8px;
  --radius-lg:   12px;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--charcoal);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Typography ───────────────────────────────────────────────────────────── */
h1, h2, h3, h4 { font-family: 'IBM Plex Sans', sans-serif; font-weight: 700; line-height: 1.25; }
code, pre, .mono { font-family: 'IBM Plex Mono', monospace; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary   { background: var(--amber);  color: var(--white); }
.btn-primary:hover:not(:disabled)  { background: var(--amber-dark); }
.btn-secondary { background: var(--grey-200); color: var(--charcoal); }
.btn-secondary:hover:not(:disabled){ background: var(--grey-400); color: var(--white); }
.btn-teal      { background: var(--teal);   color: var(--white); }
.btn-teal:hover:not(:disabled)  { background: var(--teal-dark); }
.btn-sm { padding: 7px 14px; font-size: 0.8rem; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.875rem; color: var(--grey-600); }
input[type="email"],
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  background: var(--white);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: var(--charcoal);
  transition: border-color 0.15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--teal-light); }
textarea { resize: vertical; min-height: 100px; }
.char-count { font-size: 0.75rem; color: var(--grey-400); text-align: right; margin-top: 4px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

/* ── Alerts / Banners ─────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-error   { background: #FFF0F0; border: 1px solid #FECACA; color: var(--red); }
.alert-success { background: #F0FFF4; border: 1px solid #A7F3C8; color: var(--green); }
.alert-info    { background: #EFF6FF; border: 1px solid #BFDBFE; color: var(--blue); }
.alert-warning { background: #FFFBEB; border: 1px solid #FDE68A; color: var(--orange); }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

/* ── Login Page ───────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--teal-dark) 0%, var(--teal) 100%);
}
.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-md);
}
.login-logo { color: var(--teal); font-size: 1.8rem; font-family: 'IBM Plex Sans', sans-serif; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { color: var(--grey-600); font-size: 0.875rem; margin-bottom: 28px; }
.login-step { display: none; }
.login-step.active { display: block; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

/* ── App Header ───────────────────────────────────────────────────────────── */
.app-header {
  background: var(--teal);
  color: var(--white);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.app-logo { font-family: 'IBM Plex Sans', sans-serif; font-weight: 700; font-size: 1.1rem; letter-spacing: .02em; }
.usage-counter {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  background: rgba(0,0,0,.15);
  padding: 5px 12px;
  border-radius: 20px;
}
.usage-counter.warn  { color: #FFD580; }
.usage-counter.danger{ color: #FF8080; }
.header-email { font-size: 0.75rem; color: rgba(255,255,255,.7); }
.header-logout {
  background: none; border: none; color: rgba(255,255,255,.8);
  cursor: pointer; font-size: 0.78rem; text-decoration: underline;
  padding: 0; margin-left: 8px;
}

/* ── Tab Navigation ───────────────────────────────────────────────────────── */
.tab-nav {
  background: var(--white);
  border-bottom: 2px solid var(--grey-200);
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0;
  padding: 14px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--grey-600);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover { color: var(--teal); }
.tab-btn.active { color: var(--teal); border-bottom-color: var(--teal); font-weight: 600; }
.tab-icon { font-size: 1rem; }

/* ── Tool Panels ──────────────────────────────────────────────────────────── */
.tool-panel { display: none; padding: 24px 32px; max-width: 1400px; margin: 0 auto; width: 100%; }
.tool-panel.active { display: block; }
.tool-title { font-size: 1.25rem; color: var(--teal-dark); margin-bottom: 4px; }
.tool-desc  { color: var(--grey-600); font-size: 0.875rem; margin-bottom: 20px; }
.input-group { margin-bottom: 16px; }
.generate-btn-wrap { margin: 16px 0; }

/* ── Results ──────────────────────────────────────────────────────────────── */
.result-panel {
  margin-top: 24px;
  border-top: 2px solid var(--grey-200);
  padding-top: 20px;
}
.result-panel.hidden { display: none; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Diagram */
.diagram-container {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  padding: 20px;
  overflow-x: auto;
  margin-bottom: 16px;
  text-align: center;
}
.diagram-container svg { max-width: 100%; height: auto; }
.mermaid-editor label { font-weight: 600; font-size: 0.875rem; color: var(--grey-600); margin-bottom: 6px; display: block; }
.mermaid-code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  min-height: 120px;
  background: #1E1E2E;
  color: #CDD6F4;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
}
.feedback-box {
  background: #F0F9FF;
  border: 1px solid #BAE6FD;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 0.875rem;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* Stakeholder table */
.stakeholder-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  margin-top: 12px;
}
.stakeholder-table th {
  background: var(--teal);
  color: var(--white);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
}
.stakeholder-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--grey-200);
  vertical-align: top;
}
.stakeholder-table tr:nth-child(even) td { background: var(--grey-100); }
.elicitation-tip {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.875rem;
  margin-top: 16px;
}
.elicitation-tip strong { display: block; margin-bottom: 4px; color: var(--orange); }

/* Requirements classifier */
.classification-badge {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 12px;
}
.badge-general    { background: #DBEAFE; color: var(--blue); }
.badge-technical  { background: #EDE9FE; color: var(--purple); }
.badge-functional { background: #D1FAE5; color: var(--green); }
.badge-nonfunctional { background: #FFEDD5; color: var(--orange); }
.badge-transition { background: var(--grey-200); color: var(--grey-600); }
.confidence-label { font-size: 0.75rem; color: var(--grey-400); margin-left: 8px; }
.req-section { margin-bottom: 14px; }
.req-section-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--grey-400); margin-bottom: 4px; }
.req-rewrite {
  background: var(--grey-100);
  border-left: 4px solid var(--teal);
  padding: 10px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.875rem;
  font-style: italic;
}
.req-tip {
  background: #FFF0F0;
  border: 1px solid #FECACA;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.875rem;
}

/* Criteria table */
.criteria-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  margin-top: 12px;
}
.criteria-table th {
  background: var(--teal-dark);
  color: var(--white);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
}
.criteria-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--grey-200);
  vertical-align: top;
}
.criteria-table tr:nth-child(even) td { background: var(--grey-100); }
.weighting-note {
  background: #F0FFF4;
  border: 1px solid #A7F3C8;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.875rem;
  margin-top: 16px;
}
.weighting-note strong { display: block; margin-bottom: 4px; color: var(--green); }

/* Topic validator */
.verdict-badge {
  display: inline-block;
  padding: 8px 22px;
  border-radius: 24px;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 14px;
}
.verdict-approved         { background: #D1FAE5; color: var(--green); }
.verdict-likely-approved  { background: #D1FAE5; color: #15803D; }
.verdict-needs-revision   { background: #FFFBEB; color: var(--orange); }
.verdict-rejected         { background: #FFF0F0; color: var(--red); }
.verdict-section { margin-bottom: 16px; }
.verdict-section-title { font-weight: 700; font-size: 0.875rem; color: var(--grey-600); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.verdict-list { padding-left: 18px; font-size: 0.875rem; }
.verdict-list li { margin-bottom: 4px; }

/* ── Admin page ───────────────────────────────────────────────────────────── */
.admin-wrap { max-width: 960px; margin: 32px auto; padding: 0 24px 40px; }
.admin-title { font-size: 1.6rem; color: var(--teal-dark); margin-bottom: 4px; }
.admin-subtitle { color: var(--grey-600); margin-bottom: 24px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.admin-table th { background: var(--teal); color: var(--white); padding: 10px 14px; text-align: left; }
.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--grey-200); }
.admin-table tr:hover td { background: var(--grey-100); }
.cost-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}
.cost-stat { }
.cost-stat span { display: block; }
.cost-stat .val { font-size: 1.5rem; font-weight: 700; color: var(--teal); }
.cost-stat .lbl { font-size: 0.75rem; color: var(--grey-400); text-transform: uppercase; letter-spacing: .05em; }
.pin-form { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 24px; }
.pin-form .input-wrap { flex: 1; max-width: 260px; }
.pin-form label { font-size: 0.875rem; font-weight: 600; color: var(--grey-600); }
.pin-form input { max-width: 260px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .login-card { padding: 28px 20px; }
  .tool-panel { padding: 16px; }
  .tab-btn { padding: 12px 14px; font-size: 0.8rem; }
  .tab-btn .tab-label { display: none; }
  .stakeholder-table, .criteria-table, .admin-table { display: block; overflow-x: auto; }
  .app-header { padding: 0 14px; }
  .header-email { display: none; }
}

/* ══════════════════════════════════════════════════════════════════════════════
   TOOL 1 — Three-Column Layout
   ══════════════════════════════════════════════════════════════════════════ */
.t1-layout {
  display: grid;
  grid-template-columns: 200px minmax(340px, 420px) 1fr;
  gap: 16px;
  align-items: start;
  min-height: 600px;
}

/* Column header label */
.t1-col-header {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--teal-dark);
  border-bottom: 2px solid var(--teal-light);
  padding-bottom: 6px;
  margin-bottom: 10px;
}

/* ── History column ── */
.t1-history-col {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 500px;
  max-height: 80vh;
  overflow-y: auto;
}

.t1-history-empty {
  font-size: 0.8rem;
  color: var(--grey-400);
  text-align: center;
  margin-top: 24px;
  line-height: 1.6;
}

.t1-history-item {
  cursor: pointer;
  padding: 10px 10px;
  border-radius: 6px;
  border: 1px solid var(--grey-200);
  margin-bottom: 8px;
  background: var(--grey-100);
  transition: background 0.15s, border-color 0.15s;
}
.t1-history-item:hover {
  background: #e8f4f4;
  border-color: var(--teal-light);
}
.t1-history-item.active {
  background: #d4ecec;
  border-color: var(--teal);
}
.t1-history-item .t1-hist-num {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--teal);
  margin-bottom: 3px;
}
.t1-history-item .t1-hist-preview {
  font-size: 0.78rem;
  color: var(--grey-600);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

/* ── Input column ── */
.t1-input-col {
  display: flex;
  flex-direction: column;
}

/* Examples dropdown */
.t1-example-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.t1-example-select-wrap label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--grey-600);
  white-space: nowrap;
  margin-bottom: 0;
}
.t1-example-select {
  flex: 1;
  padding: 7px 10px;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  background: var(--white);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  color: var(--charcoal);
  cursor: pointer;
  width: auto;
  min-width: 0;
}
.t1-example-select:focus { outline: none; border-color: var(--teal-light); }
.t1-load-example-btn {
  flex-shrink: 0;
  padding: 7px 12px;
  font-size: 0.8rem;
}

/* Legacy panel (hidden but kept for compatibility) */
.t1-examples-panel {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.t1-example-item {
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--grey-200);
  margin-bottom: 6px;
  background: var(--grey-100);
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.t1-example-item:last-child { margin-bottom: 0; }
.t1-example-item:hover { background: #e8f4f4; border-color: var(--teal-light); }
.t1-example-item strong { font-size: 0.82rem; color: var(--charcoal); }
.t1-example-item span   { font-size: 0.75rem; color: var(--grey-600); }

/* ── Diagram column ── */
.t1-diagram-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Zoom controls bar */
.t1-zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.t1-zoom-controls button {
  background: var(--grey-200);
  border: none;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  color: var(--charcoal);
}
.t1-zoom-controls button:hover { background: var(--grey-400); color: var(--white); }
.t1-zoom-level {
  font-size: 0.75rem;
  color: var(--grey-600);
  min-width: 36px;
  text-align: center;
}

.t1-diagram-box {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  min-height: 600px;
  max-height: 82vh;
  overflow: hidden;
  position: relative;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.t1-diagram-box.panning { cursor: grabbing; }

/* Inner canvas that transforms for zoom/pan */
.t1-diagram-canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  /* No will-change:transform — that composites to a bitmap layer and causes blur.
     Zoom is applied by resizing the SVG itself, keeping it crisp vector at all scales. */
  padding: 0;
}
.t1-diagram-canvas svg {
  display: block;
  max-width: none;
  shape-rendering: geometricPrecision;
  text-rendering: optimizeLegibility;
}

.t1-diagram-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 560px;
  color: var(--grey-400);
  gap: 12px;
  text-align: center;
}
.t1-diagram-placeholder p { font-size: 0.875rem; }

/* Responsive: stack columns on narrow screens */
@media (max-width: 1200px) {
  .t1-layout {
    grid-template-columns: 180px minmax(300px, 380px) 1fr;
  }
}
@media (max-width: 900px) {
  .t1-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }
  .t1-history-col { grid-column: 1 / -1; min-height: auto; max-height: 180px; }
  .t1-diagram-col { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .t1-layout { grid-template-columns: 1fr; }
  .t1-history-col { grid-column: 1; }
  .t1-diagram-col { grid-column: 1; }
}

/* ── Print / PDF download ─────────────────────────────────────────────────── */
#ba-print-area { display: none; }

@media print {
  body > *:not(#ba-print-area) { display: none !important; }
  #ba-print-area {
    display: block !important;
    font-family: 'Inter', sans-serif;
    font-size: 12pt;
    color: #000;
  }
  .ba-print-header {
    border-bottom: 2px solid #1A6B6B;
    padding-bottom: 8px;
    margin-bottom: 16px;
    font-size: 14pt;
    color: #1A6B6B;
  }
  .ba-print-sub { font-size: 9pt; color: #555; margin-top: 2px; }
  /* Student input block */
  .ba-print-input-block {
    background: #f7f7f7;
    border-left: 3px solid #1A6B6B;
    padding: 8px 12px;
    margin-bottom: 12px;
    page-break-inside: avoid;
  }
  .ba-print-input-label { font-size: 8pt; font-weight: 700; color: #1A6B6B; text-transform: uppercase; margin-bottom: 4px; }
  .ba-print-input-text  { font-size: 10pt; white-space: pre-wrap; color: #222; }
  /* Make tables readable in print */
  table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
  th, td { border: 1px solid #ccc; padding: 6px 8px; font-size: 10pt; text-align: left; }
  th { background: #f0f0f0; }
  /* Hide buttons that appear inside result panels */
  .result-actions, button { display: none !important; }
}
