/* =========================================================
   NOFITECH — Global Styles (mobile-first, palette-driven)
   ========================================================= */

/* ---------- Color tokens ---------- */
:root {
  /* Base palette */
  --bg: #f1f8f8;
  --panel: #ffffff;
  --text: #1c7a87;
  --muted: #4ec1b3;
  --accent: #4ec1b3;
  --assistant: #ffffff;
  --user: #e0f4f3;
  --teal: #1c7a87;
  --mint: #4ec1b3;
  --card-border: #dbe9e9;

  /* Neutrals */
  --white: #ffffff;
  --black: #000000;
  --light-gray: #f5f5f5;

  /* UI states */
  --hover-bg: #eaf2f2;

  /* Shadows & borders */
  --shadow-light: rgba(0, 0, 0, 0.05);
  --shadow-medium: rgba(0, 0, 0, 0.1);

  /* Effects */
  --topbar-gradient: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.9),
    rgba(255, 255, 255, 0.7),
    transparent
  );
  --topbar-border: rgba(28, 122, 135, 0.1);

  /* Focus */
  --focus-outline: rgba(78, 193, 179, 0.2);
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Lato', 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

img { max-width: 100%; height: auto; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: transparent;
  padding: 0.8rem max(1rem, env(safe-area-inset-left)) 0.5rem max(1rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--topbar-border);
}

.topbar-content {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.topbar-logo {
  height: 28px;
  width: auto;
  display: block;
  align-self: baseline;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw + 0.9rem, 2rem);
  color: var(--text);
  line-height: 1.1;
}

.subtitle {
  color: var(--muted);
  font-size: clamp(0.9rem, 1.5vw + 0.6rem, 1rem);
  margin-top: 0.2rem;
}

/* Back to Home button (top-right) */
.back-home-btn {
  margin-left: auto;          /* push to right in flex row */
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.45rem 0.8rem;    /* comfortable touch size */
  background: var(--panel);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--teal);
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 1px 3px var(--shadow-light);
  transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.back-home-btn:hover {
  background-color: var(--hover-bg);
  transform: translateY(-1px);
}

.back-home-btn:focus-visible {
  outline: 3px solid var(--focus-outline);
  outline-offset: 2px;
}

/* ---------- Menu (landing) ---------- */
.menucontainer {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 120px);
  padding: 1.25rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  box-shadow: 0 2px 6px var(--shadow-light);
  padding: clamp(1.5rem, 3vw, 3rem) clamp(1rem, 2.5vw, 2.5rem);
  width: min(820px, 95vw);
  text-align: center;
}

.card h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw + 0.9rem, 2rem);
  color: var(--text);
}

/* Button group */
.module-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  justify-items: stretch;
  align-items: stretch;
  margin-top: 0.75rem;
}

/* Anchor as button */
.module-button {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  text-decoration: none;
  background: var(--panel);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  border: 1px solid var(--card-border);
  box-shadow: 0 2px 4px var(--shadow-light);
  color: var(--teal);
  min-height: 56px; /* tap target */
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.module-button:hover {
  transform: translateY(-2px);
  background-color: var(--hover-bg);
  box-shadow: 0 4px 8px var(--shadow-light);
}

.module-button:focus-visible {
  outline: 3px solid var(--focus-outline);
  outline-offset: 3px;
}

.module-icon {
  font-size: 1.6rem;
  line-height: 1;
  color: var(--mint);
}

.module-title {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--teal);
}

/* Footer */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  background: transparent;
}

/* ---------- Menu Page Specific ---------- */

/* Background image */
body.menu-page {
  background-color: #00827d;
  background-image: url('background.png');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
}

/* Darker topbar text */
.topbar h1 {
  color: #0d4a52 !important;
  font-size: 2.8rem !important;
}

.topbar-logo {
  height: 2.8rem !important;
}

.topbar .subtitle {
  color: var(--muted) !important;
  font-size: 1.75rem !important;
}

/* Topbar menu styles */
.topbar-menu {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
  margin-right: 1rem;
}

.topbar-home-link {
  margin-left: auto;
  padding: 0.5rem 1.5rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 1.61rem;
  font-weight: 500;
  transition: color 0.2s;
  align-self: center;
}

.topbar-home-link:hover {
  color: #b7e7e6;
}

.topbar-user {
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 500;
  align-self: center;
  margin-left: 1rem;
}

.topbar-logout-link {
  padding: 0.5rem 1.5rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 500;
  transition: color 0.2s;
  align-self: center;
  border: 1px solid var(--muted);
  border-radius: 4px;
}

