/* GL Builder — Fluent-inspired acrylic theme */
:root {
  --md-bg: #e8eef8;
  --md-surface: rgba(255, 255, 255, 0.72);
  --md-surface-solid: #ffffff;
  --md-on-surface: #1a1c1e;
  --md-surface-variant: rgba(225, 226, 232, 0.65);
  --md-on-surface-variant: #44474e;
  --md-primary: #0b57d0;
  --md-on-primary: #ffffff;
  --md-secondary: #535f70;
  --md-on-secondary: #ffffff;
  --md-tertiary: #7d5260;
  --md-on-tertiary: #ffffff;
  --md-error: #ba1a1a;
  --md-on-error: #ffffff;
  --md-error-container: #ffdad6;
  --md-on-error-container: #410002;
  --md-outline: #747775;
  --md-outline-variant: rgba(196, 199, 197, 0.7);
  --md-border-radius: 12px;
  --md-input-radius: 8px;
  --md-button-radius: 10px;
  --acrylic-blur: 18px;
  --acrylic-saturate: 140%;
  --acrylic-tint: rgba(252, 253, 255, 0.88);
  --acrylic-border: rgba(255, 255, 255, 0.55);
  --acrylic-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.65);
  --md-elevation: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(11, 87, 208, 0.06);
  --header-height: 64px;
  --ambient-1: #c5d8f5;
  --ambient-2: #e8f0fa;
  --ambient-3: #d4e4f7;
  --ambient-4: #f2f6fc;
}

body.dark-theme {
  --md-bg: #0f1218;
  --md-surface: rgba(30, 34, 42, 0.72);
  --md-surface-solid: #1e222a;
  --md-on-surface: #e2e2e6;
  --md-surface-variant: rgba(68, 71, 78, 0.55);
  --md-on-surface-variant: #c4c7c5;
  --md-primary: #a8c7fa;
  --md-on-primary: #062e6f;
  --md-secondary: #bbc7db;
  --md-on-secondary: #253140;
  --md-tertiary: #efb8c8;
  --md-on-tertiary: #492532;
  --md-error: #ffb4ab;
  --md-on-error: #690005;
  --md-error-container: #93000a;
  --md-on-error-container: #ffdad6;
  --md-outline: #8e918f;
  --md-outline-variant: rgba(68, 71, 70, 0.8);
  --acrylic-tint: rgba(22, 26, 34, 0.92);
  --acrylic-border: rgba(255, 255, 255, 0.08);
  --acrylic-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  --md-elevation: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.35);
  --ambient-1: #1a2740;
  --ambient-2: #121820;
  --ambient-3: #243454;
  --ambient-4: #0e1218;
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  background-color: var(--md-bg);
  color: var(--md-on-surface);
  margin: 0;
  line-height: 1.5;
  min-height: 100vh;
  /* Avoid background-attachment: fixed — it makes scroll janky on many browsers */
  background-image:
    radial-gradient(1200px 600px at 10% -10%, var(--ambient-1), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, var(--ambient-3), transparent 50%),
    linear-gradient(160deg, var(--ambient-4), var(--md-bg));
}

body.electron-shell {
  background-image: none;
  background-color: transparent;
}

h1, h2, h3 { font-weight: 600; margin-top: 0; color: var(--md-on-surface); }
h1 { font-size: 1.35rem; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; margin-bottom: 12px; }

/* Panels: opaque-ish surfaces (no per-panel blur — that kills scroll perf) */
.acrylic {
  background: var(--acrylic-tint);
  border: 1px solid var(--acrylic-border);
  box-shadow: var(--acrylic-highlight), var(--md-elevation);
  position: relative;
  overflow: hidden;
}

