:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #e6ebf0;
  --text: #1f2933;
  --muted: #6b7785;
  --primary: #ff7a1a;
  --primary-deep: #e8680d;
  --danger: #e14b4b;
  --sidebar: #18212b;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(20, 30, 40, 0.08);
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --tap: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button,
.file-btn {
  min-height: var(--tap);
  touch-action: manipulation;
}

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  background:
    radial-gradient(circle at top, rgba(255, 122, 26, 0.18), transparent 45%),
    var(--bg);
}

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: grid;
  gap: 0.85rem;
}

.login-card h1 {
  margin: 0;
  font-size: 1.4rem;
}

.login-card p {
  margin: 0;
  color: var(--muted);
}

.login-card label,
.site-form label,
.modal-body label,
.icon-upload {
  display: grid;
  gap: 0.35rem;
}

.login-card input,
.site-form input,
.site-form textarea,
.modal-body input,
.modal-body select,
.toolbar input,
.toolbar select,
.field-inline select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  background: #fff;
  outline: none;
  font-size: 16px;
}

.login-card input:focus,
.site-form input:focus,
.site-form textarea:focus,
.modal-body input:focus,
.modal-body select:focus,
.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--primary);
}

.login-card button,
.btn-primary,
.btn-ghost,
.btn-danger,
.logout-btn,
.nav-btn {
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.login-card button,
.btn-primary {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  padding: 0.75rem 1rem;
}

.login-card button:hover,
.btn-primary:hover {
  background: var(--primary-deep);
}

.btn-block {
  width: 100%;
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
}

.admin-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 1.1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand {
  display: grid;
  gap: 0.35rem;
  padding: 0.4rem 0.5rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand a {
  color: #9fb0c0;
  text-decoration: none;
  font-size: 0.85rem;
}

.side-nav {
  display: grid;
  gap: 0.35rem;
}

.nav-btn {
  text-align: left;
  background: transparent;
  color: #c9d4de;
  padding: 0.75rem 0.85rem;
  min-height: var(--tap);
}

.nav-btn.is-active,
.nav-btn:hover {
  background: rgba(255, 122, 26, 0.18);
  color: #fff;
}

.logout-btn {
  margin-top: auto;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  padding: 0.75rem 0.85rem;
}

.main {
  padding: 1.2rem 1.4rem 2rem;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.topbar h2 {
  margin: 0;
  font-size: 1.25rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.field-inline span {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 160px;
}

.table-wrap {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.data-table th,
.data-table td {
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  font-size: 0.85rem;
  color: var(--muted);
  background: #fafbfc;
  position: sticky;
  top: 0;
}

.row-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  background: #f1f3f5;
  flex-shrink: 0;
}

.url-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-ghost {
  background: #f3f5f7;
  color: var(--text);
  padding: 0.55rem 0.8rem;
}

.btn-danger {
  background: #ffe8e8;
  color: var(--danger);
  padding: 0.55rem 0.8rem;
}

.btn-ghost:disabled,
.btn-danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.site-form {
  max-width: 560px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  display: grid;
  gap: 0.9rem;
}

.card-list {
  display: grid;
  gap: 0.75rem;
}

.item-card {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.9rem;
  display: grid;
  gap: 0.75rem;
}

.item-card-main {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  min-width: 0;
}

.item-card-body {
  min-width: 0;
  flex: 1;
}

.item-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  word-break: break-word;
}

.item-card-meta {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.item-card-actions .btn-ghost,
.item-card-actions .btn-danger {
  width: 100%;
}

.item-card-actions.wide {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.desktop-only { display: block; }
.mobile-only { display: none; }

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100% - 2rem);
  width: 460px;
  margin: auto;
}

.modal::backdrop {
  background: rgba(10, 16, 24, 0.55);
}

.modal-card {
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  max-height: min(90vh, 900px);
  display: flex;
  flex-direction: column;
}

.modal-card header,
.modal-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.95rem 1rem;
  flex-shrink: 0;
}

.modal-card header h3 {
  margin: 0;
}

.modal-body {
  display: grid;
  gap: 0.85rem;
  padding: 0 1rem 1rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-card footer {
  border-top: 1px solid var(--line);
  gap: 0.55rem;
}

.modal-card footer .btn-ghost {
  margin-left: auto;
}

.icon-close {
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
}

.icon-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.icon-row img {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  background: #f1f3f5;
  border: 1px solid var(--line);
}

.icon-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + var(--safe-bottom));
  transform: translateX(-50%);
  background: #18212b;
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 30;
  max-width: calc(100% - 2rem);
  text-align: center;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.empty-card {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 860px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: grid; }

  .admin-shell {
    grid-template-columns: 1fr;
    padding-bottom: calc(64px + var(--safe-bottom));
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    flex-direction: row;
    align-items: center;
    gap: 0.55rem;
    padding: 0.65rem 0.75rem;
    padding-top: calc(0.65rem + env(safe-area-inset-top, 0px));
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  }

  .brand {
    border: 0;
    padding: 0;
    min-width: 0;
  }

  .brand strong {
    font-size: 0.95rem;
  }

  .brand a {
    display: none;
  }

  .side-nav {
    display: flex;
    flex: 1;
    gap: 0.3rem;
    justify-content: center;
  }

  .nav-btn {
    flex: 1;
    text-align: center;
    padding: 0.55rem 0.35rem;
    font-size: 0.88rem;
    border-radius: 999px;
  }

  .nav-btn.is-active {
    background: var(--primary);
    color: #fff;
  }

  .logout-btn {
    margin-top: 0;
    padding: 0.55rem 0.7rem;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  .main {
    padding: 0.95rem 0.85rem calc(1.2rem + var(--safe-bottom));
  }

  .topbar {
    margin-bottom: 0.75rem;
  }

  .topbar h2 {
    font-size: 1.15rem;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .field-inline {
    width: 100%;
  }

  .field-inline select,
  .toolbar input[type="search"],
  .toolbar .btn-primary {
    width: 100%;
  }

  .toolbar .btn-primary {
    min-height: 46px;
  }

  .site-form {
    max-width: none;
    padding: 1rem;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
  }

  .modal-card {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .modal-card footer {
    padding-bottom: calc(0.95rem + var(--safe-bottom));
  }

  .modal-card footer .btn-ghost,
  .modal-card footer .btn-primary {
    flex: 1;
    margin-left: 0;
  }

  .icon-row {
    flex-wrap: wrap;
  }

  .icon-actions {
    width: 100%;
  }

  .icon-actions .btn-ghost,
  .icon-actions .file-btn {
    flex: 1;
  }

  .item-card-actions.cat-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .nav-btn {
    font-size: 0.8rem;
    padding-inline: 0.2rem;
  }

  .logout-btn {
    padding-inline: 0.5rem;
  }
}