.topbar-logout-link:hover {
  color: var(--white);
  background-color: var(--muted);
}

.topbar-menu-item {
  position: relative;
}

.topbar-menu-button {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--muted);
  font-size: 1.61rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background-color 0.2s ease;
  white-space: nowrap;
}

.topbar-menu-button:hover {
  background: transparent;
  color: #b7e7e6;
}

.topbar-menu-button.active {
  background: transparent;
}

.topbar-menu-button .menu-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
}

.topbar-menu-button.active .menu-arrow {
  transform: rotate(180deg);
}

.topbar-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 200px;
  background: #b7e7e6;
  border: none;
  border-radius: 0;
  box-shadow: 0 4px 12px var(--shadow-medium);
  z-index: 1100;
  overflow: hidden;
}

.topbar-dropdown.show {
  display: block;
}

.topbar-dropdown-item {
  display: flex;
  align-items: center;
  padding: 0.7rem 1rem;
  text-decoration: none;
  color: var(--teal);
  border-bottom: 1px solid var(--card-border);
  transition: background-color 0.2s ease;
  font-size: 1.3rem;
}

.topbar-dropdown-item:last-child {
  border-bottom: none;
}

.topbar-dropdown-item:hover:not(.disabled) {
  background-color: var(--hover-bg);
}

.topbar-dropdown-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.topbar-dropdown-item .item-icon {
  margin-right: 0.6rem;
  font-size: 1.1rem;
}

.dropdown-container {
  position: relative;
  display: inline-block;
  width: 100%;
}

.dropdown-button {
  width: 100%;
  padding: 0.9rem 1rem;
  background: var(--panel);
  border: none;
  border-radius: 12px;
  color: var(--teal);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px var(--shadow-light);
}

.dropdown-button:hover {
  background-color: var(--hover-bg);
  transform: translateY(-1px);
}

.dropdown-button .icon {
  font-size: 1.4rem;
  color: var(--mint);
  margin-right: 0.5rem;
}

.dropdown-button .arrow {
  transition: transform 0.3s ease;
  color: var(--muted);
}

.dropdown-button.active .arrow {
  transform: rotate(180deg);
}

.dropdown-content {
  display: none;
  margin-top: 0.5rem;
  background: var(--panel);
  border: none;
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--shadow-light);
  overflow: hidden;
}

.dropdown-content.show {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  padding: 0.8rem 1rem;
  text-decoration: none;
  color: var(--teal);
  border-bottom: 1px solid var(--card-border);
  transition: background-color 0.2s ease;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background-color: var(--hover-bg);
}

.dropdown-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.dropdown-item .item-icon {
  font-size: 1.3rem;
  margin-right: 0.8rem;
  color: var(--mint);
}

.dropdown-item .item-text {
  flex: 1;
}

.dropdown-item .badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  background: var(--light-gray);
  color: var(--muted);
  border-radius: 6px;
  font-weight: 600;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}

/* ---------- Responsive Tweaks ---------- */

/* ≥ 768px (tablets / small laptops) */
@media (min-width: 768px) {
  .topbar-logo { height: 32px; }
  .module-buttons { gap: 1rem; }
}

/* Motion respect */
@media (prefers-reduced-motion: reduce) {
  .module-button,
  .back-home-btn { transition: none; }
  .module-button:hover { transform: none; }
}

/* =========================================================
   Mobile / tablet nav (hamburger toggle in portal topbar)
   ========================================================= */

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.topbar-titles {
  min-width: 0;
}

.topbar-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  margin-left: auto;
  background: #0d4a52;
  border: 1px solid #0d4a52;
  border-radius: 8px;
  box-shadow: 0 1px 3px var(--shadow-light);
  cursor: pointer;
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}

.topbar-toggle:hover,
.topbar-toggle:focus-visible {
  background: #1c7a87;
  outline: none;
}

.topbar-toggle-bar {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--muted);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.topbar-toggle.is-open .topbar-toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.topbar-toggle.is-open .topbar-toggle-bar:nth-child(2) {
  opacity: 0;
}
.topbar-toggle.is-open .topbar-toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Scale the huge portal typography for narrow viewports so the topbar
   does not balloon to two lines on phones. */
