/* tokuSolutions - Clean CSS */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f3eb;
  color: #333;
  min-height: 100vh;
}

/* Header */
header {
  background: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #e94560;
}

h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #333;
}

/* Buttons */
.btn {
  background: #e94560;
  color: white;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 500;
}

.btn:hover {
  background: #d63651;
}

.btn-secondary {
  background: #718096;
}

.btn-secondary:hover {
  background: #4a5568;
}

.btn-success {
  background: #48bb78;
}

.btn-success:hover {
  background: #38a169;
}

/* Controls */
.controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.page-nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.page-nav span {
  font-size: 0.85rem;
  color: #4a5568;
  min-width: 80px;
  text-align: center;
}

/* Utility */
.hidden {
  display: none;
}

/* Dropdown */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  cursor: pointer;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  min-width: 200px;
  z-index: 1000;
  margin-top: 0.25rem;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-menu a {
  display: block;
  padding: 0.5rem 1rem;
  color: #333;
  text-decoration: none;
  font-size: 0.85rem;
  border-bottom: 1px solid #f7fafc;
}

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

.dropdown-menu a:hover {
  background: #f7fafc;
  color: #e94560;
}

/* Loading Spinner */
.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  border-top-color: #4a5568;
  animation: spin 0.8s linear infinite;
  margin-right: 0.5rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3rem;
  color: #718096;
}

.loading-container.hidden {
  display: none !important;
}

/* ============================================
   HOME VIEW - Manual Grid
   ============================================ */

#homeView .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.page-header {
  text-align: center;
  margin-bottom: 3rem;
}

#homeView h1 {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: #1a202c;
}

.subtitle {
  color: #718096;
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.6;
  max-width: 700px;
  margin: 0 auto 2.5rem;
}

.search-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.search-box {
  width: 100%;
  max-width: 500px;
}

.search-box input {
  width: 100%;
  padding: 0.5rem 1rem;
  border: 2px solid #cbd5e0;
  border-radius: 8px;
  font-size: 1rem;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: #e94560;
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.1);
}

