/* ========== RESET & BASE ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  --color-border: #e0e0e0;
  --color-text: #1a1a1a;
  --color-text-muted: #666666;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-warning: #f59e0b;
  --color-drop-bg: #f0f7ff;
  --color-drop-border: #93c5fd;
  --color-code-bg: #1e1e1e;
  --color-code-text: #d4d4d4;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
  --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ========== HEADER ========== */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header__title {
  font-size: 18px;
  font-weight: 600;
  padding: 12px 0 0;
  letter-spacing: -0.3px;
}

/* ========== TABS ========== */
.tabs {
  display: flex;
  gap: 0;
  margin-top: 8px;
}

.tabs__btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.tabs__btn:hover {
  color: var(--color-text);
}

.tabs__btn--active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* ========== MAIN ========== */
.app-main {
  padding: 20px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ========== TAB PANELS ========== */
.tab-panel {
  display: none;
}

.tab-panel--active {
  display: block;
}

/* ========== PANELS ========== */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  background: #fafafa;
}

.panel__header h2 {
  font-size: 14px;
  font-weight: 600;
}

.panel__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== LAYOUTS ========== */
.converter-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-height: calc(100vh - 140px);
}

.splitter-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.photos-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ========== DROP ZONE ========== */
.drop-zone {
  padding: 40px 20px;
  text-align: center;
  transition: background 0.2s, border-color 0.2s;
}

.drop-zone--dragover {
  background: var(--color-drop-bg);
}

.drop-zone__prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--color-text-muted);
}

.drop-zone__prompt svg {
  opacity: 0.4;
}

.drop-zone__prompt p {
  font-size: 14px;
}

.drop-zone__or {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.5;
}

.drop-zone__file-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  background: var(--color-drop-bg);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}

/* ========== PASTE AREA ========== */
.paste-area {
  padding: 16px;
  border-top: 1px solid var(--color-border);
}

.paste-area label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.paste-area textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
  line-height: 1.6;
}

.paste-area textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ========== OUTPUT AREA ========== */
.output-area {
  padding: 0;
  overflow: auto;
  max-height: 500px;
}

.output-area pre {
  margin: 0;
  padding: 16px;
  background: var(--color-code-bg);
  color: var(--color-code-text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 200px;
}

/* ========== PREVIEW ========== */
.preview-area {
  border-top: 1px solid var(--color-border);
}

.preview-frame {
  padding: 20px;
  max-height: 400px;
  overflow: auto;
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn:hover {
  background: #f0f0f0;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.btn--primary:hover {
  background: var(--color-primary-hover);
}

.btn--success {
  background: var(--color-success);
  border-color: var(--color-success);
  color: white;
}

.btn--danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: white;
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
}

.btn--ghost:hover {
  background: #f0f0f0;
}

.btn--sm {
  padding: 4px 10px;
  font-size: 13px;
}

/* ========== SELECT ========== */
.select {
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: 13px;
  cursor: pointer;
}

.select:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* ========== CANDIDATES LIST ========== */
.candidates-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}

.candidate-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.candidate-block__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fafafa;
  border-bottom: 1px solid var(--color-border);
}

.candidate-block__name-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
}

.candidate-block__name-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.candidate-block__text {
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text-muted);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.candidate-block__output {
  border-top: 1px solid var(--color-border);
  background: var(--color-code-bg);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-code-text);
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.candidate-block__actions {
  display: flex;
  gap: 6px;
}

/* ========== PHOTO GRID ========== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 16px;
}

.photo-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s;
}

.photo-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.photo-card--processed {
  border-color: var(--color-success);
}

.photo-card__image {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  background: #eee;
}

.photo-card__info {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-card__processed-name {
  padding: 4px 10px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-success);
  font-family: var(--font-mono);
}

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal__content {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal__header h2 {
  font-size: 16px;
}

.modal__close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 4px;
  line-height: 1;
}

.modal__close:hover {
  color: var(--color-text);
}

.modal__body {
  padding: 20px;
  display: flex;
  gap: 20px;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  background: #fafafa;
}

/* ========== CROP ========== */
.crop-container {
  flex: 1;
  min-width: 0;
  max-height: 400px;
  overflow: hidden;
  background: #333;
  border-radius: var(--radius-sm);
}

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

.crop-fields {
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.field input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filename-preview {
  padding: 8px 10px;
  background: var(--color-code-bg);
  color: var(--color-code-text);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
}

/* ========== HIDDEN ATTRIBUTE ========== */
[hidden] {
  display: none !important;
}

/* ========== LOADING ========== */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.85);
  z-index: 500;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 18px;
  background: var(--color-text);
  color: white;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: toast-in 0.3s ease-out;
}

.toast--success {
  background: var(--color-success);
}

.toast--error {
  background: var(--color-danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .converter-layout {
    grid-template-columns: 1fr;
  }

  .modal__body {
    flex-direction: column;
  }

  .crop-fields {
    width: 100%;
  }

  .app-main {
    padding: 12px;
  }
}
