/* study-buddy desktop UI — minimal, mobile-friendly system-font styles. */

:root {
  --fg: #1f2937;
  --fg-muted: #6b7280;
  --bg: #ffffff;
  --bg-alt: #f9fafb;
  --bg-hover: #f3f4f6;
  --bg-active: #e0e7ff;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 6px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  cursor: pointer;
}

.muted { color: var(--fg-muted); }
.hidden { display: none !important; }

/* --- Buttons -------------------------------------------------------- */

button, .btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  border-radius: var(--radius);
  padding: 8px 14px;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.6; cursor: default; }

.btn-secondary {
  background: var(--bg-alt);
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-ghost {
  background: transparent;
  color: var(--fg);
  border: 0;
}
.btn-ghost:hover { background: var(--bg-hover); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

/* --- Auth pages ----------------------------------------------------- */

main.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-alt);
}
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card h1 { margin: 0 0 18px; font-size: 22px; }
.card form { display: flex; flex-direction: column; gap: 14px; }
.card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-muted);
}
.card input[type="email"],
.card input[type="password"] {
  font: inherit;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
}
.card input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.card .msg { min-height: 1.4em; margin: 0; font-size: 14px; }
.card .msg.err { color: var(--danger); }
.card .msg.ok { color: var(--success); }
.card p.muted { margin: 18px 0 0; font-size: 13px; }
.card #success h2 { margin: 0 0 8px; font-size: 18px; }
.card #success p { margin: 0; font-size: 14px; }

/* --- Top bar -------------------------------------------------------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 600;
  font-size: 16px;
}
.topbar .spacer { flex: 1; }
.topbar .user-email {
  font-size: 13px;
  margin-right: 4px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Layout --------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - var(--topbar-h));
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-alt);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 14px 16px 8px;
}
.sidebar-header h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
}

.tree {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  flex: 1;
  overflow-y: auto;
}

.tree .subject {
  margin: 2px 0;
}
.tree .subject-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
}
.tree .subject-row:hover { background: var(--bg-hover); }
.tree .subject-row .caret {
  display: inline-block;
  width: 16px;
  text-align: center;
  font-size: 10px;
  color: var(--fg-muted);
  transition: transform 0.15s;
}
.tree .subject.expanded .subject-row .caret {
  transform: rotate(90deg);
}
.tree .subject-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree .subject-row .row-actions {
  display: none;
  gap: 2px;
}
.tree .subject-row:hover .row-actions { display: flex; }

.tree .parts {
  list-style: none;
  margin: 0;
  padding: 2px 0 4px 22px;
  display: none;
}
.tree .subject.expanded .parts { display: block; }

.tree .part-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  font-size: 14px;
}
.tree .part-row:hover { background: var(--bg-hover); }
.tree .part-row.active { background: var(--bg-active); }
.tree .part-row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree .part-row .row-actions {
  display: none;
  gap: 2px;
}
.tree .part-row:hover .row-actions,
.tree .part-row.active .row-actions { display: flex; }

.tree .row-actions button {
  background: transparent;
  color: var(--fg-muted);
  padding: 2px 6px;
  font-size: 12px;
  border: 0;
  border-radius: 4px;
}
.tree .row-actions button:hover {
  background: var(--bg);
  color: var(--danger);
}

.tree .add-part-form,
.inline-form {
  display: flex;
  gap: 6px;
  padding: 8px 8px 4px;
}
.inline-form { padding: 12px 16px 16px; border-top: 1px solid var(--border); background: var(--bg-alt); }
.tree .add-part-form { padding: 4px 0 8px 22px; }

.inline-form input,
.tree .add-part-form input {
  flex: 1;
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  min-width: 0;
}
.inline-form input:focus,
.tree .add-part-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* --- Content / gallery --------------------------------------------- */

.content {
  overflow-y: auto;
  padding: 24px;
}
.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  text-align: center;
}
.photos-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.photos-header h2 { margin: 0; font-size: 20px; }
.photos-header .muted { font-size: 13px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.thumb {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  background: var(--bg-alt);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  position: relative;
  display: block;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb:hover { border-color: var(--accent); }
.gallery .empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 16px;
  color: var(--fg-muted);
}

/* --- Modals --------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}
.modal-card {
  position: relative;
  background: var(--bg);
  border-radius: 10px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
}
.modal-header .btn-ghost {
  font-size: 22px;
  line-height: 1;
  padding: 0 8px;
}
.modal-body {
  padding: 16px;
  text-align: center;
}
.qr-wrap {
  display: grid;
  place-items: center;
  margin: 12px 0;
  min-height: 240px;
}
.qr-wrap img {
  width: 240px;
  height: 240px;
  background: var(--bg-alt);
}
.modal-body .msg { margin: 8px 0 0; }
.modal-body .msg.ok { color: var(--success); }
.modal-body .msg.err { color: var(--danger); }

/* --- Lightbox ------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
}
.lightbox img {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.4);
}
.lightbox-close:hover { background: rgba(0,0,0,0.6); }

/* --- Mobile --------------------------------------------------------- */

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
  }
  .sidebar {
    max-height: 50vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .topbar .user-email { display: none; }
}