.tag-filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.tag-filter {
  padding: 0.4rem 0.8rem;
  border: 2px solid var(--tag-color, #cbd5e0);
  background: white;
  color: var(--tag-color, #4a5568);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.tag-filter:hover {
  background: var(--tag-color, #cbd5e0);
  color: white;
  transform: translateY(-1px);
}

.tag-filter.active {
  background: var(--tag-color, #cbd5e0);
  color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stats {
  color: #718096;
  font-size: 0.9rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition:
    transform 0.2s,
    box-shadow 0.2s;
  cursor: pointer;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.card-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.thumbnail {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: #e2e8f0;
}

.card-content {
  padding: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #1a202c;
  line-height: 1.4;
}

.card-tags {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.card-tags .tag {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
}

.card-meta {
  font-size: 0.85rem;
  color: #718096;
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  background: #e2e8f0;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #f0f0f0;
}

.card-actions a {
  font-size: 0.8rem;
  color: #4a5568;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.card-actions a:hover {
  color: #2d3748;
  text-decoration: underline;
}

.no-results {
  text-align: center;
  padding: 3rem;
  color: #718096;
}

footer {
  padding-top: 2rem;
  border-top: 1px solid #e2e8f0;
  text-align: center;
  color: #718096;
  font-size: 0.875rem;
}

/* ============================================
   VIEWER - Side-by-side layout
   ============================================ */

#viewerView {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  flex-direction: column;
  height: 100vh;
  z-index: 100;
}

#viewerView:not(.hidden) {
  display: flex;
}

#viewerView header {
  flex-shrink: 0;
}

.viewer-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.page-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: #eae8e0;
}

.page {
  position: relative;
  margin: 0 auto 1.5rem;
  max-width: 1200px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: max-width 0.3s ease;
}

.page img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
}

.overlay {
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  padding: 2px;
  font-size: 10px;
  line-height: 1.15;
  color: #000;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
  border: 1px solid transparent;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.overlay:hover,
.overlay.highlight {
  background: rgba(255, 248, 220, 0.98);
  border-color: #d69e2e;
  z-index: 20;
  box-shadow: 0 0 0 2px #d69e2e;
}

.overlay.bbox-editing {
  background: rgba(72, 187, 120, 0.3);
  border-color: #48bb78;
  z-index: 30;
  box-shadow: 0 0 0 3px #48bb78;
  animation: pulse-bbox 1.5s ease-in-out infinite;
}

@keyframes pulse-bbox {
  0%,
  100% {
    box-shadow: 0 0 0 3px #48bb78;
  }
  50% {
    box-shadow: 0 0 0 5px #48bb78;
  }
}

.page-label {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 3px 10px;
  border-radius: 3px;
  font-size: 0.8rem;
}

.text-panel {
  width: 380px;
  min-width: 320px;
  background: #fff;
  border-left: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
  transition: transform 0.3s ease;
}

.sidebar-toggle-btn {
  position: absolute;
  left: -15px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 60px;
  background: #e94560;
  border: none;
  border-radius: 8px 0 0 8px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.sidebar-toggle-btn:hover {
  background: #d63651;
  left: -17px;
}

.sidebar-toggle-btn i {
  transition: transform 0.3s ease;
  font-size: 1rem;
}

.text-panel.sidebar-hidden .sidebar-toggle-btn i {
  transform: rotate(180deg);
}

.text-panel-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #eee;
  background: #fafafa;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text-panel-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #555;
  margin: 0;
}

.text-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-left 0.2s ease;
}

.text-item:hover {
  background: #f9f9f9;
}

.text-item.editing {
  border-left: 3px solid #48bb78;
  background: #f0fff4;
  box-shadow: 0 2px 8px rgba(72, 187, 120, 0.2);
}

.text-item.highlight {
  background: #fff8dc;
  border-left: 3px solid #d69e2e;
}

.text-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.text-original {
  font-size: 0.85rem;
  color: #333;
  flex: 1;
}

.delete-btn {
  font-size: 0.9rem;
  padding: 0.15rem 0.4rem;
  background: #fee;
  color: #c53030;
  border: 1px solid #fc8181;
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition:
    background 0.2s,
    color 0.2s;
}

.delete-btn:hover {
  background: #fc8181;
  color: white;
}

.text-translation {
  font-size: 0.8rem;
  color: #666;
  padding: 0.25rem;
  border-radius: 2px;
  transition: background 0.15s;
}

.text-item.editing .text-translation {
  cursor: text;
}

.text-translation[contenteditable='true'] {
  background: #fff;
  border: 1px solid #48bb78;
  outline: none;
}

.bbox-editor {
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  transition:
    background 0.2s,
    border-color 0.2s;
}

.bbox-editor.hidden {
  display: none;
}

.bbox-editor.active {
  background: #e6fffa;
  border-color: #48bb78;
}

.bbox-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.bbox-field {
  display: flex;
  flex-direction: column;
}

.bbox-field label {
  color: #4a5568;
  margin-bottom: 0.2rem;
  font-size: 0.7rem;
}

.bbox-field input {
  padding: 0.3rem;
  border: 1px solid #cbd5e0;
  border-radius: 3px;
  font-size: 0.75rem;
}

.bbox-field input:focus {
  outline: none;
  border-color: #e94560;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .viewer-container {
    flex-direction: column;
  }

  .text-panel {
    width: 100%;
    border-left: none;
    border-top: 2px solid #ddd;
    max-height: 40vh;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .controls {
    width: 100%;
  }
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  margin-top: 3rem;
  color: #666;
  font-size: 0.875rem;
}

.footer-link {
  color: #666;
  text-decoration: none;
  transition: color 0.2s;
}

.footer-link:hover {
  color: #e94560;
}

.footer-separator {
  margin: 0 0.75rem;
  color: #ccc;
}
