* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #FBF7F2;
  color: #3E2723;
  padding-bottom: 68px;
  min-height: 100vh;
  word-break: keep-all;
}

/* Header */
header {
  background: linear-gradient(135deg, #6D4C41, #4E342E);
  color: #fff;
  padding: 22px 16px 18px;
  text-align: center;
}

header h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 3px;
}

header .subtitle {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 4px;
  letter-spacing: 1px;
}

/* Tab content */
#tab-content {
  padding: 14px;
  max-width: 420px;
  margin: 0 auto;
}

/* Bottom tab bar */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  display: flex;
  border-top: 1px solid #E0D5D0;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

#tab-bar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  padding: 8px 0 6px;
  font-size: 11px;
  color: #A1887F;
  cursor: pointer;
  transition: color 0.15s;
}

#tab-bar button .tab-icon {
  font-size: 20px;
  line-height: 1;
}

#tab-bar button.active {
  color: #6D4C41;
  font-weight: 700;
}

/* 3-column book grid */
.book-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.book-card {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.12s;
}

.book-card:active {
  transform: scale(0.96);
}

.book-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  background: #EFEBE9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #A1887F;
  overflow: hidden;
  position: relative;
}

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

.book-thumb .status-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 600;
  color: #fff;
}

.status-badge.available {
  background: #43A047;
}

.status-badge.borrowed {
  background: #E53935;
}

.book-info {
  padding: 6px 8px 8px;
}

.book-info .title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}

.book-info .author {
  font-size: 10px;
  color: #8D6E63;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-info .cat-num {
  font-size: 10px;
  color: #6D4C41;
  margin-top: 1px;
  font-weight: 700;
}

/* Search & filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.filter-bar select,
.filter-bar input {
  border: 1px solid #D7CCC8;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: #3E2723;
  outline: none;
  font-family: inherit;
}

.filter-bar select {
  flex: 0 0 auto;
  min-width: 80px;
  -webkit-appearance: none;
  appearance: none;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236D4C41' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 10px center;
  padding-right: 28px;
}

.filter-bar input {
  flex: 1;
}

.filter-bar input::placeholder {
  color: #BCAAA4;
}

/* Section titles */
.section-title {
  font-size: 16px;
  font-weight: 700;
  color: #4E342E;
  margin: 18px 0 10px;
  padding-left: 4px;
  border-left: 3px solid #6D4C41;
  padding-left: 10px;
}

/* Cards container */
.cards-container {
  margin-bottom: 12px;
}

/* Modal */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#modal-overlay.hidden {
  display: none;
}

#modal-content {
  background: #fff;
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 420px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 20px 20px 28px;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 22px;
  color: #8D6E63;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-thumb {
  width: 120px;
  height: 160px;
  object-fit: cover;
  border-radius: 8px;
  background: #EFEBE9;
  margin: 8px auto 14px;
  display: block;
}

.modal-thumb-placeholder {
  width: 120px;
  height: 160px;
  border-radius: 8px;
  background: #EFEBE9;
  margin: 8px auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: #A1887F;
}

.modal-field {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.modal-field .label {
  font-weight: 600;
  color: #8D6E63;
  min-width: 56px;
  flex-shrink: 0;
}

.modal-field .value {
  color: #3E2723;
  flex: 1;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.modal-status {
  text-align: center;
  padding: 12px 0;
  margin: 14px 0;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
}

.modal-status.available {
  background: #E8F5E9;
  color: #2E7D32;
}

.modal-status.borrowed {
  background: #FFEBEE;
  color: #C62828;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: inherit;
}

.btn:active {
  opacity: 0.8;
}

.btn-primary {
  background: #6D4C41;
  color: #fff;
}

.btn-primary:disabled {
  background: #BCAAA4;
  cursor: not-allowed;
}

.btn-secondary {
  background: #EFEBE9;
  color: #5D4037;
}

.btn-danger {
  background: #E53935;
  color: #fff;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
  width: auto;
  display: inline-block;
  border-radius: 6px;
}

/* Forms */
.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #6D4C41;
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #D7CCC8;
  border-radius: 8px;
  font-size: 14px;
  color: #3E2723;
  background: #fff;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: #6D4C41;
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

/* Category tags */
.tag-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: #EFEBE9;
  border-radius: 16px;
  font-size: 12px;
  color: #5D4037;
}

.tag .tag-del {
  cursor: pointer;
  font-size: 14px;
  color: #A1887F;
  line-height: 1;
}

.tag .tag-del:hover {
  color: #E53935;
}

.add-category-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.add-category-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #D7CCC8;
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.add-category-row button {
  padding: 8px 14px;
  background: #6D4C41;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

/* PIN screen */
.pin-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 16px;
}

.pin-screen .pin-icon {
  font-size: 48px;
}

.pin-screen p {
  font-size: 14px;
  color: #8D6E63;
}

.pin-screen input {
  width: 160px;
  text-align: center;
  padding: 12px;
  font-size: 24px;
  letter-spacing: 8px;
  border: 2px solid #D7CCC8;
  border-radius: 10px;
  outline: none;
  font-family: inherit;
}

.pin-screen input:focus {
  border-color: #6D4C41;
}

.pin-error {
  color: #E53935;
  font-size: 13px;
}

/* Kakao search results */
.kakao-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.kakao-item {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #EFEBE9;
  align-items: center;
}

.kakao-item img {
  width: 48px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
  background: #EFEBE9;
  flex-shrink: 0;
}

.kakao-item .item-info {
  flex: 1;
  min-width: 0;
}

.kakao-item .item-info .item-title {
  font-size: 13px;
  font-weight: 600;
  color: #3E2723;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kakao-item .item-info .item-meta {
  font-size: 11px;
  color: #8D6E63;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kakao-item .btn {
  flex-shrink: 0;
}

/* Loans table */
.loans-section {
  margin-bottom: 20px;
}

.loans-subtitle {
  font-size: 14px;
  font-weight: 700;
  color: #4E342E;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: #EFEBE9;
  border-radius: 8px;
}

.loan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.loan-table th {
  background: #6D4C41;
  color: #fff;
  padding: 8px 6px;
  text-align: center;
  font-weight: 600;
  font-size: 11px;
}

.loan-table th:first-child {
  border-radius: 8px 0 0 0;
}

.loan-table th:last-child {
  border-radius: 0 8px 0 0;
}

.loan-table td {
  padding: 10px 6px;
  text-align: center;
  border-bottom: 1px solid #EFEBE9;
  vertical-align: middle;
}

.loan-table tr.overdue td {
  background: #FFF3F0;
}

.loan-table .overdue-badge {
  display: inline-block;
  background: #E53935;
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 700;
}

.loan-table .td-title {
  text-align: left;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #BCAAA4;
  font-size: 14px;
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
  display: block;
}

/* Toast */
#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #4E342E;
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 300;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: opacity 0.3s;
  white-space: nowrap;
}

#toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Loading */
.loading {
  text-align: center;
  padding: 20px;
  color: #8D6E63;
  font-size: 13px;
}

/* Admin settings */
.admin-section {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #EFEBE9;
}

.admin-section .section-title {
  margin-top: 0;
}

/* Responsive */
@media screen and (min-width: 421px) {
  #tab-content {
    max-width: 600px;
  }
}

@media screen and (min-width: 600px) {
  #tab-content {
    max-width: 720px;
  }
  .book-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
