/* 
Theme Name: IFHP Mosaic (Refactored)
Description: Consolidated, de-duplicated styles with preserved tile visuals and a dedicated responsive section.
Version: 1.1
Author: Custom Development (Refactor)
Text Domain: ifhp-mosaic
*/

/* ==========================================================================
   0) RESET & VARIABLES
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary-red: #e30613;        /* visual brand red */
  --accent-red:  #C70039;        /* legacy primary */
  --dark-900:    #000;
  --dark-800:    #1a1a1a;
  --dark-700:    #2c2c2c;
  --dark-600:    #555555;
  --mid-600:     #666;
  --mid-500:     #aaa;
  --mid-400:     #ccc;
  --light:       #fff;
  --shadow-strong: rgba(0,0,0,0.8);
  --shadow-mid:    rgba(0,0,0,0.6);
  --shadow-soft:   rgba(0,0,0,0.3);
  --shadow-ultra:  rgba(0,0,0,0.1);

  --font-sans: Arimo, Arial, sans-serif;
  --font-serif: 'Kaisei Decol', serif;
  --font-display: "Fraunces", serif;

  --container-max: 1200px;
  --gutter: 20px;

  /* header heights */
  --header-top-h: 50px;
  --header-main-h: 90px;
  --header-total-h: calc(var(--header-top-h) + var(--header-main-h));
}

/* ==========================================================================
   1) GLOBAL BASE
   ========================================================================== */

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  line-height: 1.4;
  background: var(--dark-900);
  color: var(--dark-800);
  min-height: 100vh;
  overflow-x: hidden;
  padding-top: var(--header-total-h); /* space for fixed header stack */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeSpeed;
}

/* media elements */
img { max-width: 100%; height: auto; vertical-align: middle; }
a { color: var(--primary-red); }
a:hover { text-decoration: none; }

/* Screen reader utility */
.screen-reader-text,
.sr-only,
.visually-hidden {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px) !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  border: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary-red);
  color: var(--light);
  padding: 8px 16px;
  text-decoration: none;
  font-weight: 700;
  border-radius: 0 0 4px 4px;
  z-index: 10000;
  transform: translateY(-100%);
  transition: transform .3s ease;
}
.skip-link:focus { transform: translateY(0); outline: none; }

/* Focus outlines */
:focus {
  outline: 3px solid var(--primary-red);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   2) SITE HEADER (Top bar + main header) & NAV
   ========================================================================== */

.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1000;
  width: 100%;
  background: transparent;
}

/* Top bar */
.header-top {
  background: linear-gradient(to bottom, #fff 0%, #ccc 90%);
  border-bottom: 5px solid var(--primary-red);
  padding: .5rem 2rem;
  font-size: 11pt;
  text-transform: uppercase;
  position: relative;
  z-index: 1001;
}
.header-top-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: .5rem;
}
.brand-name { font-weight: 700; }
.tagline { font-style: italic; text-transform: none; }

/* Main header */
.header-main {
  background: linear-gradient(to bottom, var(--dark-600) 0%, var(--dark-700) 100%);
  height: var(--header-main-h);
  display: flex;
  justify-content: center;
  align-items: center;
}
.header-main-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem 0 .5rem;
}

/* Logo block */
.logo-section { display: flex; align-items: center; gap: 0; }
.logo-section img { height: 111px; width: auto; }
.institute-text {
  font-family: var(--font-serif);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--light);
  text-shadow: 1px 1px 2px rgba(0,0,0,.7);
}
.institute-line-1, .institute-line-2 {
  display: block; letter-spacing: 1px; padding-bottom: 2px; border-bottom: 2px solid #ccc;
}
.institute-line-1 { font-size: 15px; box-shadow: 0 1px 0 rgba(255,255,255,.3); }
.institute-line-2 { font-size: 18px; box-shadow: inset 0 1px 0 rgba(255,255,255,.3); }