/* Sticky header only: light acrylic blur */
.app-header.acrylic {
  background: color-mix(in srgb, var(--acrylic-tint) 82%, transparent);
  -webkit-backdrop-filter: blur(var(--acrylic-blur)) saturate(var(--acrylic-saturate));
  backdrop-filter: blur(var(--acrylic-blur)) saturate(var(--acrylic-saturate));
  /* Promote to own layer so scroll doesn't constantly reblur page content */
  transform: translateZ(0);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .app-header.acrylic,
  .acrylic {
    background: var(--md-surface-solid);
  }
}

/* Login */
#login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.m3-auth-card {
  max-width: 440px;
  width: 100%;
  padding: 48px 40px;
  border-radius: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.auth-logo { max-width: 240px; height: auto; margin-bottom: 28px; }
body.dark-theme .auth-logo {
  background: rgba(255, 255, 255, 0.92);
  padding: 10px 20px;
  border-radius: 12px;
}
.auth-title { font-size: 1.65rem; font-weight: 600; margin-bottom: 10px; }
.auth-subtitle {
  font-size: 0.98rem;
  color: var(--md-on-surface-variant);
  margin-bottom: 32px;
  line-height: 1.5;
}
.m3-error-container {
  background-color: var(--md-error-container);
  color: var(--md-on-error-container);
  padding: 14px 16px;
  border-radius: 12px;
  margin-top: 24px;
  font-size: 0.95rem;
  font-weight: 500;
  display: none;
  width: 100%;
  text-align: left;
}

/* App chrome */
.app-shell { min-height: 100vh; padding-bottom: 40px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
}

.app-header-inner {
  max-width: 1680px;
  margin: 0 auto;
  padding: 8px 18px;
  display: grid;
  grid-template-columns: minmax(160px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 20px;
  min-height: 56px;
}

.header-brand { min-width: 0; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}
.brand-mark-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.92);
  padding: 3px;
  box-sizing: border-box;
}
body.dark-theme .brand-mark-icon {
  background: rgba(255, 255, 255, 0.95);
}
.brand-mark-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.brand-title {
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 0.72rem;
  color: var(--md-on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-start;
  flex-wrap: wrap;
  min-width: 0;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--md-on-surface);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.nav-link:hover {
  background: rgba(11, 87, 208, 0.08);
  border-color: transparent;
}
body.dark-theme .nav-link:hover {
  background: rgba(168, 199, 250, 0.12);
}
.nav-link.is-active,
.nav-link[aria-current="page"] {
  background: rgba(11, 87, 208, 0.12);
  color: var(--md-primary);
  border-color: rgba(11, 87, 208, 0.18);
}
body.dark-theme .nav-link.is-active,
body.dark-theme .nav-link[aria-current="page"] {
  background: rgba(168, 199, 250, 0.16);
  color: var(--md-primary);
  border-color: rgba(168, 199, 250, 0.22);
}
.nav-link svg { flex-shrink: 0; opacity: 0.9; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.user-chip {
  font-size: 0.78rem;
  color: var(--md-on-surface-variant);
  padding: 5px 10px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--md-outline-variant);
}
body.dark-theme .user-chip {
  background: rgba(255, 255, 255, 0.06);
}

.btn-icon-tool {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--md-on-surface);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-icon-tool svg,
.btn-icon-tool #theme-icon-light,
.btn-icon-tool #theme-icon-dark {
  width: 22px !important;
  height: 22px !important;
  min-width: 22px;
  min-height: 22px;
  flex-shrink: 0;
  display: block;
}
.btn-icon-tool:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--md-outline-variant);
  filter: none;
}
body.dark-theme .btn-icon-tool:hover {
  background: rgba(255, 255, 255, 0.08);
  filter: none;
}

.btn-compact {
  padding: 7px 14px;
  font-size: 0.86rem;
  border-radius: 10px;
}

.btn-quiet {
  padding: 7px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  background: transparent;
  color: var(--md-on-surface-variant);
  border: none;
}
.btn-quiet:hover {
  color: var(--md-on-surface);
  background: rgba(0, 0, 0, 0.04);
  filter: none;
}
body.dark-theme .btn-quiet:hover {
  background: rgba(255, 255, 255, 0.06);
  filter: none;
}

