:root{
  --navy:#071d49;
  --blue:#0b5ed7;
  --cyan:#25bde2;
  --cyan-light:#7ee7ff;
  --ink:#10233e;
  --muted:#667b91;
  --bg:#f4f8fc;
  --panel:#ffffff;
  --line:#dce8f3;
  --success:#147d56;
  --danger:#b42318;
}
*{box-sizing:border-box}
body{margin:0;font-family:Inter,Segoe UI,Arial,sans-serif;background:var(--bg);color:var(--ink)}
a{color:var(--blue);text-decoration:none}
.site-header{height:82px;background:#fff;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between;padding:8px 4vw;position:sticky;top:0;z-index:10}
.brand img{height:62px;max-width:420px;object-fit:contain;object-position:left center}
.site-header nav{display:flex;align-items:center;gap:20px;font-weight:650}
.container{width:min(1180px,92vw);margin:34px auto;min-height:calc(100vh - 180px)}
.hero{display:grid;grid-template-columns:1.2fr .8fr;gap:40px;align-items:center;padding:58px 0}
.hero h1{font-size:52px;line-height:1.05;color:var(--navy);margin:0 0 18px}
.hero p{font-size:20px;line-height:1.65;color:var(--muted)}
.hero-card,.card{background:#fff;border:1px solid var(--line);border-radius:16px;box-shadow:0 10px 30px rgba(7,29,73,.06);padding:28px}
.gradient-card{background:linear-gradient(135deg,var(--navy),var(--blue) 58%,var(--cyan));color:#fff}
.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:20px}
.btn{display:inline-block;border:0;border-radius:9px;padding:12px 18px;background:linear-gradient(90deg,var(--blue),var(--cyan));color:#fff!important;font-weight:750;cursor:pointer}
.btn.secondary{background:#fff;color:var(--blue)!important;border:1px solid #b8d4ee}
.btn.small{padding:9px 14px}
form{max-width:720px}
.form-card{background:#fff;border:1px solid var(--line);border-radius:16px;padding:30px;box-shadow:0 10px 30px rgba(7,29,73,.05)}
label{display:block;font-weight:700;margin:15px 0 7px}
input,textarea,select{width:100%;border:1px solid #bfd0df;border-radius:8px;padding:12px 13px;font:inherit;background:#fff}
input:focus,textarea:focus,select:focus{outline:2px solid rgba(37,189,226,.25);border-color:var(--cyan)}
.row{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.flash{padding:13px 16px;border-radius:8px;margin-bottom:18px}
.flash.success{background:#eaf8f2;color:var(--success)}
.flash.error{background:#fff0ee;color:var(--danger)}
.org-pill{padding:7px 10px;background:#edf7fc;border:1px solid #ccebf7;border-radius:999px;color:var(--navy);font-size:13px}
.page-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:22px}
.page-head h1{margin:0;color:var(--navy)}
.project-list{display:grid;gap:14px}
.project-item{background:#fff;border:1px solid var(--line);border-radius:12px;padding:20px}
.muted{color:var(--muted)}
.site-footer{border-top:1px solid var(--line);background:#fff;padding:22px 4vw;display:flex;justify-content:space-between;color:var(--muted);font-size:13px}
@media(max-width:800px){
  .hero,.grid,.row{grid-template-columns:1fr}
  .hero h1{font-size:40px}
  .site-header{height:auto;align-items:flex-start;gap:15px;flex-direction:column}
  .site-header nav{flex-wrap:wrap}
  .brand img{max-width:90vw;height:50px}
}

/* ===== COD SEARCH / STRUCTURE PAGES ===== */
.cod-search-card{max-width:none}
.advanced-search{margin-top:20px;border-top:1px solid var(--line);padding-top:16px}
.advanced-search summary{cursor:pointer;color:var(--blue);font-weight:750;margin-bottom:10px}
.check-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px;margin:18px 0}
.check{display:flex;align-items:center;gap:8px;font-weight:600;margin:0}
.check input{width:auto}
.search-actions{display:flex;gap:10px;margin-top:20px}
.results-head{display:flex;justify-content:space-between;align-items:end;margin:28px 0 14px}
.results-head h2{margin:0;color:var(--navy)}
.cod-results{display:grid;gap:14px}
.cod-result-card{
  display:flex;
  justify-content:space-between;
  gap:22px;
  align-items:center;
  background:#fff;
  border:1px solid var(--line);
  border-radius:14px;
  padding:20px;
  box-shadow:0 5px 20px rgba(7,29,73,.035)
}
.cod-result-card h3{margin:5px 0;color:var(--navy)}
.cod-id{
  font-size:12px;
  font-weight:800;
  letter-spacing:.08em;
  text-transform:uppercase;
  color:var(--blue)
}
.formula,.structure-formula{font-size:18px;font-weight:750;color:#24415f}
.metadata-line{
  display:flex;
  flex-wrap:wrap;
  gap:18px;
  margin-top:10px;
  color:#536a80;
  font-size:14px
}
.cod-result-actions{display:flex;gap:8px;flex:0 0 auto}
.small-text{font-size:13px;margin-top:8px}
.page-head-actions{display:flex;gap:9px;align-items:center}
.structure-layout{display:grid;grid-template-columns:1.6fr .8fr;gap:20px;margin-bottom:20px}
.detail-grid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:1px;
  background:var(--line);
  border:1px solid var(--line);
  border-radius:10px;
  overflow:hidden
}
.detail-grid>div{background:#fff;padding:15px}
.detail-grid span,.detail-list span{
  display:block;
  color:var(--muted);
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.04em;
  margin-bottom:5px
}
.detail-grid strong{font-size:15px;color:var(--navy)}
.detail-list{display:grid;gap:14px}
.detail-list>div{border-bottom:1px solid var(--line);padding-bottom:12px}
.publication-card{margin-bottom:20px}
.viewer-placeholder{
  min-height:250px;
  display:grid;
  place-items:center;
  text-align:center;
  background:linear-gradient(180deg,#fff,#f7fbfe)
}
.viewer-icon{font-size:64px;color:var(--cyan);line-height:1}
.project-structure-link{color:inherit}
.project-structure-link:hover{border-color:#a9d8ee;box-shadow:0 8px 24px rgba(7,29,73,.08)}
.cod-result-arrow{font-size:28px;color:var(--cyan)}

@media(max-width:800px){
  .check-grid,.detail-grid,.structure-layout{grid-template-columns:1fr}
  .cod-result-card{align-items:flex-start;flex-direction:column}
  .cod-result-actions{width:100%;flex-wrap:wrap}
  .page-head{align-items:flex-start;gap:15px;flex-direction:column}
}

/* ===== INTERACTIVE 3D CRYSTAL VIEWER ===== */
.crystal-viewer-card{
  padding:0;
  overflow:hidden;
  margin-bottom:20px
}
.viewer-toolbar{
  min-height:62px;
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:14px;
  padding:11px 16px;
  border-bottom:1px solid var(--line);
  background:#fff
}
.viewer-toolbar-group{
  display:flex;
  align-items:center;
  gap:8px
}
.viewer-toolbar-group label{
  margin:0;
  font-size:13px;
  color:var(--muted)
}
.viewer-toolbar select{
  width:auto;
  min-width:145px;
  padding:8px 32px 8px 10px
}
.viewer-toggle{
  display:flex;
  align-items:center;
  gap:7px;
  margin:0;
  font-size:13px;
  color:var(--ink);
  cursor:pointer
}
.viewer-toggle input{
  width:auto;
  margin:0
}
.viewer-tool-btn{
  border:1px solid #b9d5e8;
  background:#fff;
  color:var(--blue);
  border-radius:8px;
  padding:8px 11px;
  font:inherit;
  font-size:13px;
  font-weight:700;
  cursor:pointer
}
.viewer-tool-btn:hover{
  background:#f0f8fc;
  border-color:var(--cyan)
}
.viewer-stage-wrap{
  height:520px;
  min-height:420px;
  position:relative;
  background:#f8fbfe
}
.crystal-viewer-stage{
  position:absolute;
  inset:0;
  width:100%;
  height:100%
}
.viewer-loading,
.viewer-error{
  position:absolute;
  inset:0;
  z-index:3;
  display:flex;
  align-items:center;
  justify-content:center;
  flex-direction:column;
  gap:12px;
  text-align:center;
  color:var(--muted);
  background:#f8fbfe
}
.viewer-loading[hidden],
.viewer-error[hidden]{
  display:none
}
.viewer-error strong{
  color:var(--danger);
  font-size:18px
}
.viewer-spinner{
  width:36px;
  height:36px;
  border:4px solid #d9e9f3;
  border-top-color:var(--cyan);
  border-radius:50%;
  animation:mc-spin .8s linear infinite
}
@keyframes mc-spin{to{transform:rotate(360deg)}}
.viewer-help{
  display:flex;
  justify-content:space-between;
  gap:16px;
  padding:10px 16px;
  border-top:1px solid var(--line);
  background:#fff;
  color:var(--muted);
  font-size:12px
}
.viewer-help span{
  color:#7790a7
}
@media(max-width:800px){
  .viewer-stage-wrap{height:420px;min-height:360px}
  .viewer-toolbar{align-items:flex-start}
  .viewer-help{flex-direction:column;gap:4px}
}

/* ===== KETCHER DRAW / MOLECULAR SEARCH ===== */
.ketcher-card{
  padding:0;
  overflow:hidden;
  margin-bottom:20px
}
.ketcher-frame{
  width:100%;
  height:650px;
  border:0;
  display:block;
  background:#fff
}
.ketcher-unavailable{
  padding:16px 18px;
  background:#fff5f3;
  color:var(--danger);
  border-bottom:1px solid #f3ccc5
}
.ketcher-unavailable span{
  display:block;
  color:#6d4b46;
  margin-top:5px
}
.draw-search-panel{
  margin-bottom:20px
}
.draw-search-panel h2{
  margin-top:0;
  color:var(--navy)
}
.draw-search-grid{
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:6px 18px
}
.draw-organic-only{
  margin-top:20px
}
.draw-search-actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  margin-top:22px
}
.smiles-preview{
  margin-top:18px;
  padding:14px 16px;
  border:1px solid #cbe3f0;
  background:#f5fbfe;
  border-radius:10px
}
.smiles-preview span,
.molecular-query-summary span{
  display:block;
  color:var(--muted);
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.07em;
  font-weight:700;
  margin-bottom:5px
}
.smiles-preview code{
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  color:var(--navy)
}
.molecular-query-summary{
  display:flex;
  flex-wrap:wrap;
  gap:24px;
  margin-bottom:20px
}
.molecular-query-summary>div{
  min-width:130px
}
.molecular-query-summary code{
  max-width:520px;
  display:block;
  overflow-wrap:anywhere;
  color:var(--navy)
}
.molecular-query-summary strong{
  margin-right:8px
}
.molecular-results{
  margin-bottom:24px
}
@media(max-width:800px){
  .ketcher-frame{height:560px}
  .draw-search-grid{grid-template-columns:1fr}
  .molecular-query-summary{flex-direction:column;gap:14px}
}

/* ===== SEARCH HISTORY ===== */
.dashboard-stat-link{
  color:inherit;
  transition:border-color .15s ease,box-shadow .15s ease,transform .15s ease
}
.dashboard-stat-link:hover{
  border-color:#a9d8ee;
  box-shadow:0 10px 28px rgba(7,29,73,.08);
  transform:translateY(-1px)
}
.history-filter-card{
  margin-bottom:20px
}
.history-filter-form{
  max-width:none;
  display:flex;
  align-items:end;
  gap:14px
}
.history-filter-form>div:first-child{
  width:min(320px,100%)
}
.history-filter-actions{
  display:flex;
  gap:8px
}
.history-list{
  display:grid;
  gap:16px
}
.history-item{
  padding:22px
}
.history-item-head{
  display:flex;
  justify-content:space-between;
  gap:20px;
  align-items:flex-start
}
.history-type{
  color:var(--navy);
  font-size:18px;
  font-weight:800
}
.history-date{
  color:var(--muted);
  font-size:13px;
  margin-top:4px
}
.history-stats{
  display:flex;
  gap:10px;
  flex-wrap:wrap
}
.history-stats span{
  display:inline-flex;
  align-items:baseline;
  gap:5px;
  background:#f3f9fc;
  border:1px solid #d8eaf4;
  border-radius:999px;
  padding:6px 10px;
  color:var(--muted);
  font-size:12px
}
.history-stats strong{
  color:var(--navy)
}
.history-criteria{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:10px;
  margin-top:18px
}
.history-criteria>div{
  background:#f8fbfe;
  border:1px solid #e0edf5;
  border-radius:9px;
  padding:11px 12px;
  min-width:0
}
.history-criteria span{
  display:block;
  color:var(--muted);
  font-size:10px;
  text-transform:uppercase;
  letter-spacing:.07em;
  font-weight:750;
  margin-bottom:5px
}
.history-criteria strong,
.history-criteria code{
  color:var(--navy);
  font-size:13px;
  overflow-wrap:anywhere
}
.history-actions{
  display:flex;
  align-items:center;
  gap:8px;
  margin-top:18px
}
.history-actions form{
  margin:0
}
.history-actions .btn{
  padding:9px 13px
}
.history-empty{
  text-align:center;
  padding:44px 24px
}
.history-empty h2{
  color:var(--navy);
  margin-top:0
}
.history-empty-actions{
  display:flex;
  justify-content:center;
  flex-wrap:wrap;
  gap:10px;
  margin-top:20px
}
.history-pagination{
  display:flex;
  justify-content:center;
  align-items:center;
  gap:14px;
  margin-top:22px
}
.history-pagination span{
  color:var(--muted);
  font-size:13px
}
@media(max-width:800px){
  .history-filter-form{
    display:grid;
    grid-template-columns:1fr
  }
  .history-filter-form>div:first-child{
    width:100%
  }
  .history-item-head{
    flex-direction:column
  }
  .history-criteria{
    grid-template-columns:1fr
  }
  .history-actions{
    flex-wrap:wrap
  }
}

/* ===== HOMEPAGE GRADIENT CONTRAST FIX ===== */
.hero .gradient-card,
.hero .gradient-card h1,
.hero .gradient-card h2,
.hero .gradient-card h3,
.hero .gradient-card h4{
  color:#fff
}
.hero .gradient-card p{
  color:rgba(255,255,255,.94)
}

/* ===== FULL COD STRUCTURE RECORD ===== */
.structure-parameter-list{
  border:1px solid var(--line);
  border-radius:10px;
  overflow:hidden
}
.structure-parameter-row{
  display:grid;
  grid-template-columns:minmax(220px,34%) 1fr;
  border-bottom:1px solid var(--line)
}
.structure-parameter-row:last-child{border-bottom:0}
.structure-parameter-label{
  padding:11px 13px;
  background:#f7fbfe;
  color:#455f78;
  font-size:13px;
  font-weight:700
}
.structure-parameter-value{
  padding:11px 13px;
  background:#fff;
  color:var(--ink);
  overflow-wrap:anywhere
}
.structure-parameter-value code{
  color:var(--navy);
  white-space:pre-wrap;
  overflow-wrap:anywhere
}
.revision-history-card{margin-top:20px}
.full-record-head{
  display:flex;
  justify-content:space-between;
  gap:20px;
  align-items:flex-start
}
.full-record-head h2{margin-top:0}
.revision-table-wrap{
  width:100%;
  overflow:auto;
  border:1px solid var(--line);
  border-radius:10px
}
.revision-table{
  width:100%;
  border-collapse:collapse;
  min-width:850px
}
.revision-table th,
.revision-table td{
  padding:11px 13px;
  border-bottom:1px solid var(--line);
  vertical-align:top;
  text-align:left
}
.revision-table th{
  background:#f5f9fc;
  color:var(--navy);
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.05em
}
.revision-table tr:last-child td{border-bottom:0}
.revision-table .active-revision td{background:#edf8fc}
.revision-message{
  white-space:normal;
  min-width:360px
}
.revision-unavailable{
  border:1px solid #dce8f3;
  border-radius:10px;
  padding:16px;
  background:#f8fbfe
}
.raw-cif-card{
  margin-top:20px
}
.raw-cif-card summary{
  cursor:pointer;
  color:var(--navy);
  font-size:17px;
  font-weight:800
}
.raw-cif-card pre{
  max-height:620px;
  overflow:auto;
  margin:18px 0 0;
  padding:16px;
  background:#07182f;
  color:#eef8ff;
  border-radius:9px;
  font-size:12px;
  line-height:1.5;
  white-space:pre
}
@media(max-width:800px){
  .structure-parameter-row{grid-template-columns:1fr}
  .structure-parameter-label{border-bottom:1px solid #edf3f7}
  .full-record-head{flex-direction:column}
}


/* ===== COLLABORATION MODULE ===== */
.collab-two-column{display:grid;grid-template-columns:1fr 1fr;gap:20px}.collab-section{margin-bottom:20px}.collab-help{font-size:13px}.collab-list{display:grid;gap:0}.collab-list-row{display:flex;justify-content:space-between;align-items:center;gap:16px;padding:14px 0;border-bottom:1px solid var(--line)}.collab-list-row:last-child{border-bottom:0}.collab-row-actions{display:flex;align-items:center;gap:8px}.inline-form{display:flex;align-items:center;gap:8px;margin:0}.inline-form select{width:auto;min-width:130px}.project-collab-summary{display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-bottom:16px}.project-collab-summary>div{background:#fff;border:1px solid var(--line);border-radius:10px;padding:14px 16px}.project-collab-summary strong{display:block;color:var(--navy);font-size:24px}.project-collab-summary span{color:var(--muted);font-size:12px}.project-tabs{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:20px;border-bottom:1px solid var(--line)}.project-tabs a{padding:10px 14px;color:#536a80;font-weight:700;border-bottom:3px solid transparent}.project-tabs a.active{color:var(--blue);border-bottom-color:var(--cyan)}.collab-feed{display:grid;gap:14px}.collab-entry h3{margin:0;color:var(--navy)}.collab-entry-head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start}.collab-body{margin-top:14px;line-height:1.6}.viz-badge-link{display:inline-block;background:#edf7fc;border:1px solid #ccebf7;color:var(--blue);border-radius:999px;padding:6px 10px;font-size:12px;font-weight:750}.reply-form{display:flex;gap:8px;margin-top:14px;max-width:none}.reply-form input{flex:1}.activity-feed{display:grid}.activity-row{display:grid;grid-template-columns:18px 1fr;gap:10px;padding:13px 0;border-bottom:1px solid var(--line)}.activity-row:last-child{border-bottom:0}.activity-dot{width:9px;height:9px;border-radius:50%;background:var(--cyan);margin-top:6px}.member-add-form{display:grid;grid-template-columns:1fr 220px auto;gap:12px;align-items:end;max-width:none}.member-add-form label{margin-top:0}@media(max-width:850px){.collab-two-column,.project-collab-summary{grid-template-columns:1fr 1fr}.member-add-form{grid-template-columns:1fr}.collab-list-row{align-items:flex-start;flex-direction:column}.collab-row-actions{width:100%;flex-wrap:wrap}}@media(max-width:520px){.project-collab-summary,.collab-two-column{grid-template-columns:1fr}}
