/* ============================================================
   SHARED STYLESHEET — Data Center Grid Impact Report
   Theme: CEPT Chulalongkorn University (Clean Light)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* ---------- CSS Variables ---------- */
:root {
    --col-burgundy: #8A2432;
    --col-navy:     #003865;

    --col-bg:       #ffffff;
    --col-surface:  #f8f9fb;
    --col-card:     #ffffff;
    --col-border:   #e5e8ed;

    --col-accent:   #8A2432;   /* primary — burgundy */
    --col-accent2:  #003865;   /* secondary — navy */

    --col-text:     #2c3e50;
    --col-muted:    #6b7a8d;
    --col-heading:  #1a1f2e;

    --col-highlight: rgba(138, 36, 50, 0.07);
    --col-underline: rgba(138, 36, 50, 0.8);

    --sidebar-w:  280px;
    --tooltip-w:  360px;

    --font-body: 'Sarabun', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
    --transition: 0.22s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html { scroll-behavior: smooth; font-size: 16px; }

body {
    background: var(--col-bg);
    color: var(--col-text);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.9;
    display: flex;
    min-height: 100vh;
}

/* ---------- Layout ---------- */
#left-sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--col-bg);
    border-right: 1px solid var(--col-border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform var(--transition);
    overflow: hidden;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
}
#left-sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-w)));
}

#main-content {
    margin-left: var(--sidebar-w);
    margin-right: 0;
    flex: 1;
    min-width: 0;
    transition: margin var(--transition);
}
body.left-collapsed #main-content { margin-left: 0; }
body.right-open     #main-content { margin-right: var(--tooltip-w); }

/* ---------- Left Sidebar (Navy) ---------- */
#left-sidebar .sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--col-surface);
    border-bottom: 1px solid var(--col-border);
}
#left-sidebar .sidebar-header h2 {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--col-navy);
}
#left-sidebar .sidebar-header .icon-btn {
    color: var(--col-muted);
}
#left-sidebar .sidebar-header .icon-btn:hover {
    color: var(--col-accent);
}
#left-sidebar .sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0 80px;
    scrollbar-width: thin;
    scrollbar-color: var(--col-border) transparent;
}
#left-sidebar .sidebar-nav::-webkit-scrollbar { width: 3px; }
#left-sidebar .sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--col-border);
    border-radius: 2px;
}

.toc-chapter { margin-bottom: 1px; }
.toc-chapter > a {
    display: flex;
    align-items: center;
    padding: 9px 16px;
    font-size: 0.81rem;
    font-weight: 600;
    color: var(--col-text);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all var(--transition);
}
.toc-chapter > a:hover,
.toc-chapter > a.active {
    color: var(--col-accent);
    border-left-color: var(--col-accent);
    background: var(--col-surface);
}
.toc-section { padding-left: 10px; display: none; }
.toc-chapter.open > .toc-section { display: block; }
.toc-section a {
    display: block;
    padding: 4px 16px;
    font-size: 0.77rem;
    color: var(--col-muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all var(--transition);
}
.toc-section a:hover { color: var(--col-text); }
.toc-section a.active {
    color: var(--col-accent);
    border-left-color: var(--col-accent);
    background: var(--col-highlight);
}
.toc-chapter > a .arrow {
    margin-left: auto;
    transition: transform var(--transition);
    font-style: normal;
}
.toc-chapter.open > a .arrow { transform: rotate(90deg); }

/* ---------- Toggle Buttons ---------- */
.sidebar-toggle {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 52px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    font-size: 0.65rem;
    border: none;
    transition: background var(--transition);
}
#toggle-left {
    left: var(--sidebar-w);
    background: #fff;
    color: var(--col-muted);
    border: 1px solid var(--col-border);
    border-left: none;
    border-radius: 0 5px 5px 0;
    box-shadow: 2px 1px 6px rgba(0,0,0,0.08);
    transition: left var(--transition), background var(--transition);
}
#toggle-left:hover { background: var(--col-accent); color: #fff; border-color: var(--col-accent); }
body.left-collapsed #toggle-left { left: 0; }

#toggle-right {
    right: 0;
    background: #fff;
    color: var(--col-muted);
    border: 1px solid var(--col-border);
    border-right: none;
    border-radius: 5px 0 0 5px;
    box-shadow: -1px 0 6px rgba(0,0,0,0.08);
}
#toggle-right:hover { background: var(--col-burgundy); color: #fff; border-color: var(--col-burgundy); }
body.right-open #toggle-right { right: var(--tooltip-w); transition: right var(--transition); }

/* ---------- Right Sidebar ---------- */
#right-sidebar {
    position: fixed;
    top: 0; right: 0;
    width: var(--tooltip-w);
    height: 100vh;
    background: var(--col-surface);
    border-left: 1px solid var(--col-border);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(var(--tooltip-w));
    transition: transform var(--transition);
    overflow: hidden;
    box-shadow: -3px 0 16px rgba(0,0,0,0.05);
}
#right-sidebar.open { transform: translateX(0); }

