:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-muted: #fafafa;
  --surface-strong: #f4f4f4;
  --border: #e7e7e7;
  --border-strong: #d9d9d9;
  --text-main: #1d1d1f;
  --text-soft: #666666;
  --accent: #2d74ff;
  --accent-hover: #1f60df;
  --danger: #f04444;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
  --radius-xl: 24px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --font-main: "IBM Plex Sans", "Segoe UI", "PingFang SC", "Microsoft YaHei",
    sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: rgb(25, 25, 25);
  --surface: rgb(31, 31, 31);
  --surface-muted: rgb(36, 36, 36);
  --surface-strong: rgb(44, 44, 44);
  --border: rgb(57, 57, 57);
  --border-strong: rgb(72, 72, 72);
  --text-main: #f5f5f5;
  --text-soft: #aaaaaa;
  --accent: #4e8cff;
  --accent-hover: #6d9fff;
  --danger: #ff5a5a;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-main);
  color: var(--text-main);
  background: var(--bg);
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 48px;
}

.topbar {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.topbar-actions,
.topbar-create-row {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.topbar-divider {
  height: 1px;
  background: var(--border);
}

.toolbar-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  color: var(--text-main);
  background: transparent;
  transition:
    background 180ms ease,
    transform 180ms ease;
}

.toolbar-button:hover,
.toolbar-button:focus-visible {
  background: var(--surface-muted);
  outline: none;
  transform: translateY(-1px);
}

.toolbar-button img,
.toolbar-button svg {
  width: 20px;
  height: 20px;
  display: block;
}

.service-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.service-card {
  display: grid;
  grid-template-columns: 46px 120px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 20px;
  min-height: 128px;
  padding: 26px 22px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition:
    transform 180ms ease,
    border-color 180ms ease;
}

.service-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.drag-handle {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
  touch-action: none;
  user-select: none;
}

.drag-handle:hover,
.drag-handle:focus-visible {
  border-color: var(--border-strong);
  outline: none;
}

.drag-handle img {
  width: 18px;
  height: 18px;
  display: block;
  opacity: 0.72;
  pointer-events: none;
}

.service-index {
  min-width: 104px;
  justify-self: start;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-soft);
  background: var(--surface-muted);
  font-size: 1.05rem;
}

.service-main {
  display: flex;
  align-items: center;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.service-main:hover .service-meta h3,
.service-main:focus-visible .service-meta h3 {
  color: var(--accent);
}

.service-main:focus-visible {
  outline: none;
}

.service-card.sorting-placeholder {
  border-style: dashed;
  background: var(--surface-muted);
  box-shadow: none;
}

.service-card.dragging {
  opacity: 0.96;
  z-index: 60;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.14);
}

.icon-preview {
  width: 100%;
  height: 100%;
}

.service-meta h3 {
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 1.9rem;
  line-height: 1.1;
}

.service-inline-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 6px;
}

.service-inline-icon-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.service-title-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-meta p {
  margin: 0;
  line-height: 1.5;
  font-size: 1.05rem;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.service-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  min-height: 54px;
  padding: 0 20px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-main);
  font-size: 1.05rem;
  font-weight: 600;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.action-button:hover,
.action-button:focus-visible {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  outline: none;
}

.delete-button {
  color: #ffffff;
  border-color: #f04444;
  background: #f04444;
}

.delete-button:hover,
.delete-button:focus-visible {
  border-color: #d93838;
  background: #d93838;
}

.card-arrow {
  width: 18px;
  height: 18px;
  color: var(--text-soft);
}

.card-arrow svg,
.create-button svg,
.icon-button svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.empty-state {
  padding: 40px 24px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
}

.empty-state p {
  margin: 0;
  color: var(--text-soft);
}

.create-button,
.primary-button,
.icon-button {
  border: 0;
}

.create-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.create-button {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  color: white;
  background: var(--accent);
  transition: transform 180ms ease, background 180ms ease;
}

