/* ============================================================
   CV STYLES
   Order: base → language bar → page → sections → Khmer font →
          mobile/tablet → design refresh → SafeChamnun card → print
   (Each block is labelled; search for the section name to edit it.)
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
:root {
  --blue:     #1a5fa8;
  --blue-mid: #2171c7;
  --text:     #1a1a1a;
  --muted: #ffffff;
  --divider:  #d0d0d0;
  --body-font: 'Nunito Sans', sans-serif;
  --km-font:   'Battambang', serif;
}
body {
  background: #d5d5d5;
  font-family: var(--body-font);
  color: var(--text);
  font-size: 12px;
  line-height: 1.6;
}

/* Khmer Name Font */
body.lang-km #cv-name{ font-family:'Moulpali', cursive; letter-spacing:0; font-size:22px; }

/* ── LANGUAGE BAR ── */
#lang-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 999;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 8px 24px;
  background: var(--blue);
}
#lang-bar button {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,0.55);
  color: #fff;
  padding: 4px 14px;
  font-family: var(--body-font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.18s;
}
#lang-bar button:hover,
#lang-bar button.active { background: #fff; color: var(--blue); border-color: #fff; }

/* ── PAGE ── */
.page {
  max-width: 860px;
  margin: 56px auto 48px;
  background: #fff;
  box-shadow: 0 4px 28px rgba(0,0,0,0.18);
  padding: 44px 52px 56px;
}
@media (max-width: 660px) {
  .page { padding: 28px 16px 44px; margin-top: 52px; }
}

/* ── HEADER ── */
.cv-header { text-align: center; }
.cv-photo { width: 187px; height: 240px; border-radius: 0%; object-fit: cover; object-position: top center; display: block; margin: 0 auto 14px; }
.cv-photo-fallback { width: 120px; height: 120px; border-radius: 50%; background: #c5d8ee; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; font-size: 42px; color: var(--blue); }
.cv-name  { font-size: 24px; font-weight: 700; letter-spacing: 0.03em; }
.cv-label { font-size: 12px; font-weight: 400; letter-spacing: 0.18em; text-transform: uppercase; color: #444; margin-top: 2px; }

/* ── INFO BAR ── */
.info-bar { display: grid; grid-template-columns: 1fr 1px 1fr 1px 1fr; margin: 20px 0 0; padding: 16px 0; text-align: center; }
.info-col { display:flex;flex-direction:column; align-items:center; min-width:160px; }
.info-sep { background: var(--divider); }
.info-lbl { font-size: 12px; font-weight: 700; color: var(--blue); text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 2px; }
.info-val { font-size: 13px; }

/* ── ORNAMENT DIVIDER ── */
.orn { display: flex; align-items: center; margin: 26px 0; }
.orn-line { flex: 1; height: 1px; background: var(--divider); }
.orn-icon { width: 30px; height: 30px; margin: 0 14px; flex-shrink: 0; }

/* ── SECTION TITLE ── */
.sec-title { font-size: 14.5px; font-weight: 700; color: var(--blue); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 20px; }

/* ── 3-COL GRID ── */
.g3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 0 12px; }
.g3 .col { }
.period { font-size: 12px; font-weight: 700; color: var(--blue); display: block; margin-bottom: 3px; }
.i-title { font-size: 13px; font-weight: 600; line-height: 1.4; margin-bottom: 1px; }
.i-sub   { font-size: 12.5px; color: var(--cream); }

/* ── R&D ── */
.rd-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:0 20px;}
.rd-title { font-size:13px; font-weight:700; color:var(--blue); margin-bottom:7px; }
.rd-body{ font-size:12px; color:var(--text); line-height:1.7; text-align:justify;}

/* ── POLICY ── */
.pe-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:0 20px; }

/* ── PUBLICATIONS ── */
.publications-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:24px; margin-top:12px; }
.pub-venue { font-size:13px; font-weight:700; color:var(--blue); margin-bottom:8px; line-height:1.4; }
.pub-entry { font-size:12px; line-height:1.55; color:var(--text); padding-left:14px; position:relative; text-align:justify; }
.pub-entry::before{ content:'•'; position:absolute; left:0; top:0; color:var(--blue); }
.pub-entry a { color:var(--blue-mid); text-decoration:none; word-break:break-word; }