#right-sidebar .rs-header {
    padding: 13px 16px;
    background: var(--col-bg);
    border-bottom: 1px solid var(--col-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
#right-sidebar .rs-header h3 {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--col-navy);
}
#right-sidebar .rs-header .icon-btn { color: var(--col-muted); }
#right-sidebar .rs-header .icon-btn:hover { color: var(--col-accent); background: var(--col-highlight); }

#right-sidebar .rs-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--col-border) transparent;
    background: var(--col-surface);
}
#right-sidebar .rs-body::-webkit-scrollbar { width: 3px; }
#right-sidebar .rs-body::-webkit-scrollbar-thumb { background: var(--col-border); border-radius: 2px; }

#rs-placeholder {
    color: var(--col-muted);
    font-size: 0.82rem;
    text-align: center;
    margin-top: 60px;
    line-height: 1.8;
}

.cite-entry {
    margin-bottom: 20px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--col-border);
}
.cite-entry:last-child { border-bottom: none; }
.cite-entry .cite-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--col-accent2);
    margin-bottom: 6px;
}
.cite-entry .cite-ref-text {
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--col-text);
    background: #fff;
    padding: 10px 12px;
    border-radius: 4px;
    border-left: 3px solid var(--col-accent);
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.cite-entry .cite-verify {
    font-size: 0.78rem;
    color: #276749;
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 6px;
}
.cite-entry .cite-verify::before { content: '✓'; flex-shrink: 0; font-weight: 700; }
.cite-entry .cite-filename {
    font-size: 0.73rem;
    color: var(--col-muted);
    font-family: var(--font-mono);
    margin-bottom: 6px;
}
.cite-entry .cite-bib {
    font-size: 0.75rem;
    color: var(--col-muted);
    line-height: 1.6;
}

/* ---------- Main Content ---------- */
.page-wrapper {
    max-width: 860px;
    margin: 0 auto;
    padding: 56px 48px 120px;
}

/* Chapter Header */
.chapter-header {
    margin-bottom: 44px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--col-border);
}
.chapter-eyebrow {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--col-accent);
    margin-bottom: 10px;
}
.chapter-header h1 {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--col-heading);
    line-height: 1.3;
    margin-bottom: 14px;
}
.chapter-abstract {
    font-size: 0.92rem;
    color: var(--col-muted);
    border-left: 3px solid var(--col-accent);
    padding: 10px 16px;
    background: #fdf6f7;
    border-radius: 0 4px 4px 0;
    line-height: 1.75;
}

/*
 * H2 — CEPT style: heading + short burgundy bar below
 */
h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--col-heading);
    margin: 48px 0 6px;
    padding-bottom: 0;
    border-bottom: none;
    position: relative;
}
h2::after {
    content: '';
    display: block;
    width: 56px;
    height: 3px;
    background: var(--col-burgundy);
    border-radius: 2px;
    margin-top: 8px;
    margin-bottom: 16px;
}

h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--col-navy);
    margin: 28px 0 10px;
}
h4 {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--col-accent);
    margin: 20px 0 8px;
}
h5 {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--col-muted);
    margin: 16px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

p {
    margin-bottom: 1.1em;
    text-align: justify;
    font-size: 0.97rem;
}
p + p { text-indent: 1.5em; }

/* In-text citation */
a.cite-link {
    color: var(--col-accent);
    text-decoration: none;
    font-size: 0.78em;
    vertical-align: super;
    font-weight: 700;
    cursor: pointer;
    padding: 0 1px;
    transition: all var(--transition);
}
a.cite-link:hover {
    background: var(--col-highlight);
    border-radius: 2px;
    color: var(--col-accent);
}

/* Sentence highlight */
.written-sentence {
    transition: all 0.18s ease;
    border-radius: 2px;
}
.written-sentence.highlight {
    text-decoration: underline;
    text-decoration-color: var(--col-underline);
    text-underline-offset: 3px;
    text-decoration-thickness: 2px;
    background: rgba(138, 36, 50, 0.05);
}

/* Figures */
figure { margin: 28px 0; }
figure img {
    width: 100%;
    border-radius: 6px;
    border: 1px solid var(--col-border);
}
figcaption {
    font-size: 0.8rem;
    color: var(--col-muted);
    margin-top: 6px;
    text-align: center;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 0.85rem;
}
.data-table th {
    background: var(--col-navy);
    color: #fff;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
}
.data-table th:first-child { border-radius: 6px 0 0 0; }
.data-table th:last-child  { border-radius: 0 6px 0 0; }
.data-table td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--col-border);
    color: var(--col-text);
}
.data-table tr:hover td { background: var(--col-highlight); }
.table-caption { font-size: 0.8rem; color: var(--col-muted); margin-bottom: 6px; }