@media (max-width: 900px) {
  .topbar h1 {
    font-size: 1.75rem !important;
  }
  .topbar .subtitle {
    font-size: 1rem !important;
  }
  .topbar-logo {
    height: 2rem !important;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: 0.6rem max(0.75rem, env(safe-area-inset-left)) 0.5rem max(0.75rem, env(safe-area-inset-right));
  }
  .topbar h1 {
    font-size: 1.3rem !important;
    line-height: 1.15;
  }
  .topbar .subtitle {
    font-size: 0.85rem !important;
  }
  .topbar-logo {
    height: 1.75rem !important;
  }
}

/* Mobile / tablet: swap horizontal topbar-menu for a collapsible panel */
@media (max-width: 900px) {
  .topbar-toggle {
    display: inline-flex;
  }

  .topbar-brand {
    flex: 1 1 auto;
  }

  /* Outer wrapper: hidden by default, slides down when .mobile-open */
  .topbar-content > .topbar-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    margin: 0;
    padding: 0.75rem max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left));
    background: #b7e7e6;
    box-shadow: 0 6px 16px var(--shadow-medium);
    border-top: 1px solid var(--card-border);
    z-index: 1050;
  }

  .topbar-content > .topbar-nav.mobile-open {
    display: flex;
  }

  /* Nested nav (from base_topmenu.html) inherits the column layout */
  .topbar-content > .topbar-nav .topbar-menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
    position: static;
  }

  .topbar-content > .topbar-nav .topbar-home-link {
    margin-left: 0;
    padding: 0.75rem 0.5rem;
    font-size: 1.1rem;
    border-radius: 8px;
  }

  .topbar-content > .topbar-nav .topbar-home-link:hover {
    background: rgba(255, 255, 255, 0.35);
    color: var(--teal);
  }

  .topbar-content > .topbar-nav .topbar-menu-item {
    width: 100%;
  }

  .topbar-content > .topbar-nav .topbar-menu-button {
    width: 100%;
    justify-content: space-between;
    padding: 0.75rem 0.5rem;
    font-size: 1.1rem;
    border-radius: 8px;
  }

  .topbar-content > .topbar-nav .topbar-menu-button:hover {
    background: rgba(255, 255, 255, 0.35);
    color: var(--teal);
  }

  /* Dropdowns render inline (below their button) instead of absolute-right */
  .topbar-content > .topbar-nav .topbar-dropdown {
    position: static;
    display: none;
    width: 100%;
    min-width: 0;
    margin-top: 0.25rem;
    background: rgba(255, 255, 255, 0.6);
    box-shadow: none;
    border-radius: 8px;
    overflow: hidden;
  }

  .topbar-content > .topbar-nav .topbar-dropdown.show {
    display: block;
  }

  .topbar-content > .topbar-nav .topbar-dropdown-item {
    font-size: 1rem;
    padding: 0.65rem 0.9rem;
  }
}

/* Landing page menu tweaks for phones */
@media (max-width: 600px) {
  .menucontainer {
    min-height: calc(100dvh - 140px);
    padding: 0.75rem;
  }

  .card {
    width: min(100%, 100vw);
  }

  .module-buttons {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  .footer {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* Library / chatbot pages: keep content readable and scrollable on phones */
@media (max-width: 768px) {
  .library-container,
  .chatbot-container {
    margin: 1rem auto;
    padding: 0 0.75rem 3rem 0.75rem;
    max-height: none;
  }

  .library-header,
  .chatbot-header {
    padding: 1.25rem;
    margin-bottom: 1rem;
  }

  .chatbot-header h1 {
    font-size: 1.4rem;
  }

  .chatbot-header p {
    font-size: 0.95rem;
  }

  .chatbot-wrapper {
    padding: 0.75rem;
  }

  .composer {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #user-input {
    flex: 1 1 100%;
    min-height: 48px;
    padding: 0.75rem 1rem;
  }

  #send-btn,
  #clear-history-btn {
    flex: 1 1 auto;
    min-height: 48px;
    padding: 0 1rem;
  }

  .documents-table {
    overflow-x: auto;
  }

  .documents-table table {
    min-width: 520px;
  }
}

/* =========================================================
   LIBRARY PAGE STYLES
   ========================================================= */

.library-container {
    max-width: 1600px;
    margin: 2rem auto;
    padding: 0 2rem 6rem 2rem;
    max-height: calc(100vh - 8rem);
    display: flex;
    flex-direction: column;
}

.library-header {
    background: #b7e7e6;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 6px var(--shadow-light);
    flex-shrink: 0;
}

.library-header h1 {
    margin: 0 0 0.5rem 0;
    color: var(--teal);
}

.library-header p {
    margin: 0;
    color: var(--teal);
}

.doc-count {
    font-weight: 600;
    color: var(--teal);
}

.documents-table {
    background: #eaf2f2;
    border-radius: 12px;
    overflow: auto;
    box-shadow: 0 2px 6px var(--shadow-light);
    flex: 1;
    min-height: 0;
}

.documents-table table {
    width: 100%;
    border-collapse: collapse;
    background: #eaf2f2;
}

.documents-table thead {
    background: #eaf2f2;
}

.documents-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--teal);
    border-bottom: 2px solid var(--card-border);
}

