/* =============================================================
   Grandluna Links — 短縮URL管理ダッシュボード
   ダーク × ゴールドの高級感あるシングルページデザイン
   ============================================================= */

:root {
  --bg: #0d0f14;
  --bg-soft: #12151d;
  --card: #171b25;
  --card-hover: #1c2130;
  --line: #262c3a;
  --text: #e8e6e1;
  --text-dim: #8a8f9a;
  --gold: #c8a96a;
  --gold-soft: rgba(200, 169, 106, 0.14);
  --danger: #d06a6a;
  --ok: #6ab08a;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(1200px 500px at 80% -10%, rgba(200, 169, 106, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(96, 116, 176, 0.06), transparent 60%);
  min-height: 100vh;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.boot-loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  letter-spacing: 0.2em;
}

/* ---------------- 共通パーツ ---------------- */

.serif { font-family: 'Shippori Mincho', serif; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn.primary {
  background: linear-gradient(135deg, #d5b87c, #b8945a);
  border: none;
  color: #14161c;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.btn.primary:hover { filter: brightness(1.08); color: #14161c; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 5px 14px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="text"], input[type="url"], input[type="email"], input[type="password"],
input[type="datetime-local"], select {
  width: 100%;
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus { border-color: var(--gold); }
input::placeholder { color: #5a6070; }
input[type="datetime-local"] { color-scheme: dark; }

label.field {
  display: block;
  margin-bottom: 14px;
}
label.field span {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 5px;
  letter-spacing: 0.08em;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px;
  box-shadow: var(--shadow);
}

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

/* ---------------- ヘッダー ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 26px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.brand .logo {
  font-family: 'Shippori Mincho', serif;
  font-size: 24px;
  letter-spacing: 0.14em;
  color: var(--text);
}
.brand .logo em {
  font-style: normal;
  color: var(--gold);
}
.brand .tag {
  font-size: 11.5px;
  color: var(--text-dim);
  letter-spacing: 0.2em;
}
.userbox {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.userbox .role-badge {
  font-size: 10.5px;
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 999px;
  padding: 1px 10px;
  letter-spacing: 0.15em;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 22px 80px;
}

/* ---------------- 認証画面 ---------------- */

.auth-hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.auth-hero .brand { flex-direction: column; align-items: center; gap: 4px; margin-bottom: 34px; }
.auth-hero .logo { font-size: 34px; }
.auth-card {
  width: 100%;
  max-width: 420px;
}
.auth-card h2 {
  margin: 0 0 22px;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-align: center;
  color: var(--text);
}
.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-dim);
}
.auth-switch a { cursor: pointer; }

/* ---------------- 作成フォーム ---------------- */

.create-card { margin-bottom: 34px; }
.create-card h2 {
  margin: 0 0 18px;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--gold);
}
.create-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 18px;
}
@media (min-width: 720px) {
  .create-grid { grid-template-columns: 2.2fr 1fr 1fr auto; align-items: end; }
  .create-grid label.field { margin-bottom: 0; }
  .create-grid .btn { margin-bottom: 1px; }
}
.code-input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  overflow: hidden;
}
.code-input-wrap:focus-within { border-color: var(--gold); }
.code-input-wrap .prefix {
  padding: 0 0 0 14px;
  font-size: 12.5px;
  color: #5a6070;
  white-space: nowrap;
}
.code-input-wrap input {
  border: none;
  background: transparent;
  padding-left: 4px;
}

.period-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 18px;
  margin-top: 16px;
}
@media (min-width: 720px) {
  .period-grid { grid-template-columns: 1fr 1fr 1.4fr; align-items: end; }
  .period-grid label.field { margin-bottom: 0; }
  .period-grid .period-hint { padding-bottom: 10px; }
}
.period-hint { font-size: 12px; }

.modal-period {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}
@media (max-width: 480px) {
  .modal-period { grid-template-columns: 1fr; }
}

