:root {
  --primary: #009688;
  --primary-dark: #00695c;
  --primary-light: #b2dfdb;
  --bg: #f1f7f6;
  --surface: #ffffff;
  --surface-muted: #e0f2f1;
  --border: #c8e1df;
  --text: #263332;
  --shadow: rgba(0, 105, 92, 0.15);
  --overlay: rgba(38, 51, 50, 0.5);
}

* {
  box-sizing: border-box;
  font-family: system-ui, sans-serif;
}

a {
  color: var(--primary-dark);
}
a:hover {
  color: var(--primary);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

header {
  background: var(--primary);
  color: var(--surface);
  padding: 0.5rem 1rem;
  margin: 0;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#menuToggle {
  display: none;
  font-size: 1.5rem;
  background: none;
  border: none;
  color: var(--surface);
  cursor: pointer;
}

header h1 {
  margin: 0;
}

.textpage {
  margin: 1rem;
}

#app {
  display: flex;
  height: calc(100vh - 64px - 48px);
}

/* Sidebar */
#sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.subject {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  font-weight: bold;
  cursor: pointer;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
}

.subject-toggle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;

  background: transparent;
  color: var(--primary-dark);
  font-size: 16px;
  font-weight: bold;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.subject-toggle:hover {
  background: var(--primary);
  color: var(--surface);
  border-color: var(--primary);
}

.topic {
  padding: 0.5rem 2rem;
  cursor: pointer;
}

.topic:hover,
.subject:hover {
  background: var(--primary-light);
}

/* Content */
#content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

#documents {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.2rem;
}

#content h2 {
  margin-top: 0;
  font-size: 110%;
}

/* Document Card */
.card {
  border-radius: 6px;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  display: grid;
  grid-template-columns: 4fr 1.2fr;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--primary);
  box-shadow: 4px 4px 10px var(--shadow);
}

.card .content {
  display: flex;
  flex-direction: column;
}

.card .content > p {
  margin: 0;
}

.card img {
  height: 100%;
  width: 100%;
  object-fit: cover;
}

.card h3 {
  margin: 0.3rem 0;
  font-size: 1rem;
  flex-grow: 1;
}

.card p {
  font-size: 0.85rem;
  flex: 1;
}

.card .actions {
  display: grid;
  grid-template-columns: auto auto auto;
}

.card a {
  margin-top: 0.5rem;
  text-decoration: none;
  color: var(--primary-dark);
  font-weight: bold;
}

.doc-icon {
  width: 48px;
  height: 48px;
  object-fit: contain;
  margin-bottom: 0.5rem;
}

/* share dialog*/
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal h3 {
  color: var(--primary-dark);
}

.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 8px;
  min-width: 30%;
  text-align: center;
  position: relative;
}

.modal-content h3 {
  margin-top: 0;
  color: var(--primary-dark);
}

.modal-content input {
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 1.5rem;
  border: none;
  background: none;
  cursor: pointer;
}

#qrcode {
  margin: 1rem auto;
  width: 180px;
}

#shareUrl {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
}

#copyShareUrl {
  background: var(--primary);
  color: var(--surface);
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-radius: 4px;
}

#copyShareUrl:hover {
  background: var(--primary-dark);
}

/* footer */
#footer-nav {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  text-align: center;
  height: 48px;
}

#footer-nav nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
}

#footer-nav a {
  color: var(--primary-dark);
  text-decoration: none;
  font-size: 0.9rem;
}

#footer-nav a:hover {
  text-decoration: underline;
}

/* mobile */
@media (max-width: 768px) {
  html {
    height: 100%;
  }
  body {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  header h1 {
    font-size: 150%;
  }
  #menuToggle {
    display: block;
  }

  #app {
    flex-direction: column;
  }

  #sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 900;
    box-shadow: 2px 0 8px var(--shadow);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #content {
    padding: 1rem;
  }

  #documents {
    grid-template-columns: 1fr;
  }

  .subject,
  .topic {
    padding: 1rem;
    font-size: 1rem;
  }

  .subject-toggle {
    width: 28px;
    height: 28px;
    font-size: 18px;
    font-weight: bold;
  }
}
