:root {
  --bg: #f3f7f4;
  --card: #ffffff;
  --text: #1f2a24;
  --muted: #5f6b5f;
  --primary: #3d7a5a;
  --primary-dark: #2f6b4f;
  --danger: #c0392b;
  --border: #d7e3db;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --bottom-nav-height: 0px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, #d8ebe0 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #e8f2ec 0%, transparent 50%),
    var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

a:hover {
  text-decoration: underline;
}

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

.shell {
  max-width: 1100px;
  margin: 0 auto;
  padding:
    calc(24px + var(--safe-top))
    calc(20px + var(--safe-right))
    calc(48px + var(--safe-bottom) + var(--bottom-nav-height))
    calc(20px + var(--safe-left));
}

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
}

.hero p {
  margin: 6px 0 0;
  color: var(--muted);
  word-break: break-all;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
}

a.btn:hover {
  text-decoration: none;
}

.btn:hover {
  border-color: var(--primary);
}

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

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

.btn.danger {
  color: var(--danger);
  border-color: #f0c2c2;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

label.field {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

label.field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
}

.login-wrap {
  max-width: 420px;
  margin: 10vh auto 0;
}

.login-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tab {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  min-height: 40px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
}

.tab.active {
  background: #e5f2ea;
  color: var(--primary-dark);
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.swatch {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 1px solid #ccc;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 8px;
}

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.form-inline input {
  flex: 1;
  min-width: 140px;
  padding: 10px 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
}

.switch {
  position: relative;
  width: 44px;
  height: 28px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  background: #c9d5ce;
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}

.switch span::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::before {
  transform: translateX(16px);
}

.toast {
  position: fixed;
  right: calc(20px + var(--safe-right));
  bottom: calc(20px + var(--safe-bottom) + var(--bottom-nav-height));
  background: #1f2a24;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
  max-width: 320px;
}

.toast.error {
  background: var(--danger);
}

.empty {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
}

.ellipsis {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-nav {
  display: none;
}

.prefs-json {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}

@media (max-width: 720px) {
  body.has-bottom-nav {
    --bottom-nav-height: 56px;
  }

  .shell {
    padding:
      calc(16px + var(--safe-top))
      calc(16px + var(--safe-right))
      calc(20px + var(--safe-bottom) + var(--bottom-nav-height))
      calc(16px + var(--safe-left));
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 16px;
  }

  .hero h1 {
    font-size: 22px;
  }

  .desktop-nav {
    display: none;
  }

  .login-wrap {
    max-width: none;
    margin: 12px auto 0;
  }

  .login-actions .btn,
  .login-wrap .btn {
    width: 100%;
    min-height: 48px;
  }

  .card {
    padding: 16px;
    border-radius: 16px;
  }

  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    margin: 0 -16px 14px;
    padding: 0 16px 4px;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    padding: 8px 14px;
  }

  .form-inline {
    flex-direction: column;
  }

  .form-inline input {
    min-width: 0;
    width: 100%;
  }

  .form-inline .btn {
    width: 100%;
    min-height: 48px;
  }

  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    background: #fafcfb;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
  }

  td {
    border: 0;
    padding: 6px 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    word-break: break-word;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    flex: 0 0 auto;
  }

  td.ellipsis {
    max-width: none;
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
  }

  td.cell-actions {
    justify-content: flex-end;
    padding-top: 10px;
  }

  td.cell-actions::before {
    content: none;
  }

  td.cell-actions .btn {
    min-height: 44px;
    min-width: 72px;
  }

  .row {
    align-items: flex-start;
    gap: 12px;
  }

  .toast {
    left: calc(16px + var(--safe-left));
    right: calc(16px + var(--safe-right));
    max-width: none;
    text-align: center;
  }

  body.has-bottom-nav .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding: 4px var(--safe-right) var(--safe-bottom) var(--safe-left);
    min-height: calc(56px + var(--safe-bottom));
    justify-content: space-around;
  }

  .bottom-nav button {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--muted);
    min-height: 48px;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav button.active {
    color: var(--primary-dark);
    font-weight: 600;
  }
}

@media (min-width: 721px) {
  .bottom-nav {
    display: none !important;
  }

  label.field input,
  .form-inline input {
    font-size: 14px;
    min-height: 40px;
  }
}
