/* ===== Universal reset & theme ===== */
*,
*::before,
*::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #97F4FA;
  color: #e6eefc;
}

/* Theme tokens (dark) */
:root{
  --bg:#080530;
  --panel:#080530;
  --panel-2:#090007;
  --line:#1e2a44;
  --muted:#93a4c3;
  --fg:#e6eefc;
  --accent:#4cc9f0;
  --accent-ink:#07111f;
  --danger:#ff6b6b;
  --radius:14px;
  --radius-sm:10px;
  --shadow: 0 14px 50px rgba(0,0,0,.35);
}

/* (Optional) Light theme toggle: add .theme-light on <body> to switch */
.theme-light{
  --bg:#0b1020;          /* leave a touch dark so accents pop */
  --panel:#121a2a;
  --panel-2:#0f1828;
  --line:#22304d;
  --muted:#a8b6d4;
  --fg:#f2f6ff;
  --accent:#8dd8ff;
  --accent-ink:#06121f;
}

/* ===== Basic elements ===== */
a{ color: var(--accent); text-decoration: none; }
a:hover{ text-decoration: underline; }

label{ display:block; margin: 4px 0 6px; color: var(--muted); font-size: .95rem; }

input, textarea, select {
  width: 100%;
  color: var(--fg);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
}
input::placeholder, textarea::placeholder{ color: #7da0c9; }

textarea{ resize: vertical; line-height: 1.4; }

button, .btn{
  display:inline-flex; align-items:center; justify-content:center;
  gap: .4rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: transform .02s ease, filter .15s ease;
}
button:active, .btn:active{ transform: translateY(1px); }
.btn.ghost{
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--line);
}
button.danger{ background: var(--danger); color: var(--accent-ink); }
button.danger:hover{ filter: brightness(.95); }

.small{ font-size: .9rem; }
.muted{ color: var(--muted); }
.token{
  font-family: ui-monospace, Menlo, Consolas, monospace;
  background: #0a1a2a;
  color: #9dd2ff;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px dashed #2a486f;
  white-space: nowrap;
}

/* ===== Layout primitives ===== */
.container{ max-width: 1100px; margin: 0 auto; padding: 0 16px 40px; }

.topbar{
  position: sticky; top: 0; z-index: 5;
  display:flex; justify-content:space-between; align-items:center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.panel{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 16px 0;
  box-shadow: var(--shadow);
}

.card{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 50px;
}

.row{
  display:flex;
  flex-wrap: wrap;
  gap: 12px;                 /* consistent gaps in every browser */
  align-items: flex-start;   /* keep columns aligned at the top */
}
.col{ flex: 1 1 320px; min-width: 280px; }

/* ===== Dashboard grid ===== */
.grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.grid .card.link{
  text-decoration:none;
  transition: transform .08s ease, box-shadow .15s ease;
}
.grid .card.link:hover{
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(0,0,0,.35);
}
.grid .title{ font-weight: 700; margin-bottom: 6px; }
.grid .small{ color: var(--muted); }

/* ===== Figures section ===== */
.fig-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
  gap: 16px;
  align-items: start;
}
.fig.card .fig-title{ margin-bottom: 6px; }
.thumb{
  display:block;
  max-width: 220px; width: 220px; height: auto;
  margin: 8px auto 12px;        /* center the image nicely */
  border-radius: 12px;
  border: 1px solid var(--line);
  cursor: pointer;
}
.fig.card textarea,
.fig.card input[type="text"]{ width: 100%; }

/* Ensure brief/description sit on the same baseline across browsers */
.fig.card .row > .col textarea{ min-height: 96px; }
.fig.card .row > .col:last-child textarea{ min-height: 140px; }

/* ===== Upload / PDF row tidy alignment ===== */
.panel .row > form{
  flex: 1 1 320px;
  min-width: 280px;
}
#pdfHint{ display:inline-block; margin-left:.5rem; }

/* ===== Claims section ===== */
.claim{ margin: 10px 0 16px; }
.claim textarea{ min-height: 110px; }
.deps textarea{ min-height: 84px; }

/* Allow three tidy columns (Method / Apparatus / System) when wide */
@media (min-width: 1000px){
  .claims-columns{ display:grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
}

/* ===== Titles & meta area ===== */
.stack{ display:flex; flex-direction:column; gap: 8px; }
#title{ min-height: 44px; }

/* ===== Draft ===== */
#draft{ min-height: 420px; }

/* ===== Center helpers where needed ===== */
.centered{ min-height: 100vh; display:grid; place-items: center; }

/* ===== Focus rings (accessible) ===== */
:focus-visible{
  outline: 2px solid #8dd8ff;
  outline-offset: 2px;
  border-radius: 6px;
}

/* ===== Scroll/animation neutrality for consistency ===== */
@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

button.busy, .btn.busy { opacity: .85; }
button.busy::after, .btn.busy::after {
  content: '…';
  margin-left: .25rem;
  animation: dots 1.1s steps(3, end) infinite;
}
@keyframes dots { 0%{content:'·'} 33%{content:'··'} 66%{content:'···'} }

/* Title row: textarea on the left, button on the right */
.title-row{
  display:grid;
  grid-template-columns: 1fr auto;
  gap:.75rem;
  align-items:start;
  max-width: 720px;    /* keeps it from stretching across the whole card */
}

.title-row textarea{
  width:100%;
  min-height:40px;
  resize: vertical;    /* optional: let the user resize vertically */
}

/* Stack on small screens */
@media (max-width: 640px){
  .title-row{ grid-template-columns: 1fr; }
  .title-row button{ justify-self:start; }
}

/* “Draft (Editable)” — white paper look in Times 12pt, justified */
#draft{
  background:#fff !important;
  color:#111 !important;
  font-family:"Times New Roman", Times, serif !important;
  font-size:12pt;               /* Word-like size */
  line-height:1.5;              /* comfortable reading */
  text-align:justify;           /* justify paragraphs */
  padding:16px 18px;            /* breathing room */
  border:1px solid #d6dbe6;
  border-radius:10px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.06);
  caret-color:#000;             /* black cursor on white bg */
}

/* nicer focus state */
#draft:focus{
  outline: none;
  border-color:#7aa7ff;
  box-shadow: 0 0 0 3px rgba(122,167,255,.25);
}

/* optional: lighter placeholder in the white draft box */
#draft::placeholder{ color:#8a8f99; }