/* Header navigation (tabs) */
.header-nav {
  background: linear-gradient(to bottom, #2c2c2c 0%, #1a1a1a 100%);
  border-bottom: 1px solid #444;
}
.nav-tabs {
  display: flex; list-style: none; margin: 0; padding: 0 4rem; max-width: 100%; overflow-x: auto;
}
.nav-tabs li { white-space: nowrap; }
.nav-tabs a {
  display: block; padding: 1rem 1.5rem; color: #ccc; text-decoration: none;
  font-size: .9rem; font-weight: 500; text-transform: uppercase; letter-spacing: .5px;
  transition: all .3s ease; border-bottom: 3px solid transparent;
}
.nav-tabs a:hover,
.nav-tabs .current-menu-item a {
  color: #fff; background: rgba(255,255,255,.1); border-bottom-color: var(--primary-red);
}

/* Mobile menu overlay */
.mobile-menu-overlay {
  position: fixed; inset: 0; height: 100vh;
  background: rgba(0,0,0,.9);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform .3s ease;
}
.mobile-menu-overlay.active { transform: translateX(0); }
.mobile-nav { width: 100%; padding: 2rem; margin-top: 150px; }
.mobile-nav-list { list-style: none; }
.mobile-nav-list li { margin-bottom: 1rem; border-bottom: 1px solid #333; }
.mobile-nav-list a {
  display: block; padding: 1rem 0; color: #fff; text-decoration: none; font-size: 1.2rem;
  text-transform: uppercase; letter-spacing: 1px; transition: color .3s ease;
}
.mobile-nav-list a:hover { color: var(--primary-red); }

/* Hamburger / toggles */
.hamburger { color: #fff; font-size: 1.25rem; cursor: pointer; font-weight: 300; padding: 1rem; border: 1px solid transparent;
  border-image: linear-gradient(to bottom, rgba(0,0,0,.15), rgba(255,255,255,.05), rgba(0,0,0,.15)) 1;
}
.menu-toggle, .sidebar-toggle {
  display: none; background: none; border: none; cursor: pointer; padding: 10px; width: 40px; height: 40px; position: relative;
}
.hamburger-lines, .sidebar-icon { display: flex; flex-direction: column; justify-content: space-between; width: 24px; height: 18px; }
.hamburger-lines .line, .sidebar-icon .sidebar-line {
  background: var(--dark-800); height: 3px; width: 100%; border-radius: 2px; transition: all .3s ease;
}
.menu-toggle[aria-expanded="true"] .line1 { transform: rotate(45deg) translate(6px, 6px); }
.menu-toggle[aria-expanded="true"] .line2 { opacity: 0; }
.menu-toggle[aria-expanded="true"] .line3 { transform: rotate(-45deg) translate(6px, -6px); }

/* ==========================================================================
   3) MAIN LAYOUT & CONTAINERS
   ========================================================================== */

.site-content { max-width: var(--container-max); margin: 0 auto; padding: 40px var(--gutter); }
.main-container { display: flex; gap: 40px; align-items: flex-start; }
.content-area { flex: 1; width: 66%; }
.sidebar { width: 25%; flex-shrink: 0; background-color: #f8f9fa; padding: 30px 25px; border-radius: 8px; }

/* Breadcrumbs */
.breadcrumbs { background: #f8f9fa; padding: 15px 0; border-bottom: 1px solid #e0e0e0; font-size: .9rem; }
.breadcrumb-container { max-width: var(--container-max); margin: 0 auto; padding: 0 var(--gutter); }
.breadcrumb-list { list-style: none; display: flex; align-items: center; gap: 8px; }
.breadcrumb-item { display: flex; align-items: center; }
.breadcrumb-item:not(:last-child)::after { content: "›"; color: var(--mid-600); margin-left: 8px; font-weight: 700; }
.breadcrumb-item a { color: var(--mid-600); text-decoration: none; transition: color .3s ease; }
.breadcrumb-item a:hover, .breadcrumb-item a:focus { color: var(--primary-red); text-decoration: underline; }
.breadcrumb-item.current { color: var(--dark-800); font-weight: 500; }

/* ==========================================================================
   4) POSTS GRID & TILES (Preserved visuals)
   ========================================================================== */

.posts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 40px;
}

/* tile card */
.grid-tile {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  transition: transform .3s cubic-bezier(.4,0,.2,1), box-shadow .3s cubic-bezier(.4,0,.2,1);
  min-height: 250px;
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
  grid-column: span 1;
  grid-row: span 1;
  border: 5px solid #000; /* preserve outlined feel */
}
.grid-tile:hover {
  border-color: var(--primary-red);
  transform: translateY(-2px) translateZ(0);
  box-shadow: 0 8px 25px rgba(0,0,0,.2);
}

/* asymmetric pattern */
.grid-tile:nth-child(6n+1) { grid-row: span 2; min-height: 400px; }
.grid-tile:nth-child(6n+2),
.grid-tile:nth-child(6n+3),
.grid-tile:nth-child(6n+6) { min-height: 280px; }
.grid-tile:nth-child(6n+4) { grid-column: span 2; min-height: 300px; }
.grid-tile:nth-child(6n+5) { grid-row: span 2; min-height: 400px; }

/* image layer */
.tile-image { position: absolute; inset: 0; z-index: 1; }
.tile-image img { width: 100%; height: 100%; object-fit: cover; object-position: center; }

/* overlay for contrast */
.tile-overlay {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: flex-end;
  padding: 25px;
  background: linear-gradient(135deg, rgba(0,0,0,.3) 0%, rgba(0,0,0,.6) 100%);
  transition: background .3s cubic-bezier(.4,0,.2,1);
  will-change: background;
  transform: translateZ(0);
}
.grid-tile:hover .tile-overlay {
  background: linear-gradient(135deg, rgba(0,0,0,.2) 0%, rgba(0,0,0,.4) 100%);
}

/* content in overlay */
.tile-content { color: var(--light); text-shadow: 2px 2px 4px rgba(0,0,0,.8); }

.tile-title {
	font-family: 'Kaisei Decol', serif;
    font-size: clamp(1.5rem, 1.75rem + 0.625vw, 2.5rem); /* Scales from ~1.75rem mobile to 2.5rem desktop */
	text-align: left;
	font-weight: 700;
	line-height: 1;
	letter-spacing: -0.02em;
	display: inline-block;
	padding: 0.2em 0;

	word-break: break-word;
	font-weight: bold;
	color: #e30613;  /* your red */
	/* first a tight black outline, then a larger white outline */
	text-shadow:
		/* black stroke: 1px in all 8 directions */
		-1px  0    0 rgba(0,0,0,0.5),
		1px  0    0 rgba(0,0,0,0.5),
		0   -1px  0 rgba(0,0,0,0.5),
		0    1px  0 rgba(0,0,0,0.5),
		-1px -1px  0 rgba(0,0,0,0.5),
		-1px  1px  0 rgba(0,0,0,0.5),
		1px -1px  0 rgba(0,0,0,0.5),
		1px  1px  0 rgba(0,0,0,0.5),
		
		/* white stroke: 2px in all 8 directions */
		-2px  0    0 rgba(255,255,255,0.8),
		2px  0    0 rgba(255,255,255,0.8),
		0   -2px  0 rgba(255,255,255,0.8),
		0    2px  0 rgba(255,255,255,0.8),
		-2px -2px  0 rgba(255,255,255,0.8),
		-2px  2px  0 rgba(255,255,255,0.8),
		2px -2px  0 rgba(255,255,255,0.8),
		2px  2px  0 rgba(255,255,255,0.8),
		
		/* black stroke: 1px in all 8 directions */
		-1px  0    8px rgba(0,0,0,0.8),
		1px  0    8px rgba(0,0,0,0.8),
		0   -1px  8px rgba(0,0,0,0.8),
		0    1px  8px rgba(0,0,0,0.8),
		-1px -1px  8px rgba(0,0,0,0.8),
		-1px  1px  8px rgba(0,0,0,0.8),
		1px -1px  8px rgba(0,0,0,0.8),
		1px  1px  8px rgba(0,0,0,0.8);		
}
.grid-tile:hover .tile-title { text-decoration: underline; text-decoration-color: #fff; text-underline-offset: 8px; }

.tile-date {
  text-transform: uppercase;
  font-size: 9pt;
  letter-spacing: .3rem;
  display: block;
  color: #fff;
  text-shadow: -1px -1px 0 rgba(0,0,0,.92);
  margin: 0;
  text-align: left;
}

/* fallback for no thumbnail */
.grid-tile:not(.has-post-thumbnail) {
  background: linear-gradient(135deg, var(--mid-600) 0%, var(--dark-700) 100%);
}
.grid-tile:not(.has-post-thumbnail) .tile-overlay {
  background: linear-gradient(135deg, rgba(0,0,0,.2) 0%, rgba(0,0,0,.4) 100%);
}

/* ==========================================================================
   5) ARTICLE / CONTENT AREAS
   ========================================================================== */

.content-continued {
  position: relative; z-index: 5;
  background: #fff; color: var(--dark-800);
  padding: 4rem 5rem;
  font-size: clamp(1.1rem, 1.4vw, 1.25rem);
  line-height: 1.6; font-weight: 300;
  border-bottom: 10px solid transparent;
  border-image: linear-gradient(to right, transparent, rgba(0,0,0,.2), transparent) 1;
}
.content-continued a { color: var(--primary-red); }
.content-continued ul { list-style: none; padding-left: 1.5em; }
.content-continued ul li::before { content: "»"; margin-right: .5em; }

.article-content { color: #fff; font-size: clamp(.95rem, 1.8vw, 1.15rem); line-height: 1.5; font-weight: 400; }
.article-content p {
  text-shadow: 1px 1px 1px #000;
  box-shadow: 1px 1px 50px rgba(0,0,0,.5);
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(5px);
  padding: .61rem;
  border-radius: 1.61rem;
}

/* ==========================================================================
   6) SIDEBAR & WIDGETS
   ========================================================================== */

.widget { margin-bottom: 30px; }
.widget:last-child { margin-bottom: 0; }
.widget-title {
  font-size: 1.3rem; font-weight: 700; color: var(--dark-800);
  margin: 0 0 20px 0; padding-bottom: 10px; border-bottom: 2px solid var(--primary-red);
}
.breaking-news-list { list-style: none; }
.breaking-news-item { margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid #e0e0e0; }
.breaking-news-item:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.breaking-news-link { display: block; text-decoration: none; color: var(--dark-800); transition: color .3s ease; }
.breaking-news-link:hover { color: var(--primary-red); }

.category-filter-list { list-style: none; }
.category-filter-item { margin-bottom: 8px; }
.category-filter-link {
  display: block; padding: 10px 15px; background: #fff; border: 1px solid #e0e0e0; border-radius: 5px;
  text-decoration: none; color: var(--dark-800); font-weight: 500; transition: all .3s ease; position: relative;
}
.category-filter-link:hover, .category-filter-link.active {
  background: var(--primary-red); color: #fff; border-color: var(--primary-red);
}
.category-filter-link .post-count {
  float: right; font-size: .8rem; opacity: .8; background: rgba(255,255,255,.2);
  padding: 2px 8px; border-radius: 10px; margin-left: 10px;
}

/* ==========================================================================
   7) FOOTER
   ========================================================================== */

.site-footer { background: var(--dark-800); color: #fff; padding: 40px 0 20px; margin-top: 60px; }
.footer-container { max-width: var(--container-max); margin: 0 auto; padding: 0 var(--gutter); }
.footer-content { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 20px; }
.copyright p { margin: 0; font-size: .9rem; color: #ccc; }
.social-links { display: flex; list-style: none; gap: 15px; margin: 0; padding: 0; }
.social-links a {
  display: flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  background: rgba(255,255,255,.1); border-radius: 50%; color: #fff; text-decoration: none; transition: all .3s ease;
}
.social-links a:hover { background: var(--primary-red); transform: translateY(-2px); box-shadow: 0 4px 10px rgba(199,0,57,.3); }

/* ==========================================================================
   8) UTILITIES & STATES
   ========================================================================== */

.tile-link, .load-more-btn, .social-links a { transform: translateZ(0); backface-visibility: hidden; }

.load-more-container { text-align: center; margin-top: 40px; }
.load-more-btn {
  background: var(--primary-red); color: #fff; border: none; padding: 15px 40px;
  font-size: 1rem; font-weight: 700; border-radius: 5px; cursor: pointer; transition: all .3s ease; min-width: 140px;
}
.load-more-btn:hover:not(:disabled) { background: #A30031; transform: translateY(-1px); box-shadow: 0 4px 15px rgba(199,0,57,.3); }
.load-more-btn:disabled { background: var(--mid-500); color: var(--mid-600); cursor: not-allowed; }

.loading .grid-tile { opacity: .7; pointer-events: none; }
.loading .load-more-btn { cursor: progress; }
.error .load-more-btn { background: #dc3545; border-color: #dc3545; }
.success .load-more-btn { background: #28a745; border-color: #28a745; }

/* High contrast support */
@media (prefers-contrast: high) {
  :root { --accent-red: #FF0040; }
  .tile-overlay { background: rgba(0,0,0,.8) !important; }
  .grid-tile:hover .tile-overlay { background: rgba(0,0,0,.6) !important; }
}

/* ==========================================================================
   9) RESPONSIVE & PRINT (All media queries consolidated)
   ========================================================================== */

/* --- ≥1280px down --- */
@media (max-width: 1280px) {
  .site-content { max-width: 1000px; }
  .main-container { gap: 30px; }
  .posts-grid { gap: 15px; }
}

/* --- ≥1024px down --- */
@media (max-width: 1024px) {
  .posts-grid { grid-template-columns: repeat(2, 1fr); }

  /* reset conflicting spans for 2 cols */
  .grid-tile:nth-child(6n+2),
  .grid-tile:nth-child(6n+5),
  .grid-tile:nth-child(6n+6) { grid-column: span 1; grid-row: span 1; min-height: 250px; }

  /* 2-col pattern to avoid gaps */
  .grid-tile:nth-child(8n+1) { grid-row: span 2; min-height: 350px; }
  .grid-tile:nth-child(8n+2) { min-height: 250px; }
  .grid-tile:nth-child(8n+3) { grid-column: span 2; min-height: 280px; }
  .grid-tile:nth-child(8n+4) { min-height: 300px; }
  .grid-tile:nth-child(8n+5) { min-height: 270px; }
  .grid-tile:nth-child(8n+6) { grid-row: span 2; min-height: 380px; }
  .grid-tile:nth-child(8n+7) { grid-column: span 2; min-height: 260px; }
  .grid-tile:nth-child(8n+8) { min-height: 290px; }
}

/* --- ≥768px down (tablet & mobile) --- */
@media (max-width: 768px) {
  /* header stack compaction */
  :root { --header-top-h: 40px; --header-main-h: 80px; --header-total-h: calc(var(--header-top-h) + var(--header-main-h)); }
  body { padding-top: var(--header-total-h); }

  .header-top { padding: .5rem 1rem; font-size: 10pt; }
  .brand-name, .tagline { font-size: 0.7rem; }
  .header-main-content { padding: 0; }
  .logo-section img { height: 50px; }
  .institute-line-1 { font-size: 10px; }
  .institute-line-2 { font-size: 13px; }

  .header-nav { display: none; }
  .mobile-menu-overlay { display: block; }
  .nav-tabs { padding: 0 2rem; }

  .menu-toggle, .sidebar-toggle { display: block; }

  /* layout */
  .site-content { padding: 30px 15px; }
  .main-container { flex-direction: column; gap: 20px; }
  .content-area, .sidebar { width: 100%; }
  .sidebar { display: none; position: fixed; top: var(--header-total-h); left: 0; right: 0; bottom: 0; z-index: 998;
             background: #fff; border-radius: 0; padding: 0; overflow-y: auto; box-shadow: 0 4px 20px rgba(0,0,0,.1);
             transform: translateX(-100%); transition: transform .3s ease; }
  .sidebar.sidebar-open { display: block; transform: translateX(0); }

  /* grid becomes 1-col */
  .posts-grid { grid-template-columns: 1fr; gap: 20px; }
  .grid-tile { grid-column: 1 !important; grid-row: 1 !important; min-height: 280px !important; will-change: auto; }
  .grid-tile:hover { transform: none; } /* mobile perf */

  /* breadcrumbs */
  .breadcrumbs { padding: 10px 0; }
  .breadcrumb-container { padding: 0 15px; }
  .breadcrumb-list { font-size: .8rem; flex-wrap: wrap; }

  /* content */
  .content-continued { padding: 2.5rem 1.25rem; }
  .tile-content { padding: 20px; }
  .tile-title { font-size: 1.2rem; }
}

/* --- ≥480px down (small phones) --- */
@media (max-width: 480px) {
  .tile-overlay { padding: 20px; }
  .tile-title { font-size: 1.1rem; }
  .tile-date { font-size: .85rem; }

  .footer-container { padding: 0 15px; }
  .social-links { gap: 10px; }
  .social-links a { width: 35px; height: 35px; }
}

/* --- High contrast tweaks --- */
@media (prefers-contrast: high) {
  .site-header { border-bottom-width: 3px; }
  .grid-tile { border-width: 2px; }
  .load-more-btn, .category-filter-link { border-width: 2px; }
}

/* --- Print --- */
@media print {
  .site-header, .sidebar, .load-more-container, .social-icons, .breadcrumbs { display: none !important; }
  .site-content { padding-top: 0 !important; }
  .grid-tile { break-inside: avoid; page-break-inside: avoid; }
  .tile-overlay { background: rgba(0,0,0,.1) !important; }
  .tile-title { color: #000 !important; text-shadow: none !important; }
}