.create-button:hover,
.create-button:focus-visible {
  transform: translateY(-2px);
  outline: none;
  background: var(--accent-hover);
}

.create-button svg {
  width: 18px;
  height: 18px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.96);
}

html[data-theme="dark"] .overlay {
  background: rgba(25, 25, 25, 0.98);
}

.modal {
  width: min(100%, 540px);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-shell {
  display: grid;
  justify-items: center;
}

.auth-modal {
  width: min(100%, 570px);
  padding: 42px 42px 36px;
}

.auth-heading {
  margin-bottom: 28px;
  text-align: center;
}

.auth-heading h2 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  line-height: 1.15;
}

.auth-heading p,
.modal-head p,
.muted {
  margin: 0;
  line-height: 1.6;
  color: var(--text-soft);
}

.icon-button {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  color: var(--text-main);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.65rem;
}

.stack-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.centered-field {
  width: min(100%, 480px);
  margin: 0 auto;
}

.field span,
.checkbox-field {
  color: var(--text-main);
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  color: var(--text-main);
  background: var(--surface);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(86, 136, 255, 0.9);
  box-shadow: 0 0 0 3px rgba(76, 133, 255, 0.12);
}

.field textarea {
  resize: vertical;
  min-height: 92px;
}

.password-input-wrap {
  position: relative;
}

.password-input-wrap input {
  padding-right: 54px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  color: var(--text-soft);
  background: transparent;
}

.password-toggle svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: min(100%, 480px);
  margin: 0 auto;
  color: var(--text-soft);
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  accent-color: #8f8a84;
}

.primary-button {
  min-height: 50px;
  padding: 12px 18px;
  border-radius: 16px;
  color: white;
  background: #9f9a93;
  transition: transform 180ms ease, opacity 180ms ease;
  width: min(100%, 480px);
  margin: 8px auto 0;
  font-size: 1.9rem;
  font-weight: 700;
}

.primary-button:hover,
.primary-button:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.primary-button[disabled] {
  opacity: 0.7;
  cursor: progress;
}

.form-error {
  margin: 0;
  color: var(--danger);
  width: min(100%, 480px);
  margin-inline: auto;
}

.icon-preview-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 14px;
  align-items: center;
}

.icon-preview {
  display: grid;
  place-items: center;
  border-radius: 18px;
  overflow: hidden;
  font-size: 0.76rem;
  text-align: center;
  color: var(--text-soft);
  background: var(--surface-muted);
  border: 1px dashed var(--border);
}

.icon-preview.has-image {
  font-size: 0;
  background-size: cover;
  background-position: center;
  border-style: solid;
}

@media (max-width: 780px) {
  .app {
    width: min(100% - 10px, 100%);
    padding-top: 14px;
  }

  .service-card {
    grid-template-columns: 30px 52px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 0;
    padding: 12px 10px;
  }

  .drag-handle {
    width: 24px;
    height: 24px;
    border-radius: 8px;
  }

  .drag-handle img {
    width: 12px;
    height: 12px;
  }

  .service-index {
    min-width: 0;
    padding: 6px 8px;
    font-size: 0.76rem;
  }

  .service-main {
    align-items: center;
    min-width: 0;
  }

  .service-meta h3 {
    margin: 0;
    font-size: 1.06rem;
    line-height: 1.2;
    gap: 8px;
  }

  .service-inline-icon {
    width: 18px;
    height: 18px;
  }

  .service-meta p,
  .card-arrow {
    display: none;
  }

  .service-actions {
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 4px;
    margin-top: 0;
  }

  .action-button {
    min-width: 44px;
    min-height: 28px;
    padding: 0 8px;
    border-radius: 9px;
    font-size: 0.74rem;
  }

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

  .auth-modal {
    padding: 28px 20px 24px;
  }

  .auth-heading h2 {
    font-size: 2rem;
  }

  .primary-button {
    font-size: 1.5rem;
  }
}