/* Info box */
.info-box {
    background: #fdf6f7;
    border: 1px solid #e8c5ca;
    border-left: 4px solid var(--col-accent);
    border-radius: 6px;
    padding: 14px 18px;
    margin: 20px 0;
    font-size: 0.9rem;
}
.info-box .info-title {
    font-weight: 700;
    color: var(--col-accent);
    margin-bottom: 4px;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Formula */
.formula-block {
    background: var(--col-navy);
    border-radius: 6px;
    padding: 16px 20px;
    margin: 18px 0;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: #f0c060;
    text-align: center;
}
.formula-label {
    font-size: 0.74rem;
    color: var(--col-muted);
    margin-top: 4px;
    text-align: right;
}

/* Metric cards */
.metric-row {
    display: flex;
    gap: 14px;
    margin: 22px 0;
    flex-wrap: wrap;
}
.metric-card {
    flex: 1;
    min-width: 130px;
    background: #fff;
    border: 1px solid var(--col-border);
    border-top: 3px solid var(--col-accent);
    border-radius: 6px;
    padding: 14px 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    transition: box-shadow var(--transition), transform var(--transition);
}
.metric-card:hover {
    box-shadow: 0 4px 14px rgba(138, 36, 50, 0.1);
    transform: translateY(-2px);
}
.metric-card .metric-val {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--col-accent);
    font-family: var(--font-mono);
}
.metric-card .metric-lbl {
    font-size: 0.75rem;
    color: var(--col-muted);
    margin-top: 3px;
    line-height: 1.4;
}

/* ---------- Footer Nav ---------- */
#footer-nav {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-w);
    right: 0;
    background: var(--col-navy);
    padding: 11px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 150;
    transition: left var(--transition), right var(--transition);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.12);
}
body.left-collapsed #footer-nav { left: 0; }
body.right-open     #footer-nav { right: var(--tooltip-w); }

.nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 18px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 4px;
    color: rgba(255,255,255,0.88);
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.nav-btn:hover { background: var(--col-burgundy); color: #fff; border-color: var(--col-burgundy); }
.nav-btn.disabled { opacity: 0.3; pointer-events: none; }
.nav-center {
    font-size: 0.77rem;
    color: rgba(255,255,255,0.55);
    letter-spacing: 0.04em;
}

/* ---------- Icon buttons ---------- */
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--col-muted);
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { color: var(--col-text); background: var(--col-highlight); }

/* ---------- Print ---------- */
@media print {
    #left-sidebar, #right-sidebar, #footer-nav, .sidebar-toggle { display: none !important; }
    #main-content { margin: 0 !important; }
    body { background: white; color: black; }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--col-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--col-accent); }

/* ---------- Figure placeholder ---------- */
.fig-placeholder { margin: 28px 0; }
.fig-ph-box {
    background: var(--col-surface);
    border: 2px dashed var(--col-border);
    border-radius: 6px;
    padding: 36px 24px;
    text-align: center;
    font-size: 0.86rem;
    color: var(--col-muted);
}

/* ---------- Index page: TOC cards ---------- */
.toc-card {
    background: #fff !important;
    border: 1px solid var(--col-border) !important;
    border-radius: 8px !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05) !important;
    transition: all 0.2s ease !important;
}
.toc-card:hover {
    border-color: var(--col-accent) !important;
    box-shadow: 0 4px 16px rgba(138, 36, 50, 0.1) !important;
    transform: translateX(4px) !important;
    background: #fdf6f7 !important;
}
.toc-card .num { color: #d1d9e0 !important; }
.toc-card:hover .num { color: var(--col-accent) !important; }
.toc-card .info .label { color: var(--col-accent) !important; }
.toc-card .info .title { color: var(--col-heading) !important; }
.toc-card .info .desc  { color: var(--col-muted) !important; }
.toc-card .pages       { color: var(--col-muted) !important; }

/* ---------- Index hero ---------- */
.index-hero { text-align: center; padding: 44px 0 36px; }
.index-hero .org {
    font-size: 0.8rem;
    color: var(--col-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 14px;
}
.index-hero h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--col-heading);
    line-height: 1.4;
    margin-bottom: 8px;
}
/* Override h2::after for index hero h1 */
.index-hero h1::after { display: none; }

.index-hero .subtitle {
    font-size: 0.95rem;
    color: var(--col-muted);
    margin-bottom: 22px;
}
.index-hero .meta-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 18px;
}
.index-hero .meta-item {
    font-size: 0.78rem;
    color: var(--col-muted);
    background: var(--col-surface);
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--col-border);
}

.section-divider {
    margin: 32px 0 16px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--col-muted);
    border-bottom: 1px solid var(--col-border);
    padding-bottom: 8px;
}

/* ---------- Missing citation warning ---------- */
a.cite-link.cite-missing {
    color: #b7791f;
    border-bottom: 1px dashed #b7791f;
}
a.cite-link.cite-missing::after {
    content: '⚠';
    font-size: 0.65em;
    margin-left: 1px;
}