/* ── Catppuccin design tokens ── */
:root {
  /* dark theme — Catppuccin Macchiato */
  --font-mono: ui-monospace, monospace;
  --main-bg: #24273a;              /* Base */
  --main-border-color: #494d64;    /* Surface 1 */
  --text-color: #cad3f5;           /* Text */
  --text-muted-color: #a5adcb;     /* Subtext 0 */
  --heading-color: #cad3f5;        /* Text */
  --label-color: #b8c0e0;          /* Subtext 1 */
  --link-color: #8aadf4;           /* Blue */
  --sidebar-bg: #1e2030;           /* Mantle */
  --sidebar-border-color: #363a4f; /* Surface 0 */
  --card-bg: #1e2030;              /* Mantle */
  --card-hover-bg: #494d64;        /* Surface 1 */
  --btn-border-color: #363a4f;     /* Surface 0 */
  --button-bg: #1e2030;            /* Mantle */
  --input-bg: #363a4f;             /* Surface 0 — visibly distinct from card bg */
  --accent-color: #c6a0f6;         /* Mauve */
  --accent-hover: #b7bdf8;         /* Lavender */
  --accent-bg: color-mix(in srgb, #c6a0f6 12%, #24273a);
  --accent-text: #c6a0f6;          /* Mauve */
  --error-color: #ed8796;          /* Red */
}

@media (prefers-color-scheme: light) {
  :root {
    /* light theme — Catppuccin Latte */
    --main-bg: #eff1f5;              /* Base */
    --main-border-color: #bcc0cc;    /* Surface 1 */
    --text-color: #4c4f69;           /* Text */
    --text-muted-color: #6c6f85;     /* Subtext 0 */
    --heading-color: #4c4f69;        /* Text */
    --label-color: #5c5f77;          /* Subtext 1 */
    --link-color: #1e66f5;           /* Blue */
    --sidebar-bg: #e6e9ef;           /* Mantle */
    --sidebar-border-color: #ccd0da; /* Surface 0 */
    --card-bg: #e6e9ef;              /* Mantle */
    --card-hover-bg: #ccd0da;        /* Surface 0 */
    --btn-border-color: #ccd0da;     /* Surface 0 */
    --button-bg: #eff1f5;            /* Base */
    --input-bg: #ffffff;             /* Pure white — maximum contrast in light mode */
    --accent-color: #8839ef;         /* Mauve */
    --accent-hover: #7287fd;         /* Lavender */
    --accent-bg: color-mix(in srgb, #8839ef 10%, #eff1f5);
    --accent-text: #8839ef;          /* Mauve */
    --error-color: #d20f39;          /* Red */
  }
}

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

body {
  font-family: "Source Sans 3", "Source Sans Pro", "Microsoft Yahei", sans-serif;
  background: var(--main-bg);
  color: var(--text-color);
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* ── Layout ── */
.container {
  width: 100%;
  max-width: 1200px;
  align-self: center;
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr;
  gap: 1rem 1.5rem;
  flex: 1;
  padding: 1rem;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

h1 {
  font-family: "Lato", "Microsoft Yahei", sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
  color: var(--heading-color);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* ── Left panel ── */
.panel-left {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 3.5rem);
  position: sticky;
  top: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--btn-border-color) transparent;
  padding-right: 0.25rem;
}

/* ── Right panel ── */
.panel-right {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Type tabs ── */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tab {
  padding: 0.18rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--btn-border-color);
  background: var(--button-bg);
  color: var(--label-color);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s, color 0.1s;
  white-space: nowrap;
  user-select: none;
}

.tab:hover {
  border-color: var(--text-muted-color);
  color: var(--text-color);
}

.tab.active {
  background: var(--accent-bg);
  border-color: var(--accent-color);
  color: var(--accent-text);
}

/* ── Form fields ── */
.fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--label-color);
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.48rem 0.65rem;
  border: 1px solid var(--main-border-color);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text-color);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.1s;
  appearance: auto;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-color);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted-color);
  opacity: 0.7;
}

textarea {
  resize: vertical;
  min-height: 76px;
  line-height: 1.45;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.25rem 0;
}

.check-field label {
  margin: 0;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent-color);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Sidebar options ── */
.options-section {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.option {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

input[type="color"] {
  width: 100%;
  height: 32px;
  border: 1px solid var(--btn-border-color);
  border-radius: 6px;
  padding: 2px 3px;
  cursor: pointer;
  background: var(--button-bg);
}

input[type="color"]:focus {
  outline: none;
  border-color: var(--accent-color);
}

/* toggle group (reused from image-tools pattern) */
.toggle-group {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--btn-border-color);
  width: 100%;
}

.toggle-btn {
  flex: 1;
  padding: 0.28rem 0.5rem;
  border: none;
  border-right: 1px solid var(--btn-border-color);
  background: var(--button-bg);
  color: var(--text-muted-color);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  text-align: center;
}

.toggle-btn:last-child {
  border-right: none;
}

.toggle-btn:hover {
  background: var(--sidebar-bg);
  color: var(--text-color);
}

.toggle-btn.active {
  background: var(--accent-bg);
  color: var(--accent-text);
}

/* ── Generate button ── */
.process-btn {
  width: 100%;
  padding: 0.65rem;
  border-radius: 8px;
  border: none;
  background: var(--accent-color);
  color: var(--main-bg);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
  margin-top: 0.25rem;
}

.process-btn:hover {
  background: var(--accent-hover);
}

/* ── Workspace (right panel) ── */
.workspace {
  flex: 1;
  background: var(--sidebar-bg);
  border: 1px solid var(--main-border-color);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  padding: 1.5rem;
}

.workspace-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted-color);
  font-size: 0.88rem;
  user-select: none;
  text-align: center;
}

.workspace-empty-icon {
  font-size: 2.5rem;
  line-height: 1;
  opacity: 0.25;
}

.workspace-empty-sub {
  font-size: 0.75rem;
  opacity: 0.65;
}

/* ── QR output ── */
.output {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  width: 100%;
}

.output.visible {
  display: flex;
}

#qr-wrap {
  display: inline-block;
  padding: 0.85rem;
  background: #fff;
  border-radius: 8px;
  line-height: 0;
  border: 1px solid var(--main-border-color);
  box-shadow: 0 2px 12px rgb(0 0 0 / 18%);
}

.download-btn {
  padding: 0.4rem 1.25rem;
  background: var(--button-bg);
  border: 1px solid var(--btn-border-color);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--label-color);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.1s, color 0.1s;
}

.download-btn:hover {
  border-color: var(--text-muted-color);
  color: var(--text-color);
}

.encoded {
  width: 100%;
  max-width: 480px;
  padding: 0.5rem 0.65rem;
  background: var(--card-bg);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted-color);
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.45;
}

.error-msg {
  font-size: 0.82rem;
  color: var(--error-color);
  text-align: center;
}

.divider {
  border: none;
  border-top: 1px solid var(--main-border-color);
  margin: 0.25rem 0;
}

/* ── Footer ── */
footer {
  background: var(--sidebar-bg);
  border-top: 1px solid var(--main-border-color);
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  color: var(--text-muted-color);
}

footer a {
  color: var(--link-color);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ── Responsive ── */
@media (max-width: 760px) {
  .container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .app-header {
    grid-column: 1;
  }

  .panel-left {
    max-height: none;
    position: static;
    overflow: visible;
  }

  .panel-right {
    grid-column: 1;
  }

  .workspace {
    min-height: 260px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  footer {
    flex-direction: column;
    gap: 0.4rem;
    text-align: center;
  }
}
