/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --bg-subtle: #f7f7f5;
  --surface: #fafafa;
  --border: #e8e8e5;
  --border-strong: #d4d4cf;
  --text: #1a1a18;
  --text-muted: #6b6b65;
  --text-placeholder: #9c9c96;
  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-light: #fef3c7;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.06), 0 2px 4px rgba(0,0,0,.04);
  font-size: 15px;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ── Layout helpers ───────────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}
.logo:hover { color: var(--accent); }
.logo-icon { font-size: 1.25rem; }
.logo-tld { color: var(--accent); }

.nav { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--bg-subtle); }

/* ── Hero ─────────────────────────────────────────────────────────────────── */
.hero {
  padding: 64px 0 48px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}

.hero-sub {
  margin-top: 12px;
  font-size: 1.1rem;
  color: var(--text-muted);
}

/* ── Tool cards grid ──────────────────────────────────────────────────────── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  padding-bottom: 64px;
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  transition: box-shadow .15s, border-color .15s, transform .1s;
  cursor: pointer;
}

.tool-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.tool-icon { font-size: 2rem; }

.tool-card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.tool-card p {
  font-size: .9rem;
  color: var(--text-muted);
  flex: 1;
}

.tool-badge {
  display: inline-block;
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 10px;
  align-self: flex-start;
}

/* ── Tool page ────────────────────────────────────────────────────────────── */
.tool-page {
  padding: 48px 20px 80px;
  max-width: 720px;
}
.tool-page-wide { max-width: 1100px; }

.tool-header { margin-bottom: 32px; }
.tool-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.tool-header p {
  margin-top: 6px;
  color: var(--text-muted);
}

/* ── Upload form ──────────────────────────────────────────────────────────── */
.upload-form { display: flex; flex-direction: column; gap: 20px; }

.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  background: var(--bg-subtle);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.drop-zone p { font-weight: 500; margin-top: 8px; }
.drop-hint { font-size: .85rem; color: var(--text-muted); }
.drop-icon { font-size: 2.5rem; }
.drop-zone input[type=file] { display: none; }

.file-preview {
  padding: 10px 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  color: var(--text-muted);
}
.hidden { display: none; }

.img-preview-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-subtle);
}
.img-preview {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  display: block;
  background: #f0f0ed;
}
.preview-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
}
.preview-filename {
  font-size: .85rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
}
.preview-size {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Image compare ────────────────────────────────────────────────────────── */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}
@media (max-width: 520px) {
  .compare-grid { grid-template-columns: 1fr; }
}
.compare-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-subtle);
}
.compare-label {
  padding: 8px 14px;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.compare-img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  display: block;
  background: #f0f0ed;
}
.ratio-bar {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}
.ratio-badge {
  display: inline-block;
  padding: 6px 18px;
  border-radius: 100px;
  font-size: .9rem;
  font-weight: 600;
}
.ratio-good {
  background: #dcfce7;
  color: var(--success);
  border: 1px solid #86efac;
}
.ratio-neutral {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.result-download {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

/* ── Crop tool ────────────────────────────────────────────────────────────── */
.crop-preview-area {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.crop-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f0f0ed;
  line-height: 0;
}
#crop-canvas {
  display: block;
  max-width: 100%;
  cursor: crosshair;
}
.crop-result-wrap {
  background: #f0f0ed;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 80px;
}
#result-canvas {
  display: block;
  max-width: 100%;
}
.crop-dims-badge {
  font-size: .78rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 6px;
}

/* ── Format selector ──────────────────────────────────────────────────────── */
.format-selector { margin-bottom: 24px; }
.format-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.format-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.format-row select, select {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
  cursor: pointer;
  outline: none;
  min-width: 130px;
}
.format-row select:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}
.arrow { font-size: 1.2rem; color: var(--text-muted); margin-top: 18px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .7; cursor: not-allowed; }

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-copy {
  padding: 4px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-copy:hover { background: var(--bg-subtle); }

/* ── Range / fields ───────────────────────────────────────────────────────── */
.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-row label { font-weight: 500; font-size: .9rem; }
input[type=range] {
  width: 100%;
  accent-color: var(--accent);
}
.range-hints {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-muted);
}

.crop-fields { display: flex; flex-direction: column; gap: 12px; }
.crop-fields h3 { font-size: 1rem; font-weight: 600; }
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-muted);
}
.field-grid input[type=number] {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
}
.field-grid input[type=number]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}
.field-hint { font-size: .82rem; color: var(--text-muted); }

/* ── JSON tools ───────────────────────────────────────────────────────────── */
.split-pane { width: 100%; }
.split-form {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 700px) {
  .split-form { grid-template-columns: 1fr; }
}

