<?php
if (session_status() === PHP_SESSION_NONE) session_start();
ini_set('display_errors', 0); error_reporting(0);
include_once __DIR__ . '/../config/db_new.php';

$journalSlug = trim($_GET['journal'] ?? '');
if (!$journalSlug) { $uri=$_SERVER['REQUEST_URI']??''; if(preg_match('#/journals/([a-z0-9-]+)/issue#',$uri,$m)) $journalSlug=$m[1]; }
$vol_id=(int)($_GET['id']??0); $vol_num=(int)($_GET['volume']??0); $iss_num=(int)($_GET['issue']??0);

$journal=null;
if($journalSlug&&$pdo){try{$s=$pdo->prepare("SELECT * FROM journals WHERE slug=? AND is_active=1 LIMIT 1");$s->execute([$journalSlug]);$journal=$s->fetch(PDO::FETCH_ASSOC);}catch(PDOException $e){}}

$volume=null;
if($pdo){try{if($vol_id){$s=$pdo->prepare("SELECT * FROM journal_volumes WHERE id=? AND is_active=1 LIMIT 1");$s->execute([$vol_id]);$volume=$s->fetch(PDO::FETCH_ASSOC);}elseif($vol_num&&$iss_num){$s=$pdo->prepare("SELECT * FROM journal_volumes WHERE volume=? AND issue=? AND is_active=1 LIMIT 1");$s->execute([$vol_num,$iss_num]);$volume=$s->fetch(PDO::FETCH_ASSOC);}}catch(PDOException $e){}}

$allVolumes=[];
if($pdo){try{$jid=$journal?(int)$journal['journal_id']:0;if($jid){$s=$pdo->prepare("SELECT * FROM journal_volumes WHERE journal_id=? AND is_active=1 ORDER BY year DESC,volume DESC,issue DESC");$s->execute([$jid]);}else{$s=$pdo->query("SELECT jv.*,j.name AS journal_name FROM journal_volumes jv LEFT JOIN journals j ON j.journal_id=jv.journal_id WHERE jv.is_active=1 ORDER BY jv.year DESC,jv.volume DESC,jv.issue DESC");}$allVolumes=$s->fetchAll(PDO::FETCH_ASSOC);}catch(PDOException $e){}}

$articles=[];
if($volume&&$pdo){try{$stmt=$pdo->prepare("SELECT s.submission_id,s.tracking_code,mi.article_title,mi.abstract,pf.doi,pf.page_no,pf.reference,pf.published_pdf_path,pf.publication_date,pf.volume_id,pf.article_slug,GROUP_CONCAT(TRIM(CONCAT(COALESCE(NULLIF(sa.title,''),''),' ',COALESCE(sa.first_name,''),' ',COALESCE(NULLIF(sa.middle_name,''),''),' ',COALESCE(sa.last_name,''))) ORDER BY sa.author_order SEPARATOR ', ') AS authors_list FROM submission_files pf JOIN submissions s ON s.submission_id=pf.submission_id LEFT JOIN manuscript_info mi ON mi.submission_id=s.submission_id LEFT JOIN submission_authors sa ON sa.submission_id=s.submission_id WHERE pf.volume_id=? AND pf.file_type IN ('payment_receipt','final_manuscript_revised','declaration_form') AND pf.publication_date IS NOT NULL GROUP BY s.submission_id ORDER BY CAST(SUBSTRING_INDEX(COALESCE(pf.page_no,'0'),'-',1) AS UNSIGNED) ASC,pf.publication_date ASC");$stmt->execute([$volume['id']]);$articles=$stmt->fetchAll(PDO::FETCH_ASSOC);}catch(PDOException $e){}}

$siteUrl=(isset($_SERVER['HTTPS'])?'https':'http').'://'.$_SERVER['HTTP_HOST'];
$jName=$journal['name']??'Communeglobal International Journal of Social Sciences';
$jSlug=$journalSlug??($journal['slug']??'social-science');
$volLabel=$volume?'Volume '.$volume['volume'].', Issue '.$volume['issue'].($volume['year']?' ('.$volume['year'].')':''):'Browse Issues';
$issTitle=$volume['title']??''; $total=count($articles);

