:root {
  --primary: #007aff;
  --primary-hover: #0056b3;
  --bg-body: #f0f2f5;
  --sidebar-bg: #ffffff;
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.5);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --text-main: #1d1d1f;
  --text-sec: #86868b;
  --border-color: rgba(0,0,0,0.06);
  --radius-l: 24px;
  --radius-m: 16px;
  --radius-s: 8px;
  --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --sidebar-width: 300px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-stack);
  background: var(--bg-body);
  color: var(--text-main);
  /* Subtle mesh gradient background */
  background-image: 
    radial-gradient(at 0% 0%, rgba(200, 230, 255, 0.5) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(230, 230, 255, 0.5) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(255, 230, 230, 0.4) 0px, transparent 50%),
    radial-gradient(at 0% 100%, rgba(230, 255, 230, 0.4) 0px, transparent 50%);
  background-attachment: fixed;
  background-size: cover;
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
}

#app {
  height: 100%;
  min-height: 0;
}

/* Layout */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 20;
  box-shadow: 4px 0 24px rgba(0,0,0,0.02);
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(10px);
}

.brand-row {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.sidebar-brand-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
  margin-right: 12px;
  border-radius: 8px;
}

.sidebar-brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-welcome {
  font-size: 13px;
  color: var(--text-main);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-welcome::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #34c759;
  border-radius: 50%;
}

.accordion-control {
  font-size: 12px;
  color: var(--text-sec);
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.accordion-control input {
  margin: 0 4px 0 0;
  accent-color: var(--primary);
}

.menu {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.menu::-webkit-scrollbar {
  width: 4px;
}
.menu::-webkit-scrollbar-track {
  background: transparent;
}
.menu::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}
.menu::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.2);
}

/* Menu Items */
.menu-item {
  padding: 12px 16px;
  margin-bottom: 4px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid transparent;
}

.menu-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.menu-item.active {
  background: #fff;
  color: var(--primary);
  border-color: rgba(0, 122, 255, 0.1);
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.08);
}

.menu-children {
  padding-left: 12px;
  margin-bottom: 8px;
  position: relative;
}

.menu-children::before {
  content: "";
  position: absolute;
  left: 22px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border-color);
  border-radius: 2px;
}

/* Resource Link in Menu */
.resource-item-link {
  font-size: 13px;
  color: var(--text-sec);
  padding: 10px 16px 10px 42px; /* Increased left padding for indentation */
  border-radius: 8px;
  margin-bottom: 2px;
  display: flex;
  align-items: center; /* Vertically center icon and text */
  position: relative;
  line-height: 1.5;
  cursor: pointer;
  transition: all 0.2s ease;
}

.resource-item-link span:first-child {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  min-width: 20px;
  margin-right: 10px;
  font-size: 16px; /* Consistent icon size */
}

.resource-item-link span:last-child {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-item-link:hover {
  color: var(--text-main);
  background: rgba(0,0,0,0.04);
}

.resource-item-link.active {
  background: rgba(0, 122, 255, 0.1);
  color: var(--primary);
  font-weight: 600;
}

.resource-item-link::before {
  content: "";
  position: absolute;
  left: 24px;
  top: 50%;
  width: 8px;
  height: 1px;
  background: var(--border-color);
  opacity: 0.5;
}

/* Contact Card */
.contact-card {
  padding: 24px;
  border-top: 1px solid var(--border-color);
  background: rgba(249, 250, 251, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.contact-qr {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  padding: 4px;
  background: #fff;
}

.contact-info {
  margin-bottom: 12px;
}

.contact-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
}

.contact-phone {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--text-sec);
}

.contact-actions {
  display: flex;
  gap: 8px;
  width: 100%;
}

.btn-contact, .btn-logout {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: #fff;
  transition: all 0.2s;
  color: var(--text-main);
}

.btn-contact:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-logout:hover {
  background: #fff0f0;
  color: #ff3b30;
  border-color: #ff3b30;
}

/* Main Viewer */
.viewer {
  flex: 1;
  position: relative;
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#content {
  flex: 1;
  width: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.viewer iframe, .viewer img {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.watermark {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Hero Screen */
.hero-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 40px;
  position: relative;
  overflow-y: auto; /* Allow scrolling if content is too tall */
}

@media (max-width: 768px) {
  .hero-container {
    padding: 20px;
  }
  .hero-content {
    padding: 40px;
  }
}

.hero-content {
  position: relative;
  z-index: 10;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  padding: 60px 80px;
  border-radius: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.08);
  border: 1px solid rgba(255,255,255,1);
  max-width: 500px;
  width: 100%;
  animation: heroFadeIn 0.8s ease-out;
  margin: 40px auto; /* Fixed top margin, horizontal auto */
  text-align: center;
}

@keyframes heroFadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-logo {
  height: 100px;
  width: auto;
  object-fit: contain;
  margin-bottom: 32px;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.1));
}

