/* Central responsive stylesheet for Library System
   Mobile-first utility + media queries. Loaded last to override inline styles.
*/
/* Reset/Box sizing */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale; }
img, picture, video, iframe { display:block; max-width:100%; height:auto; }
a { color: inherit; }
.container { width:100%; max-width:1200px; margin:0 auto; padding:0 15px; }
/* Utility helpers */
.u-hidden-mobile { display: none; }
.table-responsive { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.center { text-align:center; }
.flex { display:flex; }
.flex-column { display:flex; flex-direction:column; }
.row { display:flex; flex-wrap:wrap; gap:16px; }
.col { flex:1 1 0; }
/* Buttons and inputs adjustments */
button, input[type=button], input[type=submit], .btn { cursor:pointer; }
input, select, textarea { max-width:100%; }
/* Header / nav adjustments - professional, responsive header */
/* Professional header: three zones (left / center / right) */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  min-height: 70px;
  background: linear-gradient(90deg,#0066cc 0%, #00aa66 100%);
  color: #fff;
  font-family: Poppins, Roboto, "Segoe UI", Tahoma, sans-serif;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
}
.header-left { justify-content: flex-start; }
.header-center { justify-content: center; flex: 1; text-align: left; }
.header-right { justify-content: flex-end; gap: 12px; }

/* Logo */
.header .logo, .header-left img, .header .logo-img {
  display: block; max-height: 60px; height: auto; width: auto; margin-right: 12px;
}

/* Title */
.header .site-title { font-size: 1.35rem; font-weight: 700; color: #fff; line-height: 1; }
.header .site-subtitle { display:block; font-size: 0.95rem; color: rgba(255,255,255,0.9); font-weight:500; }

/* Right side: welcome & actions */
.header .welcome { font-size: 0.95rem; color: rgba(255,255,255,0.95); }
.header .logout-btn, .header .back-btn {
  background: rgba(255,255,255,0.12); color: #fff; padding: 8px 12px; border-radius: 8px; border: none; text-decoration: none; cursor: pointer;
}
.header .logout-btn:hover, .header .back-btn:hover { background: rgba(255,255,255,0.18); }

/* Navigation inside header (if present) */
.header nav { display:flex; gap:12px; align-items:center; z-index:60; }
.header nav a { color: #fff; text-decoration: none; padding: 8px 12px; border-radius:6px; transition: background .18s, transform .12s; }
.header nav a:hover { background: rgba(255,255,255,0.08); transform: translateY(-1px); }

/* Header size tuning */
@media (min-width: 1025px) { .header { min-height: 80px; } }

/* Small screens: stack into three rows */
@media (max-width: 768px) {
  .header { flex-direction: column; align-items: center; text-align: center; padding: 12px 14px; min-height: auto; }
  .header-left, .header-center, .header-right { width: 100%; justify-content: center; }
  .header-center { order: 2; margin-top: 6px; }
  .header-right { order: 3; margin-top: 10px; }
  .header-left { order: 1; margin-bottom: 4px; }
  .header-right { gap: 8px; }
  .header .site-title { font-size: 1.1rem; }
  .header .site-subtitle { font-size: 0.9rem; }
  .header nav { width: 100%; }
}

/* Hide header-nav on small screens (we'll use dropdown/menu toggle there) */
@media (max-width: 768px) {
  .header-nav { display: none !important; }
}

/* Desktop: show header-nav as button-like links */
@media (min-width: 769px) {
  .header-nav { display: flex; gap: 12px; align-items: center; }
  .header-right { gap: 16px; align-items: center; }

  /* Unified header action/button styles for desktop */
  .header-nav a,
  .header-right a,
  .header-right .link-btn,
  .header-right .logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #009949 60%, #0072BC 100%);
    color: #fff;
    text-decoration: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.98rem;
    letter-spacing: 0.2px;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 8px 22px rgba(2,36,71,0.08), inset 0 -2px 0 rgba(255,255,255,0.03);
    transition: transform .18s cubic-bezier(.2,.9,.2,1), box-shadow .18s, background .18s;
    will-change: transform;
    padding-left: 16px;
    padding-right: 16px;
  }

  .header-nav a:hover,
  .header-right a:hover,
  .header-right .link-btn:hover,
  .header-right .logout-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 14px 40px rgba(2,36,71,0.12);
    background: linear-gradient(135deg, #0072BC 60%, #009949 100%);
  }

  .header-nav a:focus,
  .header-right a:focus,
  .header-right .link-btn:focus,
  .header-right .logout-btn:focus {
    outline: 3px solid rgba(0,123,255,0.12);
    outline-offset: 3px;
  }

  .header-nav a:active,
  .header-right a:active,
  .header-right .link-btn:active,
  .header-right .logout-btn:active {
    transform: translateY(-1px) scale(.995);
    box-shadow: 0 6px 16px rgba(2,36,71,0.06);
  }

  /* Ensure welcome text aligns visually with buttons */
  .header .welcome { margin-right: 6px; font-weight: 600; color: rgba(255,255,255,0.95); }
}
/* Make tables friendly on small screens */
@media (max-width: 768px) {
  .u-hidden-mobile { display:none !important; }
  .header nav { display:none !important; }
  .container { padding:0 12px; }
  .nav-menu a, .nav-menu { width:100%; display:block; }
  /* make tables horizontally scrollable */
  table { width:100%; border-collapse:collapse; }
  .table-responsive table { min-width:700px; }
}
/* Small phones */
@media (max-width: 480px) {
  .header { padding:8px 12px !important; }
  .header .logo-text { font-size:1.05em !important; }
  .container { padding:0 10px; }
  .cards-grid, .docs-grid, .media-cards, .books-grid, .stats-grid { grid-template-columns: 1fr !important; }
  .left-panel, .right-panel { padding:16px !important; }
  .tabs { gap:6px; }
}
/* Medium screens */
@media (min-width: 769px) and (max-width: 1024px) {
  .container { max-width:960px; }
  .left-panel img, .header-left img { width:140px; }
}
/* Desktop improvements */
@media (min-width: 1025px) {
  .container { max-width:1200px; }
}
/* Small tweaks to override common inline spacings */
header, .header { width:100%; }
/* Ensure common components are responsive */
.pdf-viewer iframe, #pdf-iframe { width:100% !important; }
.video-player, video { width:100% !important; height:auto !important; }
.audio-player, audio { width:100% !important; }
/* Specific overrides for forms and cards */
.form-section, .form-card, .viewer-container, .content-wrapper, .content-section, .recent-section, .form-section, .book-detail-card { width:100%; box-sizing:border-box; }
/* Force word-wrap for long strings in narrow columns */
.break-word { word-break:break-word; overflow-wrap:break-word; }

/* Accessibility: increase tap targets on small screens */
@media (max-width: 480px) {
  a, button, .nav-menu a, .tab { padding:10px 12px !important; }
}

/* Stronger small-screen table handling: allow horizontal drag/scroll and prevent text overflow */
@media (max-width: 480px) {
  /* Allow any container with tables to scroll horizontally */
  .recent-section, .content-section, .table-wrapper, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Reset fixed/min widths so tables can shrink and be scrolled */
  .recent-section table, .content-section table, table { min-width: 0 !important; width: 100% !important; }

  /* Ensure table cells wrap long text instead of overflowing */
  th, td { white-space: normal !important; word-break: break-word !important; overflow-wrap: break-word !important; }

  /* Make table headers stick and readable when horizontally scrolled */
  .recent-section table thead, .content-section table thead { display: table-header-group; }
}

/* Extra-strong XS tweaks to prevent table overflow and overlap */
@media (max-width: 480px) {
  /* Convert table rows to stacked cards on small screens so all fields remain readable */
    /* apply when .recent-section has .stacked OR viewport is narrow */
    .recent-section.stacked table, .content-section.stacked table,
    @media (max-width: 600px) {
    }
    .recent-section.stacked table, .content-section.stacked table,
    .recent-section table, .content-section table {
      border: 0 !important;
    }
    .recent-section.stacked table thead, .recent-section table thead,
    .content-section.stacked table thead, .content-section table thead { display: none !important; }
    .recent-section.stacked table tbody tr, .recent-section table tbody tr,
    .content-section.stacked table tbody tr, .content-section table tbody tr {
      display: block !important;
      margin-bottom: 12px !important;
      background: #fff !important;
      padding: 10px !important;
      border-radius: 8px !important;
      box-shadow: 0 1px 6px rgba(0,0,0,0.04) !important;
    }
    .recent-section.stacked table tbody tr td, .recent-section table tbody tr td,
    .content-section.stacked table tbody tr td, .content-section table tbody tr td {
      display: flex !important;
      justify-content: space-between !important;
      align-items: center !important;
      padding: 8px 6px !important;
      border-bottom: none !important;
    }
    .recent-section.stacked table tbody tr td:before, .recent-section table tbody tr td:before,
    .content-section.stacked table tbody tr td:before, .content-section table tbody tr td:before {
      content: attr(data-title) "" !important;
      display: inline-block !important;
      font-weight: 700 !important;
      color: #4a5568 !important;
      margin-right: 8px !important;
      width: 40% !important;
      max-width: 45% !important;
    }
    .recent-section.stacked table tbody tr td > *, .recent-section table tbody tr td > *,
    .content-section.stacked table tbody tr td > *, .content-section table tbody tr td > * {
      width: 55% !important;
      max-width: 55% !important;
      text-align: right !important;
    }

  /* Reduce padding and font-size for tighter fit */
  .recent-section table th, .recent-section table td,
  .content-section table th, .content-section table td {
    padding: 8px 8px !important;
    font-size: 13px !important;
  }

  /* Ensure badges and inline elements wrap and scale down */
  .badge, .badge-pdf, .badge-audio, .badge-video { font-size: 12px !important; padding: 4px 8px !important; }

  /* If user still wants to scroll horizontally, enable touch-drag */
  .recent-section { -webkit-overflow-scrolling: touch; }
}

/* Header nav toggle (hamburger) */
.menu-toggle {
  display: none;
  background: transparent;
  border: 0;
  width: 44px;
  height: 40px;
  padding: 8px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: #fff;
  align-items: center;
  justify-content: center;
}
.menu-toggle .bar { display:block; width:22px; height:2px; background:#fff; margin:3px 0; border-radius:2px; transition: transform .25s ease, opacity .18s ease; }

@media (max-width: 768px) {
  .menu-toggle { display: inline-flex; align-items:center; justify-content:center; }
  .header nav { display: none !important; position: absolute; top:100%; left:0; right:0; background: linear-gradient(180deg, rgba(0,0,0,0.02), rgba(255,255,255,0.02)); padding:12px 16px; box-shadow: 0 8px 20px rgba(0,0,0,0.08); }
  .header.nav-open nav { display: block !important; }
  .header nav a { display:block; padding:10px 12px; }
  .header { position: relative; }
}

/* Animate hamburger -> X when open */
.header.nav-open .menu-toggle .bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.header.nav-open .menu-toggle .bar:nth-child(2) { opacity: 0; }
.header.nav-open .menu-toggle .bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.menu-toggle:focus { outline: 2px solid rgba(255,255,255,0.22); outline-offset: 2px; }

/* Ensure touch target and contrast for the toggle */
@media (max-width: 480px) {
  .menu-toggle { width:48px; height:44px; }
  .menu-toggle .bar { width:20px; }
}

/* Header stacking for small screens: logo/title/buttons stack cleanly */
@media (max-width: 600px) {
  .header { flex-direction: column; align-items: stretch; gap:8px; padding:10px; }
  .header .logo-text { font-size:1rem; }
  .header .logo, .header img { max-width:120px; margin:0 auto; }
  .header .header-actions { display:flex; gap:8px; justify-content:flex-end; }
  .header nav { position: static; width:100%; }
}

/* Nav-menu (sidebar / page-level menu) responsive collapse */
.nav-menu { display:flex; gap:10px; flex-wrap:wrap; }
.nav-menu a { display:inline-block; }

/* Toggle button for .nav-menu on small screens */
/* Fallback toggle styles for pages without a header (icon-only) */
.menu-toggle-fallback {
  display: none;
  background: transparent;
  border: 0;
  width: 44px;
  height: 40px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  color: #333;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .menu-toggle-fallback { display: inline-flex; align-items:center; justify-content:center; }
  .nav-menu { display:none; flex-direction:column; background:#fff; padding:10px; border-radius:8px; box-shadow:0 8px 20px rgba(0,0,0,0.08); }
  .nav-menu.nav-menu-open { display:flex !important; }
  .nav-menu a { padding:10px 8px; border-top:1px solid rgba(0,0,0,0.06); }
  .nav-menu a:first-child { border-top: none; }
}

/* When we move page .nav-menu into the header, style it like header nav on small screens */
.header .nav-menu.moved-into-header { display: none; position: absolute; top: 100%; left: 0; right: 0; padding: 12px 16px; background: #ffffff; box-shadow: 0 8px 30px rgba(0,0,0,0.12); border-top-left-radius: 8px; border-top-right-radius: 8px; z-index: 60; }
.header.nav-open .nav-menu.moved-into-header { display: flex !important; flex-direction: column; }
.header .nav-menu.moved-into-header a { color: #17202a; }
.header .nav-menu.moved-into-header a + a { border-top: 1px solid rgba(0,0,0,0.06); }

/* Make nav-menu links look like buttons and full-width on mobile */
.nav-menu a {
  background: linear-gradient(135deg,#009949 60%,#0072BC 100%) !important;
  color: #fff !important;
  padding: 10px 16px !important;
  border-radius: 8px !important;
  text-decoration: none !important;
  display: inline-block !important;
}

@media (max-width: 768px) {
  .nav-menu a { display: block !important; width: 100% !important; margin: 6px 0 !important; text-align: center !important; }
}

/* Make tables inside content sections horizontally scrollable on small screens */
.content-section { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.content-section table { min-width: 700px; }


/* Auto-converted overrides for fixed pixel widths to improve responsiveness */
/* These rules intentionally use !important to override inline page styles that set fixed pixel widths. */
.header-left img, .header img, .logo, .logo-img, .left-panel img {
  width: auto !important;
  max-width: 100% !important;
  height: auto !important;
}
.container {
  width: 100% !important;
  max-width: 1200px !important;
  padding: 0 15px !important;
}
.books-grid, .cards-grid, .stats-grid, .docs-grid, .media-cards {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
}
.table-responsive table {
  min-width: 0 !important;
}
img[width], img[height] {
  width: auto !important;
  height: auto !important;
  max-width: 100% !important;
}

@media (max-width: 768px) {
  .header-left img, .header img { max-width: 140px !important; }
  .container { padding: 0 12px !important; }
}

/* Stronger menu contrast and mobile panel styling */
.header nav a { color: #fff; }
.header nav a:hover { background: rgba(255,255,255,0.14); }
.header nav a:focus { outline: 2px solid rgba(255,255,255,0.22); }

/* When mobile nav is opened, show a high-contrast panel and dark text for links */
.header.nav-open nav {
  display: block !important;
  background: #ffffff; /* solid panel for contrast */
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}
.header.nav-open nav a { color: #17202a; }
.header.nav-open nav a:hover { background: rgba(0,0,0,0.06); }
.header.nav-open nav a + a { border-top: 1px solid rgba(0,0,0,0.06); }

@media (max-width: 768px) {
  /* ensure the hidden nav on mobile is readable when open */
  .header nav { position: absolute; top:100%; left:0; right:0; padding:12px 16px; }
  .header nav a { display:block; padding:10px 12px; }
}