@media (max-width: 900px) {
  .app-header-inner {
    grid-template-columns: 1fr auto;
    min-height: auto;
    padding: 10px 14px;
  }
  .header-nav {
    grid-column: 1 / -1;
    order: 3;
    padding-top: 2px;
  }
  .brand-sub { display: none; }
  .user-chip { max-width: 120px; }
}

.app-main {
  max-width: 1680px;
  margin: 0 auto;
  padding: 18px 20px 0;
}

.panel {
  border-radius: var(--md-border-radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px 14px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
label {
  font-weight: 550;
  font-size: 0.82em;
  color: var(--md-on-surface-variant);
}

input[type="text"],
input[type="number"],
select,
.col-custom-free {
  padding: 8px 12px;
  background-color: rgba(255, 255, 255, 0.45);
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-input-radius);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
body.dark-theme input[type="text"],
body.dark-theme input[type="number"],
body.dark-theme select,
body.dark-theme .col-custom-free {
  background-color: rgba(0, 0, 0, 0.25);
}
input:focus, select:focus, .col-custom-free:focus {
  outline: none;
  border-color: var(--md-primary);
  box-shadow: 0 0 0 1px var(--md-primary);
}
select option { background-color: var(--md-surface-solid); color: var(--md-on-surface); }
select optgroup {
  background-color: var(--md-surface-solid);
  color: var(--md-on-surface-variant);
  font-weight: 600;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--md-button-radius);
  font-size: 0.9rem;
  font-weight: 550;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.12s, transform 0.12s;
}
.btn:hover { filter: brightness(0.95); }
body.dark-theme .btn:hover { filter: brightness(1.12); }
.btn-primary { background-color: var(--md-primary); color: var(--md-on-primary); }
.btn-secondary { background-color: var(--md-secondary); color: var(--md-on-secondary); }
.btn-tertiary { background-color: var(--md-tertiary); color: var(--md-on-tertiary); }
.btn-danger { background-color: var(--md-error); color: var(--md-on-error); }
.btn-ghost {
  background: transparent;
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline-variant);
}
.btn-word { background-color: #1e3f70; color: #fff; }
body.dark-theme .btn-word { background-color: #2b579a; }
.btn-sm { padding: 5px 12px; font-size: 0.82rem; }
.btn-icon {
  padding: 0;
  border-radius: 8px;
  width: 30px;
  height: 30px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  margin-bottom: 8px;
}

.col-example {
  min-width: 160px;
  font-weight: 500;
}

.bulk-add-section {
  background: var(--md-surface-variant);
  padding: 12px 14px;
  border-radius: var(--md-border-radius);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.sync-checkbox-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--md-outline-variant);
}
.sync-checkbox-container input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--md-primary);
}
.sync-checkbox-container label {
  cursor: pointer;
  color: var(--md-primary);
  font-weight: 600;
  margin: 0;
}
.bulk-note { margin-left: auto; font-size: 0.8em; opacity: 0.75; }

.section-header {
  background: var(--md-surface-variant);
  padding: 10px 14px;
  border-radius: var(--md-border-radius);
  margin: 16px 0 10px;
  font-weight: 600;
  font-size: 0.95rem;
}

table.config-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  font-size: 0.92rem;
}
table.config-table th,
table.config-table td {
  border: 1px solid var(--md-outline-variant);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}
table.config-table th {
  background: var(--md-surface-variant);
  font-weight: 600;
}
.col-letter strong { color: var(--md-primary); }