.hero-title {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #1d1d1f 0%, #434344 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 16px;
  color: var(--text-sec);
  line-height: 1.6;
}

/* PDF/Zoom Toolbar */
.pdf-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
  z-index: 50;
}

.pdf-toolbar button {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: #f9f9f9;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pdf-toolbar button:hover {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

.pdf-toolbar button:active {
  transform: translateY(0);
}

.scale-display {
  background: #f0f2f5;
  padding: 6px 12px;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  color: var(--text-sec);
  font-size: 13px;
}

/* Login Page */
.login {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-body);
  position: relative;
}

.login-card {
  background: #fff;
  padding: 48px;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.08);
  width: 360px;
  text-align: center;
  position: relative;
  z-index: 10;
}

.login-card h3 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 700;
}

.login-subtitle {
  color: var(--text-sec);
  margin-bottom: 32px;
  font-size: 14px;
}

.input {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: #f9f9f9;
  font-size: 15px;
  outline: none;
  transition: all 0.2s;
}

.input:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

.button {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.button:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 122, 255, 0.4);
}

.button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* Mobile Toggle */
.mobile-toggle {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: -100%;
    top: 0;
    bottom: 0;
    width: 280px;
    box-shadow: 100px 0 0 rgba(0,0,0,0.2); /* Backdrop simulation */
  }
  
  .sidebar.open {
    transform: translateX(100%);
  }
  
  .mobile-toggle {
    display: flex;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 100;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
  }

  /* Optimize Grid for Mobile */
  .resource-list {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    padding-bottom: 80px; /* Space for bottom content */
  }

  .resource-list-container {
    padding: 20px;
  }

  .resource-item {
    padding: 16px;
  }

  .resource-icon {
    font-size: 32px;
    margin-bottom: 12px;
  }

  .resource-name {
    font-size: 13px;
  }

  /* Adjust Docx Viewer for Mobile */
  .docx-viewer {
    width: 100% !important; /* Full width on mobile */
    min-height: auto !important;
    padding: 16px !important; /* Smaller margins */
    margin: 20px auto !important;
    box-shadow: none !important; /* Simplify shadow */
  }
}

/* Resource List (Grid Layout) */
.resource-list-container {
  padding: 40px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background: var(--bg-body);
}

.resource-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 24px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding-bottom: 40px;
}

.resource-item {
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(0,0,0,0.04);
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
  position: relative;
  overflow: hidden;
}

.resource-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.08);
}

.resource-icon {
  font-size: 48px;
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
  transition: transform 0.3s ease;
}

.resource-item:hover .resource-icon {
  transform: scale(1.1);
}

.resource-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.resource-date {
  font-size: 12px;
  color: var(--text-sec);
  margin-top: auto;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px;
  text-align: center;
  color: var(--text-sec);
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Viewer Wrapper Styles - Added for fixes */
.pdf-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  overflow: hidden;
  min-height: 0;
}

.pdf-canvas-container {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #f0f2f5;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 0;
  /* padding: 24px; Optional padding */
}

/* Docx Viewer Styles - A4 Paper Simulation */
.docx-viewer {
  background: #fff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1), 0 10px 20px rgba(0, 0, 0, 0.15);
  /* A4 Dimensions: 210mm x 297mm */
  width: 210mm;
  min-height: 297mm;
  margin: 40px auto; /* Center horizontally with vertical spacing */
  /* Add padding to simulate margins, preventing text cutoff */
  /* Using 20mm vertical and 25mm horizontal as a safe default */
  padding: 20mm 25mm !important; 
  box-sizing: border-box;
  position: relative;
  overflow: hidden; /* Clip content strictly to A4 size */
  overflow-wrap: break-word; /* Ensure long words break */
}

/* Ensure internal wrapper fills the A4 paper */
.docx-viewer .docx-wrapper {
  background: transparent !important;
  padding: 0 !important;
  width: 100% !important;
}

/* Ensure sections (pages) rendered by docx-preview fill the width */
.docx-viewer section {
  width: 100% !important;
  box-sizing: border-box !important;
  box-shadow: none !important; /* Remove internal shadows if any */
  margin: 0 !important; /* Remove external margins of sections */
  background: transparent !important;
}

/* Ensure images inside docx scale properly */
.docx-viewer img {
  max-width: 100%;
  height: auto;
}

.excel-viewer {
  background: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-height: 100%;
  width: 100%;
  padding: 20px;
  overflow: auto;
}
