/**
 * Eldermoor Campaign Viewer Styles
 * Mobile-first responsive design
 */

/* === CSS Variables === */
:root {
  --primary-color: #2c5f2d;
  --primary-dark: #1a3a1b;
  --accent-color: #8b4513;
  --text-color: #333;
  --bg-color: #f5f5dc;
  --sidebar-bg: #fff;
  --border-color: #ccc;
  --link-color: #2c5f2d;
  --link-hover: #1a3a1b;
  --shadow: 0 2px 4px rgba(0,0,0,0.1);
  --header-height: 60px;
}

/* === Reset & Base Styles === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-color);
  background: var(--bg-color);
}

/* === Header === */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--primary-color);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  box-shadow: var(--shadow);
  z-index: 1000;
}

.site-header h1 {
  font-size: 1.2rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.username {
  font-size: 0.9rem;
}

/* Mobile menu toggle */
.mobile-menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mobile-menu-toggle span {
  display: block;
  width: 24px;
  height: 3px;
  background: white;
  transition: 0.3s;
}

/* === Breadcrumbs === */
.breadcrumbs {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  background: white;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  overflow-x: auto;
  z-index: 999;
}

.breadcrumbs a {
  color: var(--link-color);
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

.breadcrumbs .separator {
  margin: 0 0.5rem;
  color: #999;
}

/* === Container === */
.container {
  display: flex;
  margin-top: calc(var(--header-height) + 41px); /* header + breadcrumbs */
  min-height: calc(100vh - var(--header-height) - 41px);
}

/* === Sidebar === */
.sidebar {
  position: fixed;
  top: calc(var(--header-height) + 41px);
  left: -280px;
  width: 280px;
  height: calc(100vh - var(--header-height) - 41px);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  transition: left 0.3s ease;
  z-index: 998;
  box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

.sidebar.open {
  left: 0;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h2 {
  font-size: 1.1rem;
  color: var(--primary-color);
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: #999;
  line-height: 1;
}

/* === Navigation === */
.sidebar-nav ul {
  list-style: none;
  padding-left: 0;
}

.sidebar-nav > ul {
  padding: 0.5rem 0;
}

.sidebar-nav ul ul {
  padding-left: 1rem;
}

.sidebar-nav li {
  margin: 0.25rem 0;
}

.sidebar-nav a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text-color);
  text-decoration: none;
  transition: background 0.2s;
}

.sidebar-nav a:hover {
  background: rgba(44, 95, 45, 0.1);
}

.sidebar-nav li.active > a {
  background: var(--primary-color);
  color: white;
  font-weight: 600;
}

.sidebar-nav .folder-toggle {
  display: block;
  padding: 0.5rem 1rem;
  font-weight: 600;
  color: var(--primary-dark);
  cursor: pointer;
  user-select: none;
}

.sidebar-nav .folder-toggle:hover {
  background: rgba(44, 95, 45, 0.05);
}

.sidebar-nav .nav-folder.active > .folder-toggle {
  color: var(--primary-color);
}

/* === Main Content === */
.content {
  flex: 1;
  padding: 1.5rem 1rem;
  max-width: 100%;
}

/* === Markdown Content Styles === */
.markdown-content {
  max-width: 800px;
  margin: 0 auto;
}

.markdown-content h1 {
  font-size: 2rem;
  color: var(--primary-dark);
  margin: 1.5rem 0 1rem;
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 0.5rem;
}

.markdown-content h2 {
  font-size: 1.5rem;
  color: var(--primary-dark);
  margin: 1.5rem 0 0.75rem;
}

.markdown-content h3 {
  font-size: 1.25rem;
  color: var(--primary-color);
  margin: 1.25rem 0 0.5rem;
}

.markdown-content h4 {
  font-size: 1.1rem;
  margin: 1rem 0 0.5rem;
}

.markdown-content p {
  margin: 0.75rem 0;
}

.markdown-content a {
  color: var(--link-color);
  text-decoration: underline;
}

.markdown-content a:hover {
  color: var(--link-hover);
}

.markdown-content ul,
.markdown-content ol {
  margin: 0.75rem 0;
  padding-left: 2rem;
}

.markdown-content li {
  margin: 0.25rem 0;
}

.markdown-content code {
  background: #f0f0f0;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.markdown-content pre {
  background: #f5f5f5;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}

.markdown-content pre code {
  background: none;
  padding: 0;
}

.markdown-content blockquote {
  border-left: 4px solid var(--primary-color);
  padding-left: 1rem;
  margin: 1rem 0;
  color: #666;
  font-style: italic;
}

.markdown-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  overflow-x: auto;
  display: block;
}

.markdown-content th,
.markdown-content td {
  border: 1px solid var(--border-color);
  padding: 0.5rem;
  text-align: left;
}

.markdown-content th {
  background: var(--primary-color);
  color: white;
  font-weight: 600;
}

.markdown-content tr:nth-child(even) {
  background: #f9f9f9;
}

/* === Info Cards === */
.info-card {
  float: right;
  width: 300px;
  margin: 0 0 1rem 1.5rem;
  padding: 1rem;
  background: #f8f8f8;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.info-card-heading {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-color);
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.info-card-item {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.info-card-item:last-child {
  margin-bottom: 0;
}

.info-card-label {
  font-weight: 600;
  color: var(--primary-color);
  display: inline;
}

.info-card-value {
  color: var(--text-color);
  display: inline;
}

/* Clear floats after info cards */
.markdown-content h2,
.markdown-content h3,
.markdown-content hr {
  clear: both;
}

/* Mobile: stack info cards */
@media (max-width: 767px) {
  .info-card {
    float: none;
    width: 100%;
    margin: 1rem 0;
  }
}

/* === Session Report Metadata === */
.session-metadata {
  margin: 0 0 1.5rem 0;
  padding: 1rem;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-left: 4px solid var(--primary-color);
  border-radius: 4px;
  font-size: 0.95rem;
}

.metadata-item {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.metadata-item:last-child {
  margin-bottom: 0;
}

.metadata-label {
  font-weight: 600;
  color: var(--primary-color);
  min-width: 80px;
  display: inline-block;
}

.metadata-value {
  color: var(--text-color);
}

/* === Session Report Party Composition === */
.party-composition {
  margin: 0 0 2rem 0;
  padding: 0.5rem 1.25rem 1.25rem 1.25rem;
  background: linear-gradient(135deg, #f0f7ff 0%, #e3f2fd 100%);
  border-left: 4px solid var(--primary-color);
  border-radius: 4px;
}

.party-composition .party-heading {
  margin: 0.25rem 0 0.75rem 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary-color);
  color: var(--primary-color);
  font-size: 1.3rem;
}

.party-members {
  display: grid;
  gap: 0.5rem;
}

.party-member {
  padding: 0.25rem 0.75rem;
  line-height: 1.6;
  font-size: 0.95rem;
}

/* === D&D Stat Blocks === */
.stat-block {
  background: #FDF1DC;
  border: 2px solid #58180D;
  border-radius: 4px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  font-family: 'Libre Baskerville', 'Book Antiqua', Georgia, serif;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);
  max-width: 650px;
}

/* Creature type line (e.g., "Medium undead, neutral evil") */
.stat-block-type {
  color: #822000;
  font-style: italic;
  font-size: 0.95rem;
  margin: 0.5rem 0 1rem 0;
  border-bottom: 1px solid #58180D;
  padding-bottom: 0.5rem;
}

/* Stat block paragraphs */
.stat-block p {
  margin: 0.5rem 0;
  line-height: 1.5;
}

/* Stat block lists (AC, HP, Speed, etc.) */
.stat-block ul {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0;
}

.stat-block ul li {
  margin: 0.25rem 0;
}

/* Ability score table */
.stat-block table {
  width: 100%;
  margin: 1rem 0;
  border: none;
  display: table;
  background: transparent;
}

.stat-block th,
.stat-block td {
  text-align: center;
  padding: 0.5rem;
  border: none;
  background: transparent;
  color: #58180D;
  font-weight: 600;
}

.stat-block th {
  color: #822000;
  font-size: 0.85rem;
  border-bottom: 1px solid #58180D;
}

.stat-block tr:nth-child(even) {
  background: transparent;
}

/* Ability names (Undead Fortitude, Shapechanger, etc.) */
.stat-block-ability {
  font-weight: 700;
  font-style: italic;
  color: #58180D;
}

/* Action names (Slam, Sting, etc.) */
.stat-block-action {
  font-weight: 700;
  font-style: italic;
  color: #822000;
}

/* Section headings inside stat blocks (Actions, Tactics, etc.) */
.stat-block h2,
.stat-block h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #822000;
  margin: 1rem 0 0.5rem 0;
  padding-top: 0.75rem;
  border-top: 1px solid #58180D;
}

.stat-block h2:first-child,
.stat-block h3:first-child {
  border-top: none;
  padding-top: 0;
}

/* Mobile: full width stat blocks */
@media (max-width: 767px) {
  .stat-block {
    padding: 1rem;
    font-size: 0.95rem;
  }

  .stat-block table {
    font-size: 0.85rem;
  }

  .stat-block th,
  .stat-block td {
    padding: 0.35rem;
  }
}

/* === Images === */
.campaign-image {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1rem auto;
  cursor: zoom-in;
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.campaign-image.portrait {
  max-width: 400px;
}

.campaign-image.map {
  max-width: 100%;
}

.campaign-image.location {
  max-width: 800px;
}

.campaign-image.item {
  max-width: 300px;
}

/* === Lightbox === */
.lightbox {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}

.lightbox.active {
  display: flex;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 30px;
  color: white;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
}

.lightbox-image {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.lightbox-caption {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  font-size: 1rem;
  text-align: center;
}

/* === Back to Top Button === */
.back-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: opacity 0.3s;
}

.back-to-top.show {
  display: flex;
}

.back-to-top:hover {
  background: var(--primary-dark);
}

/* === Buttons === */
.btn {
  padding: 0.5rem 1rem;
  border-radius: 4px;
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn:disabled {
  background: #999;
  cursor: not-allowed;
  opacity: 0.6;
}

.btn:disabled:hover {
  background: #999;
}

.btn-logout {
  background: transparent;
  color: white;
  border: 1px solid white;
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* === Page Navigation === */
.page-navigation {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 0;
  border-top: 2px solid var(--border-color);
  border-bottom: 2px solid var(--border-color);
  margin: 1.5rem 0;
}

.page-navigation-bottom {
  border-top: 2px solid var(--border-color);
  border-bottom: none;
  margin-top: 2rem;
  margin-bottom: 1rem;
}

.nav-prev-next {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.nav-link {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--primary-color);
  color: white;
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.2s;
  font-size: 0.9rem;
}

.nav-link:hover {
  background: var(--primary-dark);
  color: white;
}

.nav-up {
  background: rgba(44, 95, 45, 0.1);
  color: var(--primary-dark);
  border: 1px solid var(--primary-color);
}

.nav-up:hover {
  background: rgba(44, 95, 45, 0.2);
  color: var(--primary-dark);
}

.nav-prev {
  margin-right: auto;
}

.nav-next {
  margin-left: auto;
}

/* === Login Page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
}

.login-container {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 400px;
}

.login-container h1 {
  text-align: center;
  color: var(--primary-dark);
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 1rem;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.form-group input:disabled {
  background: #f0f0f0;
  cursor: not-allowed;
  opacity: 0.6;
}

.login-container .btn {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  margin-top: 1rem;
}

.alert {
  padding: 0.75rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.alert-error {
  background: #fee;
  color: #c00;
  border: 1px solid #fcc;
}

.alert-info {
  background: #e7f3fe;
  color: #004085;
  border: 1px solid #b8daff;
}

/* === Tablet (768px+) === */
@media (min-width: 768px) {
  .mobile-menu-toggle {
    display: none;
  }

  .sidebar {
    left: 0;
    box-shadow: none;
  }

  .sidebar-close {
    display: none;
  }

  .content {
    margin-left: 280px;
    padding: 2rem;
  }

  .site-header h1 {
    font-size: 1.5rem;
  }

  .campaign-image.portrait {
    max-width: 300px;
    float: right;
    margin: 0 0 1rem 1rem;
  }
}

/* === Desktop (1024px+) === */
@media (min-width: 1024px) {
  .markdown-content {
    font-size: 18px;
  }

  .markdown-content h1 {
    font-size: 2.5rem;
  }

  .markdown-content h2 {
    font-size: 1.75rem;
  }
}
