:root {
  --bg: #ffffff;
  --bg-alt: #f7f7f8;
  --border: #e2e2e5;
  --text: #1f2124;
  --text-muted: #6b6f76;
  --accent: #2f6fed;
  --accent-hover: #2557c0;
  --danger: #c0392b;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg-alt);
  color: var(--text);
  line-height: 1.6;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; color: var(--text-muted); }

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
}

code {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.85em;
}

.screen { min-height: 100vh; }

/* ログイン画面 */
.login-box {
  max-width: 420px;
  margin: 10vh auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.login-box label {
  display: block;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  margin-top: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

textarea { resize: vertical; }

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.1rem;
  font-size: 0.9rem;
  background: var(--accent);
  color: #fff;
  margin-top: 0.4rem;
}

button:hover { background: var(--accent-hover); }
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--bg-alt); }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.8rem; }

/* アプリ画面 */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1rem 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px 6px 0 0;
  border: 1px solid transparent;
  margin: 0;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--accent);
  border-color: var(--border);
  border-bottom-color: var(--bg);
  background: var(--bg);
  font-weight: 600;
}

main { padding: 1rem 1.25rem 3rem; max-width: 900px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* カード（設定一覧） */
.card-list { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }

.setting-card, .template-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.setting-card .key { font-weight: 600; font-size: 0.9rem; }
.setting-card .desc { color: var(--text-muted); font-size: 0.8rem; margin: 0.2rem 0 0.5rem; }
.setting-card .readonly-badge {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.4em;
  margin-left: 0.5rem;
}

.setting-card .row { display: flex; gap: 0.5rem; align-items: center; }
.setting-card .row input { flex: 1; }

.template-card { margin-bottom: 1rem; }
.template-card .field-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.6rem; }
.template-card textarea.body-field { min-height: 220px; font-family: ui-monospace, monospace; font-size: 0.85rem; }
.template-card .warning { color: #b8860b; font-size: 0.8rem; margin-top: 0.4rem; }
.template-card .saved-msg { color: #1e7d32; font-size: 0.8rem; margin-top: 0.4rem; }

.result-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  margin-top: 1rem;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg);
  font-size: 0.8rem;
}

table th, table td {
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
  white-space: nowrap;
}

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

@media (max-width: 600px) {
  .login-box { margin: 5vh 1rem; padding: 1.25rem; }
  main { padding: 1rem 0.75rem 3rem; }
  .app-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}

/* 別ページへのリンク（タブ風） */
.tab-link {
  display: inline-block;
  padding: 0.5rem 1rem;
  margin-left: auto;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}


/* 処理中表示 */
.spinner[hidden] { display: none !important; }
.spinner {
  display: inline-block;
  width: 0.9em; height: 0.9em;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  margin-right: 0.4em;
  vertical-align: -0.1em;
  animation: spin 0.8s linear infinite;
}
button.secondary .spinner { border-color: rgba(0,0,0,0.2); border-top-color: var(--text); }
button:disabled { opacity: 0.6; cursor: wait; }
button.is-busy { position: relative; color: transparent !important; }
button.is-busy::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 0.9em; height: 0.9em; margin: -0.45em 0 0 -0.45em;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
button.secondary.is-busy::after { border-color: rgba(0,0,0,0.2); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }
details.sub { margin-top: 0.6rem; font-size: 0.9rem; }
details.sub summary { cursor: pointer; color: var(--accent); }
details.sub input { display: block; width: 100%; margin: 0.3rem 0; }


/* 全画面オーバーレイ（ログイン・長い処理） */
#ss-overlay[hidden] { display: none !important; }
#ss-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(20, 24, 33, 0.55);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; font-size: 1rem;
}
#ss-overlay .big-spinner {
  width: 56px; height: 56px; margin-bottom: 1rem;
  border: 5px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

details.adv { margin: 0.5rem 0 1rem; font-size: 0.85rem; }
details.adv summary { cursor: pointer; color: var(--text-muted); }
