@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700;9..144,800&family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
  --bg: #f6f1ea;
  --surface: #fff9f2;
  --surface-2: #f1e7dc;
  --text: #1c1917;
  --muted: #6b6259;
  --border: #e4d5c3;
  --accent: #0f766e;
  --accent-2: #d97706;
  --accent-3: #b91c1c;
  --shadow: 0 20px 48px rgba(34, 24, 10, 0.14);
  --radius: 18px;
  --font-body: "Space Grotesk", "Helvetica Neue", sans-serif;
  --font-display: "Fraunces", "Georgia", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 12% -10%, rgba(15, 118, 110, 0.18), transparent 56%),
    radial-gradient(900px 420px at 90% 0%, rgba(217, 119, 6, 0.18), transparent 50%),
    linear-gradient(180deg, #f9f2e7 0%, #f4ede2 55%, #f6f1ea 100%);
}

body.menu-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  display: block;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  background: rgba(255, 249, 242, 0.92);
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
}

.brand:hover,
.brand:focus {
  text-decoration: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  padding: 6px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 26px rgba(15, 118, 110, 0.25);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.brand-text {
  display: grid;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.nav {
  display: flex;
  gap: 8px;
  flex: 1;
  flex-wrap: wrap;
}

.burger {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

.burger svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

.menu {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 40;
}

.menu.open {
  display: block;
}

.menu-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 23, 0.2);
}

.menu-panel {
  position: absolute;
  right: 20px;
  top: 70px;
  width: min(300px, calc(100% - 40px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
}

.menu-title {
  font-weight: 800;
  font-family: var(--font-display);
}

.menu-link {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 700;
}

.menu-link.active {
  background: var(--surface-2);
}

.nav-link {
  padding: 8px 12px;
  border-radius: 12px;
  font-weight: 600;
  background: transparent;
}

.nav-link.active {
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}

.user-block {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-name {
  font-weight: 600;
}

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
}

.container {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 28px 0 64px;
}

.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 0 30px;
}

.footer-inner {
  width: min(1100px, 92vw);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
}

.footer-right {
  text-align: right;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-books {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.load-more {
  display: flex;
  justify-content: center;
  margin: 18px 0 6px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.fields {
  display: grid;
  gap: 12px;
}

label {
  display: block;
  font-weight: 700;
  font-size: 13px;
  margin-top: 10px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  font-family: var(--font-body);
  font-size: 14px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.35);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(23, 15, 5, 0.12);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #12b981);
  color: #fff;
  border-color: transparent;
}

.btn-danger {
  background: linear-gradient(135deg, var(--accent-3), #ef4444);
  color: #fff;
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
}

.btn-muted {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #475569;
  box-shadow: none;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  align-items: stretch;
}

.hero h1 {
  margin: 6px 0 10px;
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 44px);
}

.hero-panel {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  gap: 10px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.search {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.search .suggest input {
  padding-right: 38px;
}

.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--danger);
  background: #fff;
  color: var(--danger);
  font-weight: 800;
  cursor: pointer;
}

.search-clear.hidden {
  display: none;
}

.book-card {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  align-items: center;
}

.cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: #f5ebe0;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.cover-fallback {
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.book-meta h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.book-meta .muted {
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.book-meta {
  min-width: 0;
}

.book-meta-actions {
  margin-top: 6px;
  display: grid;
  gap: 6px;
}

.detail {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 20px;
}

.detail-cover {
  display: grid;
  place-items: start;
}

.detail-main h1 {
  margin-top: 0;
  font-family: var(--font-display);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.metric-label {
  font-size: 12px;
  color: var(--muted);
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  padding: 12px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--surface-2);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: #fff;
  color: #fff;
}

.badge-ok {
  background: #16a34a;
  border-color: #16a34a;
}

.badge-info {
  background: #2563eb;
  border-color: #2563eb;
}

.badge-warn {
  background: #dc2626;
  border-color: #dc2626;
}

.badge-danger {
  background: #b91c1c;
  border-color: #b91c1c;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.flash {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 600;
}

.flash-success {
  border-color: rgba(5, 150, 105, 0.35);
}

.flash-danger {
  border-color: rgba(185, 28, 28, 0.35);
}

.flash-warn {
  border-color: rgba(217, 119, 6, 0.35);
}

.flash-info {
  border-color: rgba(14, 116, 144, 0.35);
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.suggest {
  position: relative;
}

.suggest-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 10;
  max-height: 240px;
  overflow: auto;
  padding: 6px;
}

.suggest-list.open {
  display: grid;
  gap: 6px;
}

.suggest-item {
  text-align: left;
  border: 1px solid transparent;
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 600;
}

.suggest-item:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.qr-box {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.qr-code {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.qr-placeholder {
  width: 140px;
  height: 140px;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.2), rgba(217, 119, 6, 0.12)),
    repeating-linear-gradient(45deg, rgba(28, 25, 23, 0.08), rgba(28, 25, 23, 0.08) 8px, transparent 8px, transparent 16px);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--muted);
}

.scan-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.scan-panel {
  margin-top: 16px;
  display: grid;
  gap: 10px;
  justify-items: start;
}

.scan-panel video {
  width: min(100%, 420px);
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #000;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.error {
  color: var(--accent-3);
  font-weight: 700;
}

.fade-up {
  opacity: 0;
  transform: translateY(12px);
}

body:not(.is-ready) .hero > *,
body:not(.is-ready) .metrics .card {
  opacity: 0;
  transform: translateY(12px);
}

body.is-ready .fade-up {
  animation: fadeUp 0.6s ease forwards;
  animation-delay: var(--delay, 0s);
}

body.is-ready .hero > * {
  animation: fadeUp 0.6s ease forwards;
}

body.is-ready .hero > *:nth-child(2) {
  animation-delay: 0.08s;
}

body.is-ready .metrics .card {
  animation: fadeUp 0.6s ease forwards;
}

body.is-ready .metrics .card:nth-child(2) {
  animation-delay: 0.06s;
}

body.is-ready .metrics .card:nth-child(3) {
  animation-delay: 0.12s;
}

body.is-ready .metrics .card:nth-child(4) {
  animation-delay: 0.18s;
}

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

@media (max-width: 900px) {
  .book-card {
    grid-template-columns: 1fr;
  }
  .detail {
    grid-template-columns: 1fr;
  }
  table {
    min-width: 520px;
  }
}

@media (max-width: 700px) {
  .topbar {
    flex-wrap: wrap;
  }
  .nav {
    width: 100%;
  }
  .user-block {
    width: 100%;
    justify-content: flex-start;
  }
  .search {
    flex-direction: column;
  }
  .scan-form {
    flex-direction: column;
  }
}

.calendar-wrap {
  overflow-x: auto;
}

.calendar-table {
  min-width: 1800px;
  table-layout: fixed;
  font-size: 12px;
}

.calendar-table th,
.calendar-table td {
  padding: 6px 6px;
}

.calendar-holidays th {
  background: #fff;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  vertical-align: top;
}

.calendar-months th {
  background: var(--surface-2);
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
}

.calendar-headings th {
  font-size: 10px;
}

.calendar-entry {
  display: block;
  line-height: 1.3;
}

.calendar-entry.holiday {
  color: var(--accent-3);
  font-weight: 700;
}

.calendar-entry.fest {
  color: var(--text);
}

.calendar-col-day {
  width: 36px;
}

.calendar-col-weekday {
  width: 42px;
}

.calendar-col-note {
  width: 140px;
}

.calendar-col-week {
  width: 38px;
  text-align: center;
}

td.calendar-col-note[contenteditable="true"] {
  min-height: 20px;
  border-radius: 6px;
}

td.calendar-col-note[contenteditable="true"]:focus {
  outline: 2px solid rgba(15, 118, 110, 0.3);
  background: #fff;
}

.calendar-empty {
  background: var(--surface);
}

@media (prefers-reduced-motion: reduce) {
  .fade-up {
    opacity: 1;
    transform: none;
  }
  body:not(.is-ready) .hero > *,
  body:not(.is-ready) .metrics .card {
    opacity: 1;
    transform: none;
  }
  body.is-ready .fade-up {
    animation: none;
  }
  body.is-ready .hero > *,
  body.is-ready .metrics .card {
    animation: none;
  }
}