.field-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--md-outline-variant);
}
.field-item:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.field-row { display: flex; gap: 6px; width: 100%; }
.field-select { flex-grow: 1; min-width: 0; }
.button-group { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.w-100 { width: 100%; }
.m-0 { margin: 0 !important; }

.csv-preview-container {
  border: 1px solid var(--md-outline-variant);
  border-radius: 10px;
  padding: 10px;
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.35);
}
body.dark-theme .csv-preview-container { background: rgba(0, 0, 0, 0.2); }
.csv-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 0.85em;
}
.csv-table th, .csv-table td {
  border: 1px solid #d0d7de;
  padding: 6px 10px;
  white-space: nowrap;
}
.csv-table th { background-color: #f6f8fa; font-weight: 600; color: #24292f; text-align: center; }
.csv-table td { background-color: #fff; color: #24292f; }
.csv-table td.row-num {
  background-color: #f6f8fa;
  font-weight: 600;
  text-align: center;
  color: #57606a;
  width: 30px;
}
.csv-table tr.header-row td {
  background-color: #eef2f5;
  font-weight: bold;
  border-bottom: 2px solid #d0d7de;
}
body.dark-theme .csv-table th { background-color: #161b22; color: #c9d1d9; border-color: #30363d; }
body.dark-theme .csv-table td { background-color: #0d1117; color: #c9d1d9; border-color: #30363d; }
body.dark-theme .csv-table td.row-num { background-color: #161b22; color: #8b949e; border-color: #30363d; }
body.dark-theme .csv-table tr.header-row td { background-color: #21262d; border-bottom: 2px solid #30363d; }

.preview-hint {
  color: var(--md-on-surface-variant);
  margin: -4px 0 12px;
  font-size: 0.85em;
}

/* Configure page — collapsible category groups */
.dict-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.dict-list { display: flex; flex-direction: column; gap: 10px; }

.dict-section {
  border-radius: 12px;
  border: 1px solid var(--md-outline-variant);
  background: rgba(255, 255, 255, 0.28);
  overflow: hidden;
}
body.dark-theme .dict-section {
  background: rgba(0, 0, 0, 0.18);
}

.dict-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--md-surface-variant);
  cursor: pointer;
}
.dict-section-header input,
.dict-section-header .dict-section-actions {
  cursor: auto;
}

.dict-section-toggle {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.dict-section-toggle:hover,
.dict-section-title-btn:hover {
  background: rgba(11, 87, 208, 0.08);
}
body.dark-theme .dict-section-toggle:hover,
body.dark-theme .dict-section-title-btn:hover {
  background: rgba(168, 199, 250, 0.1);
}

.dict-chevron {
  color: var(--md-on-surface-variant);
  font-size: 0.95rem;
}

.dict-section-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.dict-section-title-btn {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
}

.dict-section-title {
  font-weight: 650;
  font-size: 0.98rem;
}

.dict-group-label {
  font-weight: 650;
  font-size: 0.98rem;
  padding: 4px 8px !important;
  background: rgba(255, 255, 255, 0.5) !important;
}
body.dark-theme .dict-group-label {
  background: rgba(0, 0, 0, 0.25) !important;
}

.dict-section-count {
  font-size: 0.75rem;
  color: var(--md-on-surface-variant);
}

.dict-section-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.dict-section-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 12px;
}
/* Author display:flex overrides the UA [hidden] rule — force collapse */
.dict-section-body[hidden],
.dict-section:not(.is-open) .dict-section-body {
  display: none !important;
}

.dict-empty {
  margin: 4px 0;
  font-size: 0.88rem;
  color: var(--md-on-surface-variant);
}

.dict-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--md-surface-variant);
  border: 1px solid var(--md-outline-variant);
}
.dict-row-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.dict-sample-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 2px;
  border-top: 1px dashed var(--md-outline-variant);
}
.dict-sample-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--md-on-surface-variant);
  margin: 0;
}
.dict-actions { display: flex; gap: 4px; }

@media (max-width: 700px) {
  .dict-section-header {
    flex-wrap: wrap;
  }
  .dict-row-top {
    grid-template-columns: 1fr;
  }
}

.app-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--md-on-surface);
  color: var(--md-surface-solid);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.92rem;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  max-width: min(520px, 92vw);
  box-shadow: var(--md-elevation);
}
.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
