*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232635;
  --border: #2e3148;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --text: #e2e4f0;
  --text-muted: #8b8fa8;
  --error: #ef4444;
  --radius: 10px;
  --sidebar-w: 200px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ===== App shell ===== */
.app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.logo { font-size: 15px; font-weight: 700; padding: 0 16px 14px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.nav-btn {
  display: block; width: 100%; background: none; border: none;
  color: var(--text-muted); text-align: left; padding: 9px 16px;
  cursor: pointer; font-size: 13px; transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }

/* ===== Hamburger ===== */
.menu-toggle {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 400;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 11px; cursor: pointer; font-size: 18px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 300; opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: all; }

/* ===== Main ===== */
.main { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 0; min-width: 0; }

/* ===== 2-Column layout ===== */
.content-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
  flex: 1;
}

/* ===== LEFT PANE ===== */
.left-pane {
  display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 20px;
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); transition: border-color 0.2s, background 0.2s; cursor: pointer;
}
.upload-zone.dragover { border-color: var(--accent); background: rgba(99,102,241,0.08); }
.upload-inner { padding: 24px 16px; text-align: center; }
.upload-icon { font-size: 32px; display: block; margin-bottom: 8px; }
.upload-inner p { color: var(--text-muted); font-size: 13px; line-height: 1.6; }
.upload-inner .hint { font-size: 11px; margin-top: 6px; color: var(--text-muted); }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* Preview stack (vertical) */
.preview-stack { display: flex; flex-direction: column; gap: 10px; }
.preview-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.preview-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; align-self: flex-start; }
.preview-box img { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: 6px; background: #111; }
.preview-info { font-size: 11px; color: var(--text-muted); align-self: flex-start; word-break: break-all; }
.result-box .btn { width: 100%; margin-top: 2px; }

/* EXIF table */
#exifDisplay {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; overflow-x: auto;
}
#exifDisplay table { width: 100%; border-collapse: collapse; font-size: 12px; }
#exifDisplay th, #exifDisplay td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; }
#exifDisplay th { color: var(--text-muted); font-weight: 500; white-space: nowrap; }
#exifDisplay a { color: var(--accent); }

/* ===== RIGHT PANE ===== */
.right-pane { min-width: 0; }

/* ===== Panel ===== */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; gap: 16px;
}
.panel h2 { font-size: 18px; font-weight: 600; }
.panel-desc { color: var(--text-muted); font-size: 13px; line-height: 1.6; }
.panel-subhead { font-size: 13px; font-weight: 600; }
.divider { border: none; border-top: 1px solid var(--border); }

.panel label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-muted); }
.panel label input,
.panel label select {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 9px 12px; font-size: 13px; outline: none; width: 100%;
}
.panel label input:focus, .panel label select:focus { border-color: var(--accent); }
.panel label input[type="range"] { padding: 4px 0; background: none; border: none; cursor: pointer; accent-color: var(--accent); }
.panel label input[type="color"] { padding: 2px; width: 60px; height: 36px; cursor: pointer; }
.panel label input[type="file"] { padding: 7px; }
.panel p { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.panel code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-size: 12px; color: var(--accent); }

/* 2-column input row */
.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Quality marks */
.quality-marks { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); padding: 0 2px; margin-top: -8px; }

/* Info box */
.info-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font-size: 13px; color: var(--text-muted);
}
.info-icon { font-size: 18px; flex-shrink: 0; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 7px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 500; text-decoration: none;
  transition: background 0.15s, transform 0.1s; white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.button-group { display: flex; flex-wrap: wrap; gap: 8px; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 4px; background: var(--surface2); border-radius: 8px; padding: 4px; }
.tab-btn {
  flex: 1; background: none; border: none; color: var(--text-muted);
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 12px;
  transition: background 0.15s, color 0.15s; white-space: nowrap;
}
.tab-btn.active { background: var(--accent); color: #fff; }

/* ===== Filter grid ===== */
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filter-btn {
  padding: 16px 10px; border-radius: 8px; border: 2px solid var(--border);
  background: var(--surface2); color: var(--text); cursor: pointer;
  font-size: 13px; transition: border-color 0.15s, background 0.15s; text-align: center;
}
.filter-btn:hover { border-color: var(--accent); }
.filter-btn.selected { border-color: var(--accent); background: rgba(99,102,241,0.15); color: var(--accent); }

/* ===== Loading ===== */
.loading {
  position: fixed; inset: 0; background: rgba(15,17,23,0.78);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; z-index: 500; backdrop-filter: blur(4px);
}
.spinner {
  width: 44px; height: 44px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 20px;
  border-radius: 8px; font-size: 13px; font-weight: 500; z-index: 600;
  max-width: 380px; animation: slideIn 0.3s ease;
}
.toast.error { background: #7f1d1d; border: 1px solid var(--error); color: #fca5a5; }
@keyframes slideIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Tablet (< 1000px) ===== */
@media (max-width: 1000px) {
  :root { --sidebar-w: 180px; }
  .content-layout { grid-template-columns: 270px 1fr; gap: 14px; }
  .main { padding: 14px; }
}

/* ===== Mobile (< 680px) ===== */
@media (max-width: 680px) {
  /* Hamburger */
  .menu-toggle { display: block; }
  .sidebar-overlay { display: block; }

  /* Sidebar drawer */
  .sidebar {
    position: fixed; left: calc(-1 * var(--sidebar-w) - 4px); top: 0;
    height: 100%; z-index: 350; transition: left 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .sidebar.open { left: 0; }

  /* Layout */
  .app { flex-direction: column; }
  .main { padding: 10px; padding-top: 50px; }

  /* 1 cột */
  .content-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Left pane không sticky nữa */
  .left-pane { position: static; }

  /* Preview ngang */
  .preview-stack { flex-direction: row; }
  .preview-box { flex: 1; min-width: 0; }
  .preview-box img { max-height: 150px; }

  /* Panel */
  .panel { padding: 14px; gap: 12px; }
  .panel h2 { font-size: 16px; }
  .panel > .btn { width: 100%; }
  .button-group { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .button-group .btn { width: 100%; }
  .input-row { grid-template-columns: 1fr; gap: 8px; }

  /* Toast */
  .toast { right: 10px; left: 10px; max-width: none; bottom: 14px; }
}