/* ── AWARDS TABLE ── */
.awards-table {width: 100%;border-collapse: collapse;}
.awards-table tbody {display: flex;flex-direction: column-reverse;}
.awards-table tr {display: table;width: 100%;table-layout: fixed;border-bottom: 1px solid #f0f0f0;}
.awards-table tr:first-child {border-bottom: none;}
.awards-table td {padding: 6px 4px;font-size: 12.5px;vertical-align: middle;}
.td-name {width: 38%;text-align: left;}
.td-org {width: 41%;text-align: left;color: var(--cream);}
.td-date {width: 21%;text-align: right;white-space: nowrap;}

/* ── REFEREES ── */
.ref-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:0 16px; }
.ref-deg{ font-size:13px; color:var(--cream); }
.ref-name{ font-size:14px; font-weight:700; color:var(--blue); margin-bottom:3px; }
.ref-role{ font-size:12px; line-height:1.5; margin-bottom:5px; color:var(--text); }
.ref-email{ font-size:12px; color:var(--blue-mid); text-decoration:none; display:block; }
.ref-email:hover{ text-decoration:underline; }
.ref-phone{ font-size:12px; color:var(--text); }

/* ── CONTACT ── */
.contact-center{text-align:center;margin-top:12px;}
.contact-line{font-size:12px;line-height:1.8;color:var(--text);}
.contact-line a{color:var(--blue-mid);text-decoration:none;}

#sec-contact{text-align:center;}
.contact-line a{ color:var(--blue-mid); text-decoration:none; }
.contact-line a:hover{ text-decoration:underline; }

/* ── KHMER FONT ── */
body.lang-km .sec-title, body.lang-km .i-title,
body.lang-km .i-sub, body.lang-km .rd-title,
body.lang-km .rd-body, body.lang-km .pub-venue,
body.lang-km .pub-entry, body.lang-km .awards-table td,
body.lang-km .ref-deg, body.lang-km .ref-name,
body.lang-km .ref-role, body.lang-km .info-lbl,
body.lang-km .info-val, body.lang-km .cv-label,
body.lang-km .period, body.lang-km .contact-line,
body.lang-km .contact-line a { font-family:var(--km-font); }

@media (max-width: 660px) {
  .g3, .rd-grid, .ref-grid { grid-template-columns: 1fr; }
  .info-bar { grid-template-columns: 1fr; }
  .info-sep { display: none; }
  .pe-grid { grid-template-columns:1fr; }
  .g3 .col { margin-bottom: 14px; }
}

/* ═══════════════════════════════════════════════════════════
   DESIGN REFRESH — mobile-first polish (appended; content untouched)
   ═══════════════════════════════════════════════════════════ */