.documents-table td {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--card-border);
    color: var(--text);
}

.documents-table tbody tr:hover {
    background-color: #b7e7e6;
}

.documents-table tbody tr:last-child td {
    border-bottom: none;
}

/* =========================================================
   NOFIBOT/CHATBOT PAGE STYLES
   ========================================================= */

.chatbot-container {
  max-width: 1600px;
  margin: 2rem auto;
  padding: 0 2rem 4rem 2rem;
  max-height: calc(100vh - 8rem);
  display: flex;
  flex-direction: column;
}

.chatbot-header {
  background: #b7e7e6;
  border-radius: 12px;
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 6px var(--shadow-light);
  flex-shrink: 0;
}

.chatbot-header h1 {
  margin: 0 0 0.5rem 0;
  color: var(--teal);
  font-size: 2rem;
}

.chatbot-header p {
  margin: 0;
  color: var(--teal);
  font-size: 1.1rem;
}

.chatbot-wrapper {
  background: #b7e7e6;
  border-radius: 12px;
  box-shadow: 0 2px 6px var(--shadow-light);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
}

#chat {
  flex: 1;
  overflow-y: auto;
  background: #b7e7e6;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: inset 0 1px 3px var(--shadow-light);
}

.composer {
  display: flex;
  gap: 0.75rem;
}

/* Chat Messages */
.msg {
  display: flex;
  margin: 0.6rem 0;
}

.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  padding: 1rem 1.25rem;
  border-radius: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 2px 4px var(--shadow-light);
  font-size: 1rem;
  font-family: 'Lato', 'Segoe UI', system-ui, sans-serif;
}

.msg.user .bubble {
  background: var(--user);
  color: var(--text);
}

.msg.assistant .bubble {
  background: var(--assistant);
  border: 1px solid var(--card-border);
  color: var(--text);
}

/* Tables inside assistant bubbles */
.bubble table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--card-border);
  margin-top: 0.4rem;
}

.bubble th,
.bubble td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--card-border);
  font-size: 0.95rem;
}

.bubble thead th {
  background: var(--hover-bg);
  color: var(--teal);
  font-weight: 600;
}

/* Chat Input & Buttons */
#user-input {
  flex: 1;
  min-height: 54px;
  padding: 1rem 1.25rem;
  font-size: 1rem;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--hover-bg);
  color: var(--text);
  font-family: 'Lato', 'Segoe UI', system-ui, sans-serif;
  box-shadow: 0 2px 4px var(--shadow-light);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#user-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-outline);
  outline: none;
}

#send-btn,
#clear-history-btn {
  min-height: 54px;
  padding: 0 1.5rem;
  font-size: 1rem;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  background: var(--teal);
  color: #ffffff;
  font-weight: 500;
  box-shadow: 0 2px 4px var(--shadow-light);
  transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

#send-btn:hover,
#clear-history-btn:hover {
  background: #156971;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px var(--shadow-light);
}

#send-btn:active,
#clear-history-btn:active {
  background: #0f5158;
  transform: translateY(0);
}

#send-btn:disabled,
#clear-history-btn:disabled {
  background: var(--light-gray);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
}

@media (min-width: 768px) {
  .bubble { max-width: 75%; }
}

@media (prefers-reduced-motion: reduce) {
  #send-btn,
  #clear-history-btn { transition: none; }
  #send-btn:hover,
  #clear-history-btn:hover { transform: none; }
}

/* Elapsed-time meta line shown below assistant replies */
.elapsed-meta {
  font-size: 0.75rem;
  font-weight: 300;
  opacity: 0.7;
  margin-top: 0.15rem;
  margin-left: 0.25rem;
  font-style: italic;
  color: var(--text);
}

/* Right-aligned action group in the topbar (Clear history + Home) */
.topbar-actions {
  margin-left: auto;
  margin-right: calc(-1 * max(1rem, env(safe-area-inset-right)));
  padding-right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.topbar-actions .back-home-btn {
  margin-left: 0;
}

/* Chatbot topbar layout: left brand + right actions, edge to edge */
.topbar-content {
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}