.pane {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 420px;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.pane-actions { display: flex; align-items: center; gap: 8px; }

.pane textarea {
  flex: 1;
  border: none;
  padding: 16px;
  font-family: "Menlo", "Consolas", "Monaco", monospace;
  font-size: .85rem;
  line-height: 1.7;
  resize: none;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 100%;
  min-height: 380px;
}

.split-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding-top: 40px;
}

.json-view {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: var(--bg);
  min-height: 380px;
}
.json-view pre { font-family: "Menlo","Consolas","Monaco",monospace; font-size: .85rem; line-height: 1.7; }

/* JSON syntax highlight classes */
.jk { color: #6366f1; }      /* key */
.js { color: #16a34a; }      /* string value */
.jn { color: #d97706; }      /* number */
.jb { color: #7c3aed; }      /* boolean/null */
.jp { color: var(--text-muted); } /* punctuation */

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: .9rem;
}
.alert-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: var(--danger);
}

/* ── SEO info section ─────────────────────────────────────────────────────── */
.seo-info {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}
.seo-info h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; }
.seo-info ol { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.seo-info li { font-size: .9rem; color: var(--text-muted); }
.seo-info p { margin-top: 12px; font-size: .9rem; color: var(--text-muted); }

/* ── Footer ───────────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* Chat layout                                                                */
/* ─────────────────────────────────────────────────────────────────────────── */
body.chat-layout {
  height: 100dvh;
  overflow: hidden;
}

#layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
#sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-top {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-logo {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  display: block;
}
.sidebar-logo:hover { color: var(--accent); }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  transition: background .12s;
}
.new-chat-btn:hover { background: var(--accent-light); border-color: var(--accent); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-list-empty { font-size: .82rem; color: var(--text-placeholder); padding: 8px 12px; }

.chat-item-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: var(--radius-sm);
  padding-right: 4px;
}
.chat-item-row:hover { background: var(--border); }

.chat-item {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  font-size: .84rem;
  color: var(--text-muted);
  min-width: 0;
  text-decoration: none;
  transition: color .12s;
}
.chat-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.chat-item.active, .chat-item-row.is-active .chat-item { color: var(--text); font-weight: 500; }
.chat-item-row:hover .chat-item { color: var(--text); }

.chat-item-del {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s;
}
.chat-item-row:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { background: #fee2e2; color: var(--danger); }

/* ── Main ──────────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Welcome screen */
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}
.welcome-icon { font-size: 3rem; }
.chat-welcome h2 { font-size: 1.4rem; font-weight: 600; color: var(--text); }
.chat-welcome p { font-size: .95rem; }

/* Messages */
.message { display: flex; }
.user-msg { justify-content: flex-end; }
.assistant-msg { justify-content: flex-start; }

.msg-bubble {
  max-width: 72%;
  padding: 11px 15px;
  border-radius: 18px;
  word-break: break-word;
}

.user-msg .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.assistant-msg .msg-bubble {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown inside bubbles */
.msg-content { font-size: .93rem; line-height: 1.7; }
.msg-content p { margin: 0 0 .6em; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content pre {
  background: rgba(0,0,0,.06);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  font-size: .82rem;
  margin: .5em 0;
}
.msg-content code { font-family: "Menlo","Consolas",monospace; font-size: .88em; }
.msg-content pre code { font-size: 1em; }
.msg-content ul, .msg-content ol { padding-left: 1.4em; margin: .4em 0; }
.msg-content li { margin: .15em 0; }
.msg-content strong { font-weight: 600; }
.user-msg .msg-content pre { background: rgba(255,255,255,.15); }
.user-msg .msg-content code { color: inherit; }

/* Typing dots */
.typing-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  margin: 0 2px;
  animation: tdot 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes tdot {
  0%, 80%, 100% { transform: scale(.7); opacity: .5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input area ────────────────────────────────────────────────── */
#input-area {
  padding: 10px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

#input {
  flex: 1;
  border: none;
  background: none;
  resize: none;
  font-family: inherit;
  font-size: .95rem;
  line-height: 1.55;
  color: var(--text);
  outline: none;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 0;
}
#input::placeholder { color: var(--text-placeholder); }

#send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background .12s;
}
#send-btn:hover:not(:disabled) { background: var(--accent-hover); }
#send-btn:disabled { background: var(--border-strong); cursor: not-allowed; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 700px) {
  #sidebar { width: 210px; }
  .msg-bubble { max-width: 88%; }
}
@media (max-width: 500px) {
  #sidebar { display: none; }
}

/* ── Responsive (tool pages) ───────────────────────────────────── */
@media (max-width: 640px) {
  .nav-link { padding: 6px 10px; }
  .field-grid { grid-template-columns: 1fr; }
  .format-row { flex-direction: column; align-items: flex-start; }
  .arrow { display: none; }
}