$finalTitle=$volume?$jName.' | '.$volLabel:$jName.' | Archive';
$finalDesc=$volume?"Browse {$total} peer-reviewed articles in {$jName}, {$volLabel}.":"Browse all published issues of {$jName}.";
$finalCanonical=$siteUrl.'/journals/'.$jSlug.'/issue.php?'.($vol_id?"id={$vol_id}":"volume={$vol_num}&issue={$iss_num}");
$finalKeywords=''; $finalFeatureImg=$siteUrl.'/asset/og-default.jpg'; $finalImgAlt=$jName;
$ogTitle=$finalTitle;$ogDesc=$finalDesc;$ogImage=$finalFeatureImg;$ogType='website';
$twCard='summary_large_image';$twTitle=$finalTitle;$twDesc=$finalDesc;$twImage=$finalFeatureImg;$twSite='@communeglobal';
$schemaRaw=$aiSummary=$faqSchema=''; $htmlTitle=htmlspecialchars($finalTitle);
$pageData=['title'=>$volLabel,'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')];

function hx($v):string{return htmlspecialchars($v??'',ENT_QUOTES,'UTF-8');}
function pdfUrl($p,$sr='https://communeglobal.com'):string{$p=trim((string)$p);if(!$p||$p==='0')return '';if(strpos($p,'http')===0)return $p;return $sr.(strpos(ltrim($p,'/'),'uploads/')===0?'/author/':'/').(ltrim($p,'/'));}