:root{
  --blue-soft:#e8f1fb;
  --blue-line:#d6e4f4;
  --card:#f7fafd;
  --sub:#555b63;
  --grad:linear-gradient(90deg,#1a5fa8,#3b8be0);
  --bar-h:56px;
  --safe-b:env(safe-area-inset-bottom,0px);
}
html{-webkit-text-size-adjust:100%;scroll-padding-top:calc(var(--bar-h) + 8px)}
body{
  background:linear-gradient(180deg,#e3eaf2 0%,#d3dce7 100%);
  background-attachment:fixed;
  -webkit-font-smoothing:antialiased;-webkit-tap-highlight-color:transparent;
}
body.lang-km{line-height:1.85}
a,button{-webkit-tap-highlight-color:transparent}
:focus-visible{outline:2px solid var(--blue-mid);outline-offset:2px;border-radius:3px}

/* undefined vars in the original (--cream) → give subtitles a real grey */
.i-sub,.td-org,.ref-deg{color:var(--sub)}

/* LANGUAGE BAR */
#lang-bar{
  height:var(--bar-h);padding:0 max(24px,env(safe-area-inset-right)) 0 max(24px,env(safe-area-inset-left));
  background:linear-gradient(90deg,#17518f,#1a5fa8);box-shadow:0 2px 12px rgba(0,0,0,.2);
}
#lang-bar button{min-height:36px;min-width:52px;border-radius:999px;padding:0 16px}

/* PAGE */
.page{
  margin:calc(var(--bar-h) + 20px) auto 48px;
  border-radius:10px;border-top:4px solid var(--blue);
  box-shadow:0 12px 40px rgba(13,40,80,.16);
}

/* HEADER */
.cv-photo{border-radius:8px;box-shadow:0 8px 24px rgba(13,40,80,.2);border:3px solid #fff;outline:1px solid var(--blue-line);margin-bottom:18px}
.cv-name{font-size:30px;letter-spacing:.02em;line-height:1.2}
.cv-label{margin-top:6px;color:var(--blue);font-weight:600}
.info-bar{background:var(--card);border:1px solid var(--blue-line);border-radius:12px;padding:16px 8px;margin-top:24px}
.info-col{min-width:0;padding:0 8px}
.info-sep{background:var(--blue-line)}
.info-val{font-weight:600}

/* DIVIDERS */
.orn{margin:30px 0}

/* SECTION TITLES */
.sec-title{position:relative;padding-bottom:12px;margin-bottom:22px}
.sec-title::after{content:'';display:block;position:absolute;left:0;bottom:0;width:44px;height:3px;border-radius:3px;background:var(--grad)}
#sec-contact::after{left:50%;transform:translateX(-50%)}

/* CARDS (education / work / R&D / policy / publications / referees) */
.g3 .col,.rd-col,.publications-grid>div,.referee{
  background:var(--card);border:1px solid var(--blue-line);border-radius:10px;padding:14px 16px;min-width:0;
}
.g3{gap:12px}
.rd-grid,.pe-grid{gap:12px}
.publications-grid{gap:12px}
.ref-grid{gap:12px}
.period{display:inline-block;background:var(--blue-soft);padding:2px 10px;border-radius:999px;margin-bottom:8px}
.i-title{margin-bottom:3px}
.rd-body,.pub-entry{overflow-wrap:anywhere}
.pub-venue{margin-bottom:10px}
.pub-entry a{display:inline-block;margin-top:4px}
.ref-email{overflow-wrap:anywhere;margin-top:2px}

/* AWARDS */
.awards-table tr{transition:background .2s}
.awards-table tr:hover{background:#f4f8fc}
.awards-table td{overflow-wrap:anywhere}

/* CONTACT */
.contact-line{overflow-wrap:anywhere}
.contact-line a{font-weight:600}

/* Tablet: 3-col grids get tight under ~900px */
@media (max-width:900px){
  .page{margin-left:16px;margin-right:16px;padding:36px 30px 48px}
  .rd-grid,.publications-grid{grid-template-columns:repeat(2,1fr)}
  .ref-grid{grid-template-columns:repeat(2,1fr)}
}

/* ─── PHONE ─── */
@media (max-width:660px){
  :root{--bar-h:60px}
  body{font-size:15px;background:#fff}

  #lang-bar{justify-content:center;gap:10px;padding:0 12px}
  #lang-bar button{flex:1;max-width:120px;min-height:42px;font-size:14px}

  /* edge-to-edge page, no floating card */
  .page{
    margin:var(--bar-h) 0 0;padding:26px max(18px,env(safe-area-inset-left)) calc(44px + var(--safe-b)) max(18px,env(safe-area-inset-right));
    border-radius:0;border-top:none;box-shadow:none;max-width:none;
  }

  .cv-photo{width:150px;height:192px}
  .cv-name{font-size:28px}
  .cv-label{font-size:12px;letter-spacing:.16em}
  body.lang-km #cv-name{font-size:24px}

  /* info bar → compact label/value rows */
  .info-bar{grid-template-columns:1fr;padding:4px 14px;margin-top:20px;text-align:left}
  .info-col{flex-direction:row;justify-content:space-between;align-items:baseline;gap:16px;padding:12px 0;border-bottom:1px solid var(--blue-line);text-align:left}
  .info-col:last-of-type{border-bottom:none}
  .info-lbl{margin:0;font-size:12px;flex-shrink:0}
  .info-val{font-size:15px;text-align:right}

  .orn{margin:26px 0}
  .orn-icon{width:26px;height:26px;margin:0 12px}

  .sec-title{font-size:15px;margin-bottom:18px}

  /* single column cards */
  .g3,.rd-grid,.pe-grid,.publications-grid,.ref-grid{grid-template-columns:1fr;gap:12px}
  .g3 .col{margin-bottom:0}
  .g3 .col,.rd-col,.publications-grid>div,.referee{padding:16px}
  .period{font-size:13px}
  .i-title{font-size:16px;line-height:1.4}
  .i-sub{font-size:14.5px}
  .rd-title{font-size:15px}
  .rd-body{font-size:14.5px;line-height:1.7;text-align:left}
  .pub-venue{font-size:14.5px}
  .pub-entry{font-size:14px;line-height:1.65;text-align:left}
  .pub-entry a{font-size:13.5px;padding:4px 0}

  /* AWARDS: table → timeline cards */
  .awards-table{display:block}
  .awards-table tbody{padding-left:16px;margin-left:6px;border-left:2px solid var(--blue-line)}
  .awards-table tr{
    display:grid;grid-template-columns:1fr;gap:3px;width:auto;
    position:relative;padding:14px 0;border-bottom:1px solid #eef2f7;
  }
  .awards-table tr:hover{background:transparent}
  .awards-table tr::before{
    content:'';position:absolute;left:-23px;top:20px;width:10px;height:10px;border-radius:50%;
    background:#fff;border:2px solid var(--blue);
  }
  .awards-table td{display:block;width:auto !important;padding:0;font-size:14.5px;text-align:left;white-space:normal}
  .td-date{order:-1;font-size:12.5px !important;font-weight:700;color:var(--blue);letter-spacing:.02em}
  .td-name{font-weight:600;font-size:15.5px !important;line-height:1.4}
  .td-org{font-size:14px !important}

  /* referees */
  .ref-deg{font-size:13.5px}
  .ref-name{font-size:16px}
  .ref-role{font-size:14px;line-height:1.55}
  .ref-phone{font-size:14.5px;padding:2px 0}
  .ref-email{font-size:14px;padding:4px 0}

  /* contact */
  .contact-center{margin-top:6px}
  .contact-line{font-size:15px;line-height:1.9}
  .contact-line a{display:inline;font-size:14.5px}

  body.lang-km .cv-label{letter-spacing:0}
  body.lang-km .sec-title{letter-spacing:0}
}

@media (max-width:360px){
  .cv-name{font-size:25px}
  .info-col{flex-direction:column;gap:2px;align-items:flex-start}
  .info-val{text-align:left}
}

/* PRINT — a CV often gets printed / saved as PDF */
@media print{
  #lang-bar{display:none}
  html,body{background:#fff !important}
  body{-webkit-print-color-adjust:exact;print-color-adjust:exact;font-size:11pt}
  .page{margin:0 !important;box-shadow:none;border-radius:0;max-width:none;padding:0 4mm}
  .g3 .col,.rd-col,.publications-grid>div,.referee,.awards-table tr,.info-bar{break-inside:avoid}
  .sec-title{break-after:avoid}
  .pub-entry a,.ref-email,.contact-line a{color:var(--blue-mid)}
}

/* ─── POLICY: featured case (SafeChamnun) ─── */
.pe-feature{
  grid-column:1/-1;
  background:linear-gradient(180deg,#f2f7fd 0%,var(--card) 100%);
  border-left:4px solid var(--blue);
  padding:20px 22px 22px;
}
.pe-tag{
  display:inline-block;background:var(--blue);color:#fff;
  font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;
  padding:4px 12px;border-radius:999px;margin-bottom:10px;
}
.pe-feature-title{font-size:17px;line-height:1.4;margin-bottom:10px}
.pe-focus{font-size:12.5px;line-height:1.6;color:var(--sub);margin-bottom:16px;padding-bottom:14px;border-bottom:1px solid var(--blue-line)}
.pe-lbl{font-size:11px;font-weight:700;color:var(--blue);text-transform:uppercase;letter-spacing:.07em;margin-bottom:4px}
.pe-focus .pe-lbl{display:inline;margin:0;margin-right:6px}
.pe-case-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px 24px}
.pe-block{min-width:0}
.pe-wide{grid-column:1/-1}
.pe-block .pe-body{text-align:left}
.pe-callout{
  margin-top:18px;padding:14px 16px;border-radius:8px;
  background:var(--blue-soft);border-left:3px solid var(--blue);
}
.pe-callout .pe-body{font-weight:600;text-align:left}
body.lang-km .pe-tag,body.lang-km .pe-lbl{font-family:var(--km-font);letter-spacing:0}
body.lang-km .pe-focus,body.lang-km .pe-callout{font-family:var(--km-font)}

@media (max-width:660px){
  .pe-feature{padding:18px 16px 18px}
  .pe-feature-title{font-size:17px}
  .pe-focus{font-size:14px}
  .pe-lbl{font-size:12px}
  .pe-case-grid{grid-template-columns:1fr;gap:16px}
  .pe-callout{padding:14px}
}
@media print{.pe-feature{break-inside:auto}.pe-block,.pe-callout{break-inside:avoid}}

/* ─── LOADER (modular version) ─── */
.page:not(.loaded){min-height:60vh}
body:not(.ready) .page{visibility:hidden}
.cv-error{background:#fff4f4;border:1px solid #f0c4c4;color:#8a1f1f;padding:14px 16px;border-radius:8px;font-size:14px;line-height:1.6;visibility:visible}

/* ═══════════════════════════════════════════════════════════
   DARK MODE (appended; light theme above is untouched)
   Switched by <html data-theme="dark"> — see the toggle in index.html
   ═══════════════════════════════════════════════════════════ */
/* toggle button lives in the language bar (both themes) */
#lang-bar #theme-toggle{flex:0 0 auto;min-width:44px;padding:0;font-size:17px;line-height:1;display:inline-flex;align-items:center;justify-content:center}
@media (max-width:660px){#lang-bar #theme-toggle{flex:0 0 46px;max-width:46px;min-width:46px;font-size:18px}}

/* screen only — printing / saving as PDF always stays light */
@media screen{
html[data-theme="dark"]{
  color-scheme:dark;
  --blue:#7ab8f0;
  --blue-mid:#8ec7f7;
  --text:#e6edf6;
  --divider:#2a3a50;
  --sub:#a3b1c4;
  --card:#152133;
  --blue-soft:#1d3552;
  --blue-line:#25384f;
  --grad:linear-gradient(90deg,#3b8be0,#7ab8f0);
}
html[data-theme="dark"] body{background:linear-gradient(180deg,#0a111b 0%,#0d1623 100%) fixed}

/* language bar */
html[data-theme="dark"] #lang-bar{background:linear-gradient(90deg,#0f2742,#12335a);box-shadow:0 2px 12px rgba(0,0,0,.55)}
html[data-theme="dark"] #lang-bar button:hover,
html[data-theme="dark"] #lang-bar button.active{background:#fff;color:#12335a;border-color:#fff}

/* page */
html[data-theme="dark"] .page{background:#101a28;border-top-color:#2a6fc0;box-shadow:0 12px 40px rgba(0,0,0,.55)}
html[data-theme="dark"] .cv-photo{border-color:#101a28;box-shadow:0 8px 24px rgba(0,0,0,.55)}
html[data-theme="dark"] .cv-photo-fallback{background:#223a5a}
html[data-theme="dark"] .orn-icon{filter:brightness(1.8)}

/* awards */
html[data-theme="dark"] .awards-table tr{border-bottom-color:var(--blue-line)}
html[data-theme="dark"] .awards-table tr:hover{background:var(--card)}
html[data-theme="dark"] .awards-table tr::before{background:#101a28}

/* policy: featured case */
html[data-theme="dark"] .pe-feature{background:linear-gradient(180deg,#182b44 0%,var(--card) 100%);border-left-color:#3b8be0}
html[data-theme="dark"] .pe-tag{background:#2a6fc0;color:#fff}

/* loader error box */
html[data-theme="dark"] .cv-error{background:#3a1a1d;border-color:#7a3a3f;color:#ffb4b4}
}
@media screen and (max-width:660px){
  html[data-theme="dark"] .awards-table tr:hover{background:transparent}
}
