:root {
  --primary: #0381fe;
  --primary-hover: #0266d6;
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #16181c;
  --text-secondary: #6a707a;
  --divider: #e6e8ec;
  --danger: #e5484d;
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
  --header-height: 56px;
  --bottom-nav-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #4da3ff;
    --primary-hover: #6fb6ff;
    --bg: #0d0f12;
    --surface: #1a1d21;
    --surface-2: #22262b;
    --text: #f2f4f7;
    --text-secondary: #a4acb8;
    --divider: #2b2f36;
    --danger: #ff6b6f;
    --shadow: 0 2px 10px rgba(0,0,0,0.5);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Noto Sans JP", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body.app {
  padding-top: var(--header-height);
  padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
}

/* ===== Header ===== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  border-bottom: 1px solid var(--divider);
}
.app-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}
.role-chip {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.role-chip.admin { background: rgba(3,129,254,0.15); color: var(--primary); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }

/* ===== Bottom Navigation ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--surface);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  border-top: 1px solid var(--divider);
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.2s;
}
.nav-item.active { color: var(--primary); }
.nav-item .nav-icon { width: 26px; height: 26px; }
.nav-item.active .nav-icon { transform: scale(1.05); }

/* ===== Content ===== */
.content {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 8px 4px 20px;
}
.section-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 20px 8px 8px;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: 18px;
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 24px;
  border: none;
  border-radius: 26px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.2s, opacity 0.15s, transform 0.05s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-secondary {
  background: var(--surface-2);
  color: var(--primary);
}
.btn-secondary:hover { background: var(--divider); }
.btn-inline { width: auto; padding: 10px 22px; font-size: 0.9rem; }

/* ===== Form ===== */
.field { margin-bottom: 16px; }
.field-label {
  display: block;
  margin: 0 6px 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 14px 18px;
  border: 1.5px solid var(--divider);
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.15s, background 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

/* ===== Toggle Switch ===== */
.toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: relative;
  width: 52px;
  height: 32px;
  background: var(--divider);
  border-radius: 20px;
  transition: background 0.25s;
  flex-shrink: 0;
}
.toggle .slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.25s;
}
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ===== List rows ===== */
.list {
  background: var(--surface);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--divider);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 500; }
.list-item .li-sub {
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item .li-trailing {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.message {
  text-align: center;
  min-height: 22px;
  margin: 14px 0 4px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.message.error { color: var(--danger); }
.message.success { color: var(--primary); }

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: rgba(28,30,34,0.96);
  color: #fff;
  padding: 13px 24px;
  border-radius: 26px;
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ===== Login page ===== */
body.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 26px;
  padding: 40px 28px;
  box-shadow: var(--shadow);
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0 auto 20px;
}
.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}
.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 28px;
}
.pw-login {
  margin-top: 22px;
  border-top: 1px solid var(--divider);
  padding-top: 18px;
}
.pw-login-title {
  color: var(--primary);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 16px;
}

/* =========================================================================
   Responsive & Missing Components (mobile-first, phone + desktop)
   ========================================================================= */

/* ===== Stat grid (dashboard) ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 8px;
}
.stat { text-align: center; padding: 18px 12px; }
.stat-num {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}
.stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== Chips (keywords) ===== */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 20px;
  padding: 6px 8px 6px 14px;
  font-size: 0.88rem;
}
.chip-x {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 50%;
}
.chip-x:hover { background: var(--danger); color: #fff; }

/* ===== Badges & small buttons ===== */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.badge-frozen { background: rgba(229,72,77,0.15); color: var(--danger); }
.btn-sm {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { background: var(--divider); }

/* ===== Inline forms (sites/settings) ===== */
.inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.inline-form input, .inline-form select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 11px 14px;
}
.inline-form .btn { width: auto; flex-shrink: 0; padding: 11px 20px; }

/* ===== Site rows ===== */
.site-url { font-weight: 500; overflow-wrap: anywhere; }
.site-sub {
  font-size: 0.82rem;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

/* ===== Language switcher ===== */
.language-switcher {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.language-select {
  width: auto;
  padding: 6px 10px;
  font-size: 0.82rem;
  border-radius: 12px;
}

/* ===== Settings field layout ===== */
.field > span {
  display: block;
  margin: 0 6px 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ===== Tablet (≥600px) ===== */
@media (min-width: 600px) {
  .content { padding: 28px 24px 40px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .stat-num { font-size: 2rem; }
  .btn { width: auto; padding: 13px 32px; }
  .btn-block, .btn.btn-block { width: 100%; }
  .card { padding: 24px 26px; }
}

/* ===== Desktop (≥900px) ===== */
@media (min-width: 900px) {
  .content { max-width: 960px; padding: 36px 32px 48px; }
  .page-title { font-size: 1.9rem; margin-bottom: 26px; }
  .stat-num { font-size: 2.2rem; }

  /* Bottom nav → side rail */
  .bottom-nav {
    top: var(--header-height);
    bottom: 0;
    left: 0;
    right: auto;
    width: 220px;
    height: auto;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 2px;
    padding: 14px 10px;
    border-top: none;
    border-right: 1px solid var(--divider);
  }
  .nav-item {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
  }
  .nav-item.active { background: var(--surface-2); }
  .nav-item .nav-icon { width: 22px; height: 22px; }
  body.app {
    padding-bottom: 40px;
    padding-left: 220px;
  }
  .toast-container { bottom: 24px; }
}

/* ===== Large desktop (≥1280px) ===== */
@media (min-width: 1280px) {
  .content { max-width: 1080px; }
}

/* ===== Small phone adjustments (≤380px) ===== */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-num { font-size: 1.35rem; }
  .stat-label { font-size: 0.7rem; }
  .app-title { font-size: 1.1rem; }
  .role-chip { display: none; }
  .language-switcher { display: none; }
  .content { padding: 14px 12px 28px; }
  .card { padding: 16px; border-radius: 14px; }
  .login-card { padding: 28px 20px; }
}

/* ===== Login page fixes ===== */
/* パスワードフォーム表示 */
#password-area { display: block; }
#password-area .field { margin: 12px 0; }
#password-area input {
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
}
/* 言語セレクタ（右上固定） */
.login-card { position: relative; }
.login-card > .language-switcher {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 2px 4px;
}
.login-card > .language-switcher .language-select {
  width: auto;
  min-width: 0;
  padding: 6px 26px 6px 10px;
  font-size: 0.85rem;
  border: none;
  background: transparent;
  border-radius: 10px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236a707a' stroke-width='2'%3e%3cpath d='M6 9l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.login-card > .language-switcher .language-select:focus { outline: none; }
