/* ── MetaClean — Modern Metadata Cleaner ── */

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

:root {
  --bg: #0b0b12;
  --surface: #13131e;
  --surface2: #1a1a2a;
  --surface3: #222236;
  --border: #2c2c42;
  --border-hover: #4a4a6a;
  --text: #e8e8f4;
  --text-dim: #8888a4;
  --text-muted: #55556a;
  --accent: #00c9a7;
  --accent-glow: rgba(0, 201, 167, 0.2);
  --accent-hover: #00e6bf;
  --danger: #ff4d6a;
  --danger-glow: rgba(255, 77, 106, 0.2);
  --warning: #ffb84d;
  --radius: 14px;
  --radius-sm: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.25s ease;
}

html { scroll-behavior: smooth }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Gradient bg */
body::before {
  content: '';
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(0,201,167,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 85%, rgba(0,120,255,0.04) 0%, transparent 50%);
  animation: bgDrift 25s ease-in-out infinite alternate;
  z-index: -1;
  pointer-events: none;
}
@keyframes bgDrift {
  0%   { transform: translate(0, 0) }
  100% { transform: translate(-3%, 3%) }
}

/* ── Header ── */
header {
  text-align: center;
  padding: 60px 24px 28px;
}

.logo {
  font-size: 3rem;
  margin-bottom: 10px;
  display: inline-block;
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1) }
  50% { transform: scale(1.08) }
}

h1 {
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, #00c9a7 60%, #0af 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 1.05rem;
  max-width: 440px;
  margin: 0 auto;
}

/* ── Main ── */
main {
  flex: 1;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* ── Drop Zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  background: var(--surface);
}
.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(0,201,167,0.04);
  box-shadow: 0 0 40px var(--accent-glow);
}
.drop-zone.hidden { display: none }

.drop-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.7;
}
.drop-text {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 6px;
}
.drop-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.browse-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font-weight: 500;
}
.browse-link:hover { color: var(--accent-hover) }

/* ── File Bar ── */
.file-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.file-bar.hidden { display: none }

.file-bar-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.file-bar-icon { font-size: 1.8rem; flex-shrink: 0; }
.file-bar-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}
.file-bar-size {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.file-bar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-icon { font-size: 1rem; }

.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #ff6680;
  box-shadow: 0 4px 20px var(--danger-glow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  padding: 10px 12px;
}
.btn-ghost:hover { color: var(--text); background: var(--surface2); }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-outline:hover {
  background: rgba(0,201,167,0.1);
}

.btn-small {
  padding: 6px 14px;
  font-size: 0.82rem;
}

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

/* ── Progress ── */
.progress-wrap {
  margin-bottom: 20px;
}
.progress-wrap.hidden { display: none }

.progress-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #0af);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-text {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 6px;
  text-align: center;
}

/* ── Metadata Section ── */
.meta-section { margin-top: 0; }
.meta-section.hidden { display: none }

.meta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.meta-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
}
.meta-count {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 400;
}
.meta-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.meta-search {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
  width: 200px;
  transition: border-color var(--transition);
}
.meta-search:focus {
  outline: none;
  border-color: var(--accent);
}

/* Add field form */
.add-field-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.add-field-form.hidden { display: none }

.input-field {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
}
.input-field:focus {
  outline: none;
  border-color: var(--accent);
}

/* Metadata table */
.meta-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.meta-group-header {
  padding: 10px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.meta-group-header:hover { background: var(--surface3) }
.meta-group-header .chevron {
  transition: transform var(--transition);
  font-size: 0.7rem;
}
.meta-group-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.meta-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 2fr auto;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  align-items: stretch;
}
.meta-row:last-child { border-bottom: none }
.meta-row:hover { background: rgba(255,255,255,0.02) }
.meta-row.hidden { display: none }

.meta-key {
  padding: 10px 16px;
  font-size: 0.82rem;
  font-family: var(--mono);
  color: var(--text-dim);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  word-break: break-all;
}

.meta-value {
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text);
  display: flex;
  align-items: center;
  word-break: break-all;
  min-height: 40px;
}
.meta-value.editable {
  cursor: text;
}
.meta-value.editable:hover {
  background: var(--surface2);
}

.meta-value input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
}
.meta-value input:focus { outline: none }

.meta-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
}

.meta-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.meta-btn:hover {
  background: var(--surface3);
  color: var(--text);
}
.meta-btn.save-btn:hover { color: var(--accent) }
.meta-btn.del-btn:hover { color: var(--danger) }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-size: 0.9rem;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none }
.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }

/* ── Footer ── */
footer {
  text-align: center;
  padding: 28px 24px;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
}
footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover { text-decoration: underline }

/* ── Responsive ── */
@media (max-width: 640px) {
  header { padding: 40px 16px 20px }
  main { padding: 20px 12px 48px }
  .drop-zone { padding: 32px 16px }
  .file-bar { flex-direction: column; align-items: stretch; gap: 12px }
  .file-bar-actions { justify-content: flex-end }
  .meta-row { grid-template-columns: 1fr; }
  .meta-key { border-right: none; border-bottom: 1px solid var(--border); padding: 8px 12px }
  .meta-value { padding: 8px 12px }
  .meta-search { width: 140px }
  .meta-header { flex-direction: column; align-items: flex-start }
  .add-field-form { flex-direction: column }
  .file-bar-name { max-width: 200px }
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px) }
  to { opacity: 1; transform: translateY(0) }
}
.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