.result-banner {
  margin-top: 18px;
  padding: 14px 18px;
  border: 1px solid var(--gold);
  background: var(--gold-soft);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.result-banner .url {
  font-size: 16px;
  color: var(--gold);
  word-break: break-all;
}

/* ---------------- リンク一覧 ---------------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.section-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--gold);
}

.link-list { display: flex; flex-direction: column; gap: 12px; }

.link-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 18px;
  padding: 18px 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.link-item:hover { background: var(--card-hover); border-color: #37405a; }
.link-item.selected { border-color: var(--gold); }
.link-item.inactive { opacity: 0.55; }

.link-main { min-width: 0; }
.link-code {
  font-size: 16.5px;
  color: var(--gold);
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.link-code .title { color: var(--text); font-size: 13.5px; }
.link-code .badge-off {
  font-size: 10.5px;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 999px;
  padding: 0 8px;
}
.link-code .badge-sched {
  font-size: 10.5px;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0 8px;
}
.link-code .badge-ended {
  font-size: 10.5px;
  color: var(--text-dim);
  border: 1px solid var(--text-dim);
  border-radius: 999px;
  padding: 0 8px;
}
.link-period {
  font-size: 12px;
  color: var(--gold);
  opacity: 0.85;
  margin-top: 2px;
}
.link-code .badge-owner {
  font-size: 10.5px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
}
.link-url {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.click-stat {
  text-align: right;
  margin-right: 8px;
  line-height: 1.3;
}
.click-stat b { font-size: 19px; color: var(--text); font-weight: 500; }
.click-stat span { display: block; font-size: 10.5px; color: var(--text-dim); letter-spacing: 0.1em; }

.empty-state {
  padding: 50px 20px;
  text-align: center;
  color: var(--text-dim);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ---------------- 解析パネル ---------------- */

.stats-panel { margin-top: 34px; }
.stats-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.stats-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
}
.stats-head h2 .code { color: var(--gold); }

.tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(5, 1fr); } }
.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.tile .num { font-size: 26px; font-weight: 500; line-height: 1.2; }
.tile .num.gold { color: var(--gold); }
.tile .lbl { font-size: 11px; color: var(--text-dim); letter-spacing: 0.12em; margin-top: 4px; }

.chart-card { margin-bottom: 18px; }
.chart-card h3, .bd-card h3, .recent-card h3 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.14em;
}
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.bar { fill: var(--gold); opacity: 0.85; transition: opacity 0.15s; }
.bar:hover { opacity: 1; }
.bar.dim { fill: #4a5468; }
.axis-text { fill: #5a6070; font-size: 10px; }

.bd-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
@media (min-width: 720px) { .bd-grid { grid-template-columns: repeat(3, 1fr); } }
.bd-card ul { list-style: none; margin: 0; padding: 0; }
.bd-card li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 13px;
}
.bd-card li .k {
  flex: 0 0 42%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.bd-card li .meter {
  flex: 1;
  height: 6px;
  background: var(--bg-soft);
  border-radius: 3px;
  overflow: hidden;
}
.bd-card li .meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #b8945a, #d5b87c);
  border-radius: 3px;
}
.bd-card li .n { flex: 0 0 44px; text-align: right; color: var(--text-dim); font-size: 12px; }

.recent-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.recent {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 760px;
}
table.recent th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.recent td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(38, 44, 58, 0.5);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.recent td.dim { color: var(--text-dim); }
.bot-badge {
  font-size: 10px;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 999px;
  padding: 0 7px;
}

/* ---------------- 管理者セクション ---------------- */

.admin-section { margin-top: 44px; }
table.users {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 640px;
}
table.users th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}
table.users td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(38, 44, 58, 0.5);
  white-space: nowrap;
}

/* ---------------- モーダル ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 480px;
  animation: modal-in 0.18s ease;
}
@keyframes modal-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.modal h3 { margin: 0 0 18px; font-size: 16px; font-weight: 500; letter-spacing: 0.08em; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  margin-bottom: 14px;
  cursor: pointer;
  user-select: none;
}
.check-row input { accent-color: var(--gold); }

/* ---------------- トースト ---------------- */

#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e2432;
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 12px 26px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease;
  z-index: 200;
  max-width: 88vw;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--danger); }

.form-error {
  color: var(--danger);
  font-size: 12.5px;
  margin: 4px 0 12px;
  min-height: 1em;
}

.fade-in { animation: fade-in 0.25s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