include __DIR__ . '/../include/header.php';
?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
*,*::before,*::after{box-sizing:border-box}
:root{--ink:#0d1b2a;--ink2:#1e3a5f;--blue:#1a56db;--blue-l:#eff6ff;--accent:#c8410a;--green:#0a6640;--green-l:#dcfce7;--muted:#64748b;--border:#e2e8f0;--bg:#f8fafc;--w:#fff;--serif:'Georgia',serif;--sans:system-ui,-apple-system,sans-serif;--sh:0 1px 4px rgba(0,0,0,.08);--sh2:0 4px 20px rgba(0,0,0,.10)}
.ip{background:var(--bg);font-family:var(--sans);color:var(--ink)}
.wrap{max-width:1140px;margin:0 auto;padding:0 20px}
/* strip */
.ip-strip{background:var(--ink2);padding:9px 0;font-size:12px;color:rgba(255,255,255,.7)}
.ip-bc{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.ip-bc a{color:rgba(255,255,255,.75);text-decoration:none}.ip-bc a:hover{color:#fff}
.ip-bc i{font-size:8px;color:rgba(255,255,255,.35)}
/* hero */
.ip-hero{background:linear-gradient(155deg,#0d1f3c 0%,#1a3a6b 55%,#173060 100%);padding:44px 0 38px;position:relative;overflow:hidden}
.ip-hero::before{content:'';position:absolute;top:-60px;right:-60px;width:380px;height:380px;border-radius:50%;background:rgba(255,255,255,.03)}
.ip-hero::after{content:'';position:absolute;bottom:-50px;left:8%;width:280px;height:280px;border-radius:50%;background:rgba(26,86,219,.07)}
.ip-hero-in{position:relative;z-index:1}
.ip-jtag{display:inline-flex;align-items:center;gap:6px;background:rgba(255,255,255,.1);border:1px solid rgba(255,255,255,.18);color:rgba(255,255,255,.9);border-radius:20px;padding:4px 14px;font-size:12px;font-weight:600;text-decoration:none;margin-bottom:13px;transition:background .15s}
.ip-jtag:hover{background:rgba(255,255,255,.18);color:#fff}
.ip-hero h1{font-family:var(--serif);font-size:clamp(22px,3.5vw,36px);font-weight:700;color:#fff;line-height:1.22;margin:0 0 8px}
.ip-hero-sub{font-size:13.5px;color:rgba(255,255,255,.65);font-style:italic;margin-bottom:17px}
.ip-badges{display:flex;flex-wrap:wrap;gap:8px}
.ip-badge{display:inline-flex;align-items:center;gap:5px;background:rgba(255,255,255,.09);border:1px solid rgba(255,255,255,.14);border-radius:16px;padding:4px 12px;font-size:11.5px;font-weight:500;color:#fff}
.ip-badge i{font-size:10px;color:#93bff5}
/* body */
.ip-body{padding:32px 0 60px}
.ip-grid{display:grid;grid-template-columns:248px 1fr;gap:26px;align-items:start}
@media(max-width:880px){.ip-grid{grid-template-columns:1fr}}
/* left col */
.ip-left{position:sticky;top:78px}
/* toc */
.ip-toc{background:var(--w);border-radius:12px;box-shadow:var(--sh);overflow:hidden;margin-bottom:14px}
.ip-toc-hd{background:var(--ink);color:#fff;padding:11px 15px;display:flex;align-items:center;justify-content:space-between}
.ip-toc-hd h3{font-size:11.5px;font-weight:700;text-transform:uppercase;letter-spacing:.8px;display:flex;align-items:center;gap:6px}
.ip-toc-cnt{background:var(--accent);color:#fff;font-size:10px;font-weight:700;padding:1px 7px;border-radius:9px}
.ip-toc-dl{background:rgba(255,255,255,.12);color:#fff;border:none;border-radius:4px;padding:3px 9px;font-size:10.5px;font-weight:600;cursor:pointer;text-decoration:none;display:inline-flex;align-items:center;gap:4px}
.ip-toc-dl:hover{background:rgba(255,255,255,.22);color:#fff}
.ip-toc-scroll{max-height:400px;overflow-y:auto}
.ip-toc-list{list-style:none;padding:5px 0}
.ip-toc-list li{border-bottom:1px solid #f1f5f9}
.ip-toc-list li a{display:flex;align-items:flex-start;gap:6px;padding:6px 13px;text-decoration:none;font-size:11px;transition:background .1s}
.ip-toc-list li a:hover{background:#f8fafc}
.ip-tsn{min-width:17px;font-size:10px;font-weight:700;color:var(--blue);flex-shrink:0;padding-top:1px}
.ip-tt{color:var(--ink);line-height:1.35;flex:1}
.ip-tpg{font-size:10px;color:var(--muted);white-space:nowrap;flex-shrink:0;padding-top:1px}
/* issue list */
.ip-issues{background:var(--w);border-radius:12px;box-shadow:var(--sh);overflow:hidden}
.ip-issues-hd{padding:10px 14px;background:#f1f5f9;border-bottom:1px solid var(--border);font-size:11px;font-weight:700;text-transform:uppercase;letter-spacing:.7px;color:var(--muted);display:flex;align-items:center;gap:6px}
.ip-vlist{list-style:none;padding:0}
.ip-vlist li a{display:flex;align-items:center;justify-content:space-between;padding:7px 13px;text-decoration:none;font-size:12px;color:var(--ink);border-bottom:1px solid #f1f5f9;transition:background .1s,color .1s}
.ip-vlist li a:hover{background:#f8fafc;color:var(--blue)}
.ip-vlist li a.active{background:var(--blue-l);color:var(--blue);font-weight:700}
.ip-curr{background:#dbeafe;color:var(--blue);font-size:10px;font-weight:700;padding:1px 7px;border-radius:8px}
/* right col */
.ip-art-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px;flex-wrap:wrap;gap:10px}
.ip-art-top h2{font-family:var(--serif);font-size:19px;font-weight:700;color:var(--ink);display:flex;align-items:center;gap:8px}
.ip-srch{display:flex;align-items:center;gap:7px;background:var(--w);border:1.5px solid var(--border);border-radius:7px;padding:6px 12px}
.ip-srch input{border:none;outline:none;font-size:12.5px;color:var(--ink);background:transparent;font-family:inherit;width:190px}
.ip-srch i{color:var(--muted);font-size:12px}
/* card */
.ip-card{background:var(--w);border-radius:10px;border:1px solid var(--border);padding:20px 22px;margin-bottom:12px;border-left:4px solid transparent;transition:border-color .15s,box-shadow .15s;scroll-margin-top:76px}
.ip-card:hover{border-left-color:var(--blue);box-shadow:var(--sh2)}
.ip-card-top{display:flex;align-items:flex-start;gap:12px;margin-bottom:9px}
.ip-cnum{width:26px;height:26px;border-radius:50%;background:var(--ink2);color:#fff;display:flex;align-items:center;justify-content:center;font-size:10.5px;font-weight:700;flex-shrink:0;margin-top:2px}
.ip-ctitle{font-family:var(--serif);font-size:15.5px;font-weight:600;color:var(--ink);line-height:1.4;text-decoration:none;display:block;margin-bottom:4px;transition:color .12s}
.ip-ctitle:hover{color:var(--blue)}
.ip-cauth{font-size:12px;color:var(--muted);font-style:italic;margin-bottom:9px}
.ip-cbody{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-bottom:11px}
@media(max-width:680px){.ip-cbody{grid-template-columns:1fr}}
.ip-abs-lbl{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:1px;color:var(--muted);margin-bottom:4px}
.ip-abs-txt{font-size:12.5px;color:#475569;line-height:1.6;display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden}
.ip-abs-btn{background:none;border:none;color:var(--blue);font-size:11px;font-weight:600;cursor:pointer;padding:2px 0;font-family:inherit;display:block;margin-top:3px}
.ip-info-row{display:flex;align-items:center;gap:7px;margin-bottom:6px;font-size:12px}
.ip-info-row i{width:13px;text-align:center;color:var(--muted);font-size:10.5px;flex-shrink:0}
.ip-doi{color:var(--blue);text-decoration:none;font-family:monospace;font-size:11.5px}.ip-doi:hover{text-decoration:underline}
.ip-cfoot{display:flex;flex-wrap:wrap;gap:7px;padding-top:11px;border-top:1px solid var(--border)}
.ip-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 14px;border-radius:5px;font-size:12px;font-weight:600;text-decoration:none;border:none;cursor:pointer;transition:all .15s;font-family:inherit}
.ip-b-blue{background:var(--blue);color:#fff}.ip-b-blue:hover{background:#1648c2;color:#fff}
.ip-b-red{background:#dc2626;color:#fff}.ip-b-red:hover{background:#b91c1c;color:#fff}
.ip-b-out{background:var(--bg);color:var(--ink);border:1.5px solid var(--border)}.ip-b-out:hover{background:#e2e8f0}
/* empty */
.ip-empty{text-align:center;padding:55px 20px;background:var(--w);border-radius:10px;border:1px solid var(--border)}
.ip-empty i{font-size:42px;color:#cbd5e1;margin-bottom:11px;display:block}
.ip-empty h3{font-family:var(--serif);font-size:17px;color:var(--ink);margin-bottom:6px}
.ip-empty p{font-size:13px;color:var(--muted)}
/* grid (no vol) */
.ip-vgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(185px,1fr));gap:11px}
.ip-vcard{display:block;border:1.5px solid var(--border);border-radius:9px;padding:13px 15px;text-decoration:none;background:var(--w);transition:all .15s}
.ip-vcard:hover{border-color:var(--blue);box-shadow:var(--sh2);transform:translateY(-2px)}
.ip-vcard-v{font-size:11px;font-weight:700;color:var(--blue);text-transform:uppercase;letter-spacing:.7px;margin-bottom:3px}
.ip-vcard-t{font-size:12.5px;font-weight:600;color:var(--ink);line-height:1.3}
.ip-vcard-y{font-size:11px;color:var(--muted);margin-top:3px}
/* modal */
.ip-modal{display:none;position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:9999;align-items:center;justify-content:center}
.ip-modal.open{display:flex}
.ip-mbox{background:#fff;border-radius:13px;padding:24px 28px;max-width:550px;width:92%;box-shadow:0 8px 40px rgba(0,0,0,.2)}
.ip-mbox h3{font-family:var(--serif);font-size:15.5px;margin-bottom:11px;color:var(--ink);display:flex;align-items:center;gap:7px}
.ip-mcite{background:#f8fafc;border:1px solid var(--border);border-radius:7px;padding:12px;font-size:12.5px;line-height:1.7;color:var(--ink);user-select:all;margin-bottom:11px}
.ip-mbtns{display:flex;gap:8px;justify-content:flex-end}
@media(max-width:640px){.ip-card{padding:14px 12px}.ip-hero{padding:30px 0 26px}}
</style>

<div class="ip">

<div class="ip-strip"><div class="wrap"><div class="ip-bc">
  <a href="<?=hx($siteUrl)?>">Home</a><i class="fas fa-chevron-right"></i>
  <a href="<?=hx($siteUrl.'/journals/'.$jSlug.'/')?>">CIJSS</a><i class="fas fa-chevron-right"></i>
  <?php if($volume):?><a href="<?=hx($siteUrl.'/journals/'.$jSlug.'/issue.php')?>">Archive</a><i class="fas fa-chevron-right"></i><span><?=hx($volLabel)?></span>
  <?php else:?><span>Archive</span><?php endif;?>
</div></div></div>

<div class="ip-hero"><div class="wrap"><div class="ip-hero-in">
  <a href="<?=hx($siteUrl.'/journals/'.$jSlug.'/')?>" class="ip-jtag"><i class="fas fa-graduation-cap"></i> <?=hx($jName)?></a>
  <h1><?=$volume?hx($volLabel):'Browse All Issues'?></h1>
  <?php if($issTitle):?><div class="ip-hero-sub"><?=hx($issTitle)?></div><?php endif;?>
  <div class="ip-badges">
    <?php if($volume&&$volume['year']):?><span class="ip-badge"><i class="fas fa-calendar-alt"></i> <?=hx($volume['year'])?></span><?php endif;?>
    <?php if($volume):?><span class="ip-badge"><i class="fas fa-file-alt"></i> <?=$total?> Article<?=$total!=1?'s':''?></span><?php endif;?>
    <span class="ip-badge"><i class="fas fa-unlock-alt"></i> Open Access</span>
    <span class="ip-badge"><i class="fas fa-check-double"></i> Peer Reviewed</span>
    <?php if(count($allVolumes)>1):?><span class="ip-badge"><i class="fas fa-archive"></i> <?=count($allVolumes)?> Issues</span><?php endif;?>
  </div>
</div></div>

</div>
<div class="ip-body container" >
<h5>In Progress</h5>
</div>

<div class="ip-body " style="display : none;"><div class="wrap">

<?php if(!$volume):?>
<h2 style="font-family:var(--serif);font-size:20px;color:var(--ink);margin-bottom:15px;display:flex;align-items:center;gap:8px">
  <i class="fas fa-archive" style="color:var(--blue);font-size:.9em"></i> All Published Issues
</h2>
<?php if(empty($allVolumes)):?>
<div class="ip-empty"><i class="fas fa-inbox"></i><h3>No issues yet</h3><p>Issues will appear here once articles are published.</p></div>
<?php else:?>
<div class="ip-vgrid">
<?php foreach($allVolumes as $v):?>
<a href="<?=hx($siteUrl.'/journals/'.$jSlug.'/issue.php?id='.(int)$v['id'])?>" class="ip-vcard">
  <div class="ip-vcard-v">Vol.<?=(int)$v['volume']?> · Issue <?=(int)$v['issue']?></div>
  <?php if($v['title']):?><div class="ip-vcard-t"><?=hx($v['title'])?></div><?php endif;?>
  <div class="ip-vcard-y"><?=$v['year']?:'—'?><?php if(!empty($v['journal_name'])):?> · <?=hx($v['journal_name'])?><?php endif;?></div>
</a>
<?php endforeach;?>
</div>
<?php endif;?>

<?php else:?>
<div class="ip-grid">

<aside class="ip-left">
<?php if(!empty($articles)):?>
<div class="ip-toc">
  <div class="ip-toc-hd">
    <h3><i class="fas fa-list-ol"></i> Contents <span class="ip-toc-cnt"><?=$total?></span></h3>
    <a href="?<?=$vol_id?"id={$vol_id}":"volume={$vol_num}&issue={$iss_num}"?>&download_toc=1" class="ip-toc-dl"><i class="fas fa-download"></i> TOC</a>
  </div>
  <div class="ip-toc-scroll"><ul class="ip-toc-list">
  <?php foreach($articles as $i=>$a):?>
  <li><a href="#ipa-<?=(int)$a['submission_id']?>">
    <span class="ip-tsn"><?=$i+1?></span>
    <span class="ip-tt"><?=hx(mb_strimwidth($a['article_title']??'',0,80,'…'))?></span>
    <?php if($a['page_no']):?><span class="ip-tpg"><?=hx($a['page_no'])?></span><?php endif;?>
  </a></li>
  <?php endforeach;?>
  </ul></div>
</div>
<?php endif;?>
<?php if(!empty($allVolumes)):?>
<div class="ip-issues">
  <div class="ip-issues-hd"><i class="fas fa-archive"></i> All Issues</div>
  <ul class="ip-vlist">
  <?php foreach($allVolumes as $v):$isAct=(int)$v['id']===(int)$volume['id'];?>
  <li><a href="<?=hx($siteUrl.'/journals/'.$jSlug.'/issue.php?id='.(int)$v['id'])?>" class="<?=$isAct?'active':''?>">
    <span><strong style="display:block;font-size:11.5px">Vol.<?=(int)$v['volume']?> · Issue <?=(int)$v['issue']?></strong>
    <?php if($v['title']):?><span style="font-size:10.5px;color:#94a3b8"><?=hx(mb_strimwidth($v['title'],0,26,'…'))?></span><?php endif;?>
    </span><?php if($isAct):?><span class="ip-curr">Current</span><?php endif;?>
  </a></li>
  <?php endforeach;?>
  </ul>
</div>
<?php endif;?>
</aside>

<div>
<div class="ip-art-top">
  <h2><i class="fas fa-newspaper" style="color:var(--blue);font-size:.85em"></i> Articles</h2>
  <div class="ip-srch"><i class="fas fa-search"></i><input type="text" id="ipSrch" placeholder="Search title or author…" oninput="ipFilter(this.value)"></div>
</div>

<?php if(empty($articles)):?>
<div class="ip-empty"><i class="fas fa-newspaper"></i><h3>No articles yet</h3>
<p>Articles will appear once assigned to this issue.<br><a href="<?=hx($siteUrl.'/author/submission.php')?>" style="color:var(--blue)">Submit your paper</a></p></div>
<?php else:?>
<div id="ipArts">
<?php foreach($articles as $i=>$a):
  $sid=(int)$a['submission_id'];
  $ttl=$a['article_title']??'Untitled';
  $auth=trim(preg_replace('/\s+/',' ',$a['authors_list']??''));
  $abs=$a['abstract']??''; $doi=$a['doi']??''; $pg=$a['page_no']??'';
  $pdf=$a['published_pdf_path']?pdfUrl($a['published_pdf_path']):'';
  $pd=$a['publication_date']??'';
//   $artUrl=$siteUrl.'/journals/'.$jSlug.'/article.php?id='.$sid;
  $artSlug = trim($a['article_slug'] ?? '');
$artUrl = $artSlug
    ? $siteUrl.'/journals/'.$jSlug.'/article/'.$artSlug
    : $siteUrl.'/journals/article.php?id='.$sid;
  $cite=($auth?$auth.'. ':'').($volume['year']?'('.$volume['year'].'). ':'').$ttl.'. '.$jName.', '.$volLabel.($pg?', pp.'.$pg:'').'.'.($doi?' https://doi.org/'.$doi:'');
?>
<div class="ip-card" id="ipa-<?=$sid?>" data-title="<?=hx(strtolower($ttl))?>" data-authors="<?=hx(strtolower($auth))?>">
  <div class="ip-card-top">
    <div class="ip-cnum"><?=$i+1?></div>
    <div style="flex:1">
      <a href="<?=hx($artUrl)?>" class="ip-ctitle"><?=hx($ttl)?></a>
      <?php if($auth):?><div class="ip-cauth"><strong style="font-style:normal;color:#475569;font-size:11px">Authors:</strong> <?=hx($auth)?></div><?php endif;?>
    </div>
  </div>
  <div class="ip-cbody">
    <div>
      <?php if($abs):?>
      <div class="ip-abs-lbl">Abstract</div>
      <div class="ip-abs-txt" id="ipab-<?=$sid?>"><?=hx($abs)?></div>
      <button class="ip-abs-btn" onclick="ipAbs(<?=$sid?>)" id="ipabt-<?=$sid?>">Read more…</button>
      <?php else:?><span style="font-size:12px;color:#94a3b8;font-style:italic">No abstract</span><?php endif;?>
    </div>
    <div>
      <?php if($doi):?><div class="ip-info-row"><i class="fas fa-fingerprint"></i><a href="https://doi.org/<?=hx($doi)?>" target="_blank" class="ip-doi" rel="noopener"><?=hx($doi)?></a></div><?php endif;?>
      <?php if($pg):?><div class="ip-info-row"><i class="fas fa-book-open"></i><span>Pages: <?=hx($pg)?></span></div><?php endif;?>
      <?php if($pd):?><div class="ip-info-row"><i class="fas fa-calendar-check"></i><span><?=hx(date('d M Y',strtotime($pd)))?></span></div><?php endif;?>
      <div class="ip-info-row"><i class="fas fa-unlock-alt" style="color:var(--green)"></i><span style="color:var(--green);font-weight:600;font-size:11.5px">Open Access</span></div>
    </div>
  </div>
  <div class="ip-cfoot">
    <a href="<?=hx($artUrl)?>" class="ip-btn ip-b-blue"><i class="fas fa-book-reader"></i> Read More</a>
    <?php if($pdf):?><a href="<?=hx($pdf)?>" target="_blank" class="ip-btn ip-b-red"><i class="fas fa-file-pdf"></i> Download PDF</a><?php endif;?>
    <button class="ip-btn ip-b-out" onclick="ipCite('<?=htmlspecialchars(addslashes($cite),ENT_QUOTES)?>')"><i class="fas fa-quote-left"></i> Cite</button>
  </div>
</div>
<?php endforeach;?>
</div>
<?php endif;?>
</div>

</div>
<?php endif;?>
</div></div>
</div>

<div class="ip-modal" id="ipModal" onclick="if(event.target===this)ipCC()">
  <div class="ip-mbox">
    <h3><i class="fas fa-quote-left" style="color:var(--blue)"></i> Cite this Article</h3>
    <div class="ip-mcite" id="ipCT"></div>
    <div class="ip-mbtns">
      <button class="ip-btn ip-b-out" onclick="ipCC()">Close</button>
      <button class="ip-btn ip-b-blue" onclick="ipCopy()"><i class="fas fa-copy"></i> Copy</button>
    </div>
  </div>
</div>
<script>
var _e={};
function ipAbs(s){var el=document.getElementById('ipab-'+s),b=document.getElementById('ipabt-'+s);if(_e[s]){el.style.webkitLineClamp='4';el.style.display='-webkit-box';b.textContent='Read more…';_e[s]=false;}else{el.style.webkitLineClamp='unset';el.style.display='block';b.textContent='Show less';_e[s]=true;}}
function ipFilter(q){q=q.toLowerCase().trim();document.querySelectorAll('#ipArts .ip-card').forEach(function(c){c.style.display=(!q||(c.dataset.title+' '+c.dataset.authors).includes(q))?'':'none';});}
function ipCite(t){document.getElementById('ipCT').textContent=t;document.getElementById('ipModal').classList.add('open');}
function ipCC(){document.getElementById('ipModal').classList.remove('open');}
function ipCopy(){var t=document.getElementById('ipCT').textContent;navigator.clipboard&&navigator.clipboard.writeText(t).then(function(){var b=document.querySelector('#ipModal .ip-b-blue');b.innerHTML='<i class="fas fa-check"></i> Copied!';setTimeout(function(){b.innerHTML='<i class="fas fa-copy"></i> Copy';},2000);});}
document.querySelectorAll('.ip-toc-list a').forEach(function(a){a.addEventListener('click',function(e){var h=this.getAttribute('href');if(h&&h[0]==='#'){e.preventDefault();var el=document.querySelector(h);if(el)el.scrollIntoView({behavior:'smooth',block:'start'});}});});
</script>
<?php include __DIR__ . '/../include/footer.php'; ?>