:root {
  color-scheme: light;
  --ink: #18312f;
  --muted: #5f6f6b;
  --line: #d9e2df;
  --paper: #f7faf8;
  --panel: #ffffff;
  --green: #2f7d5f;
  --green-dark: #1f5f49;
  --amber: #a85d12;
  --red: #b53636;
  --blue: #2766a8;
  --shadow: 0 18px 50px rgba(31, 62, 55, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(47, 125, 95, 0.08), rgba(247, 250, 248, 0) 320px),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.workbench {
  display: grid;
  gap: 14px;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 22px 24px;
  border: 1px solid rgba(217, 226, 223, 0.88);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 14px 42px rgba(31, 62, 55, 0.08);
}

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

.brand-block {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.brand-logo {
  width: auto;
  height: clamp(98px, 11vw, 128px);
  margin-left: clamp(-36px, -3vw, -26px);
  display: block;
}

.title-row {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  min-width: 0;
}

.masthead-mascot {
  flex: 0 0 auto;
  width: clamp(72px, 7vw, 96px);
  height: auto;
  display: block;
  opacity: 0.82;
  pointer-events: none;
  filter: drop-shadow(0 10px 20px rgba(31, 62, 55, 0.12));
}

.masthead-actions {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.2rem, 4vw, 3.5rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
  letter-spacing: 0;
}

.domain-chip,
.account-chip {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.domain-chip {
  min-width: 190px;
}

.account-chip {
  min-width: 116px;
}

.icon-action {
  align-self: center;
  min-width: 76px;
}

.domain-chip span,
.account-chip span,
label span,
.panel-toolbar p {
  color: var(--muted);
  font-size: 0.84rem;
}

.domain-chip strong,
.account-chip strong {
  color: var(--green-dark);
  font-size: 1.2rem;
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.mode-tabs {
  display: inline-flex;
  width: fit-content;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.tab-button {
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tab-button.active {
  border-color: var(--green);
  background: rgba(47, 125, 95, 0.12);
  color: var(--green-dark);
}

.mode-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.mode-panel[hidden] {
  display: none;
}

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

.guide-panel {
  display: grid;
  gap: 14px;
}

.guide-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.guide-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.guide-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.86fr) minmax(0, 1.14fr);
  gap: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.guide-grid[hidden] {
  display: none;
}

.guide-block h3 {
  margin: 0 0 8px;
  color: var(--green-dark);
  font-size: 0.92rem;
  letter-spacing: 0;
}

.guide-block ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 1.25rem;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.5;
}

.field-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.field-list div {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.field-list dt {
  color: var(--green-dark);
  font-size: 0.88rem;
  font-weight: 900;
}

.field-list dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.inline-code {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  font-weight: 800;
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.full-field {
  grid-column: 1 / -1;
}

.tag-picker {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.tag-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.tag-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag-picker-header p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.tag-library-tools {
  padding-top: 2px;
  margin-bottom: 10px;
}

.tag-library-tools input {
  height: 38px;
  background: #fff;
}

.tag-category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.tag-category {
  min-height: 34px;
  padding: 0 10px;
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 0.84rem;
}

.tag-category.active {
  border-color: var(--green);
  background: rgba(47, 125, 95, 0.11);
  color: var(--green-dark);
}

.tag-category small {
  margin-left: 6px;
  color: inherit;
  font-size: 0.72rem;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 132px;
  overflow: auto;
  padding-right: 4px;
}

.tag-chip {
  min-height: 32px;
  padding: 0 10px;
  border-color: #cbd9d4;
  background: #f6faf8;
  color: var(--green-dark);
  font-size: 0.86rem;
}

.tag-chip.active {
  border-color: var(--green);
  background: rgba(47, 125, 95, 0.13);
}

.tag-chip small {
  margin-left: 6px;
  color: var(--muted);
  font-size: 0.74rem;
}

.tag-empty {
  width: 100%;
  padding: 10px 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.text-action {
  min-height: 30px;
  padding: 0 8px;
  border-color: var(--line);
  background: #fff;
  color: var(--green-dark);
  font-size: 0.82rem;
}

label {
  display: grid;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 210px;
  margin-top: 14px;
  padding: 14px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 125, 95, 0.14);
}

input[readonly] {
  cursor: not-allowed;
  background: #f4f7f5;
  color: var(--ink);
}

.tracking-card {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.tracking-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.tracking-header h3 {
  margin: 0;
  color: var(--green-dark);
  font-size: 0.96rem;
}

.tracking-header p,
.tracking-preview {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.compact-grid {
  gap: 12px;
}

.file-button,
button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.primary {
  background: var(--green);
  color: #fff;
}

.primary:hover {
  background: var(--green-dark);
}

.danger {
  border-color: rgba(181, 54, 54, 0.36);
  background: #fff;
  color: var(--red);
}

.danger:hover {
  border-color: var(--red);
  background: rgba(181, 54, 54, 0.06);
}

.secondary,
.file-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary:hover,
.file-button:hover {
  border-color: var(--green);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.actions,
.result-actions,
.import-actions,
.analytics-filter {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 10px;
}

.actions,
.result-actions {
  margin-top: 14px;
}

.single-result-panel {
  min-height: 0;
}

.single-result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 164px;
  gap: 18px;
  align-items: center;
}

.single-result-main {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.single-result-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.single-result-list div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.single-result-list dt {
  color: var(--green-dark);
  font-size: 0.86rem;
  font-weight: 900;
}

.single-result-list dd {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.single-result-list a {
  color: var(--blue);
  font-weight: 900;
  text-decoration: none;
}

.single-result-list a:hover {
  text-decoration: underline;
}

.single-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.qr-preview {
  display: grid;
  place-items: center;
  min-height: 164px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.qr-preview img {
  width: 148px;
  height: 148px;
  display: block;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
}

.login-panel {
  width: min(100%, 430px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.login-logo {
  width: min(100%, 230px);
  height: auto;
}

.login-mascot {
  width: 92px;
  height: auto;
  justify-self: end;
  filter: drop-shadow(0 10px 18px rgba(31, 62, 55, 0.12));
}

.login-panel h1 {
  margin-bottom: 22px;
  font-size: 2rem;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-hint {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
}

.login-message {
  min-height: 24px;
  color: var(--red);
  font-weight: 700;
}

.result-panel {
  min-height: 320px;
}

.analytics-filter {
  flex: 1 1 420px;
  max-width: 560px;
}

.analytics-filter input {
  flex: 1 1 280px;
  min-width: 220px;
}

.links-filter {
  display: flex;
  flex: 1 1 520px;
  align-items: center;
  justify-content: end;
  gap: 10px;
  max-width: 720px;
}

.links-filter > input {
  flex: 1 1 280px;
  min-width: 220px;
}

.page-size-control {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.page-size-control select {
  width: 68px;
  height: 42px;
  padding: 0 8px;
}

.links-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
}

.links-pagination[hidden] {
  display: none;
}

.links-pagination p {
  color: var(--muted);
  font-size: 0.88rem;
}

.links-pagination > div {
  display: flex;
  gap: 8px;
}

.links-pagination button {
  min-height: 38px;
}

.table-wrap {
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.analytics-table {
  min-width: 1040px;
}

.links-table {
  min-width: 1080px;
}

.links-table .owner-column {
  width: 108px;
  min-width: 108px;
  white-space: nowrap !important;
  overflow-wrap: normal !important;
  word-break: keep-all;
}

.links-table th:last-child,
.links-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  width: 84px;
  min-width: 84px;
  background: var(--panel);
  box-shadow: -10px 0 14px rgba(31, 62, 55, 0.07);
}

.links-table th:last-child {
  z-index: 3;
  background: #eef5f1;
}

.links-table tr.owner-self td {
  background: rgba(47, 125, 95, 0.055);
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.92rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef5f1;
  color: var(--green-dark);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

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

.empty {
  height: 160px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.status {
  display: inline-flex;
  align-items: center;
  min-width: 64px;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}

.status.ok {
  background: rgba(47, 125, 95, 0.12);
  color: var(--green-dark);
}

.status.error {
  background: rgba(181, 54, 54, 0.12);
  color: var(--red);
}

.status.pending {
  background: rgba(168, 93, 18, 0.12);
  color: var(--amber);
}

.truncate {
  max-width: 360px;
  overflow-wrap: anywhere;
}

.short-url-cell {
  white-space: normal;
}

.copy-link-button {
  min-width: 30px;
  min-height: 30px;
  margin-left: 6px;
  padding: 0 5px;
  border-color: transparent;
  background: transparent;
  color: var(--green-dark);
  font-size: 1.15rem;
  line-height: 1;
  vertical-align: middle;
}

.copy-link-button:hover {
  border-color: var(--line);
  background: #fff;
}

.analytics-detail-panel[hidden],
.link-edit-panel[hidden] {
  display: none;
}

.form-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metric-item {
  display: grid;
  gap: 4px;
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.metric-item span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.metric-item strong {
  color: var(--green-dark);
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.quality-notice {
  margin: -2px 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(168, 93, 18, 0.28);
  border-radius: 8px;
  background: rgba(168, 93, 18, 0.08);
  color: var(--ink);
}

.quality-notice[hidden] {
  display: none;
}

.quality-notice strong {
  display: block;
  margin-bottom: 6px;
  color: var(--amber);
  font-size: 0.9rem;
}

.quality-notice ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 1.1rem;
}

.quality-notice li {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.analytics-breakdown-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.breakdown-block {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.breakdown-block h3 {
  margin: 0 0 10px;
  color: var(--green-dark);
  font-size: 0.9rem;
}

.breakdown-block ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.breakdown-block li {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.breakdown-block li span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.breakdown-block li strong {
  color: var(--ink);
}

.recent-visits-wrap table {
  min-width: 760px;
}

@media (max-width: 980px) {
  .masthead-mascot {
    display: none;
  }
}

@media (max-width: 760px) {
  html {
    background: var(--paper);
  }

  body {
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .workbench {
    gap: 10px;
  }

  .masthead,
  .panel-toolbar,
  .tracking-header,
  .guide-header,
  .guide-grid,
  .single-result-grid,
  .input-grid,
  .metric-grid,
  .analytics-breakdown-grid {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .panel-toolbar,
  .guide-header {
    display: grid;
  }

  .masthead {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
    border-right: 0;
    border-left: 0;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 6px 18px rgba(31, 62, 55, 0.08);
  }

  .brand-block {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .brand-logo {
    flex: 0 0 auto;
    width: auto;
    height: 42px;
    margin: 0;
  }

  .title-row {
    display: block;
  }

  .title-row h1 {
    font-size: 1.1rem;
    line-height: 1.25;
  }

  .mode-tabs {
    position: sticky;
    top: 8px;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: calc(100% - 20px);
    margin: 0 10px;
    gap: 2px;
    padding: 4px;
    box-shadow: 0 8px 20px rgba(31, 62, 55, 0.12);
  }

  .tab-button {
    min-width: 0;
    min-height: 46px;
    padding: 4px 2px;
    font-size: 0.82rem;
    line-height: 1.2;
    white-space: normal;
  }

  .domain-chip {
    display: none;
  }

  .masthead-actions {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }

  .account-chip {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    min-height: 40px;
    padding: 0 10px;
  }

  .account-chip span {
    display: none;
  }

  .account-chip strong {
    font-size: 0.9rem;
  }

  .masthead-actions .secondary {
    min-width: 0;
    min-height: 40px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .mode-panel,
  .guide-panel {
    width: 100%;
  }

  .panel {
    padding: 16px 14px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .guide-panel {
    gap: 12px;
  }

  .guide-grid {
    gap: 14px;
    padding-top: 12px;
  }

  .field-list div {
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 8px;
  }

  input,
  select {
    height: 48px;
  }

  textarea {
    min-height: 180px;
  }

  .tracking-card,
  .tag-picker,
  .qr-preview,
  .metric-item,
  .breakdown-block {
    border-radius: 8px;
  }

  .tracking-header {
    gap: 8px;
  }

  .tracking-header .text-action {
    flex: 0 0 auto;
  }

  .single-result-grid {
    gap: 14px;
  }

  .qr-preview {
    min-height: 184px;
  }

  .qr-preview img {
    width: 164px;
    height: 164px;
  }

  .table-wrap {
    margin-right: -14px;
    margin-left: -14px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    -webkit-overflow-scrolling: touch;
  }

  .actions,
  .single-result-actions,
  .result-actions,
  .import-actions,
  .analytics-filter {
    justify-content: stretch;
    max-width: none;
  }

  .actions button,
  .single-result-actions button,
  .result-actions button,
  .import-actions .button-link,
  .analytics-filter input,
  .analytics-filter button,
  .file-button {
    width: 100%;
  }

  .links-filter {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
    max-width: none;
  }

  .links-filter > input {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .links-filter #linksRefresh {
    width: auto;
  }

  .links-pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .links-pagination > div {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 390px) {
  .brand-logo {
    height: 38px;
  }

  .title-row h1 {
    font-size: 1rem;
  }

  .tab-button {
    font-size: 0.76rem;
  }
}
