/* AIMIHARU 管理画面 — ダークサイドバー + ライトメイン */

:root {
  --sidebar-bg: #0f172a;
  --sidebar-border: #1e293b;
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --page-bg: #eef2f7;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #ea580c;
  --warning-bg: #ffedd5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --font: "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--page-bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ----- アプリシェル ----- */

.app-body {
  margin: 0;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar__logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.45);
}

.sidebar__title {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.sidebar__tagline {
  font-size: 0.72rem;
  color: var(--sidebar-muted);
  margin-top: 2px;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px;
  flex: 1;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.sidebar__link:hover {
  background: rgba(255, 255, 255, 0.06);
  text-decoration: none;
}

.sidebar__link.is-active {
  background: var(--accent-soft);
  color: #93c5fd;
}

.sidebar__link--muted {
  color: var(--sidebar-muted);
  font-weight: 400;
}

.sidebar__icon {
  width: 1.5rem;
  text-align: center;
  opacity: 0.85;
  font-size: 0.95rem;
}

.sidebar__footer {
  padding: 14px 10px 20px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar__user {
  font-size: 0.8rem;
  color: var(--sidebar-muted);
  padding: 0 12px 8px;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar__title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.page-main {
  flex: 1;
  padding: 22px 28px 36px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.page-section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.page-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-section__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

/* ----- KPI カード ----- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 1100px) {
  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .kpi-row {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.kpi-card__label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.kpi-card__value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.kpi-card__unit {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 2px;
}

.kpi-card--alert .kpi-card__value {
  color: var(--danger);
}

.kpi-card--ok .kpi-card__value {
  color: var(--success);
}

/* ----- 地図 ----- */

.map-wrap {
  height: 360px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #e8edf4;
}

.map-wrap--sm {
  height: 220px;
}

#dash-map,
#detail-map {
  width: 100%;
  height: 100%;
}

.map-wrap iframe#detail-map,
.map-wrap iframe.map-embed {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* ----- テーブル ----- */

.data-table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.thumb {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f1f5f9;
}

/* ----- ステータスバッジ ----- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--pending {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge--bear {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge--not_bear {
  background: #e0f2fe;
  color: #0369a1;
}

.badge--unknown {
  background: #f1f5f9;
  color: var(--muted);
}

.badge--notified {
  background: var(--success-bg);
  color: var(--success);
}

.badge--online {
  background: var(--success-bg);
  color: var(--success);
}

.badge--remote {
  background: #e0e7ff;
  color: #3730a3;
}

/* ----- 端末カード ----- */

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: #fafbfc;
}

.device-card__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.device-card__id {
  font-weight: 700;
  font-size: 0.95rem;
}

.device-card__name {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.device-card__metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-size: 0.8rem;
  color: var(--text);
}

.device-card__metrics dt {
  color: var(--muted);
  font-weight: 500;
}

.device-card__metrics dd {
  margin: 0;
  font-weight: 600;
}

.device-card__actions {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ----- 検知詳細 ----- */

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 20px;
}

@media (max-width: 900px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

.detail-photo {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0f172a;
}

.detail-photo img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 480px;
  object-fit: contain;
}

.meta-list {
  display: grid;
  grid-template-columns: minmax(96px, 120px) 1fr;
  column-gap: 14px;
  row-gap: 0;
  margin: 0;
  font-size: 0.9rem;
}

.meta-list dt,
.meta-list dd {
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.meta-list dt {
  color: var(--muted);
  font-weight: 500;
}

.meta-list dd {
  font-weight: 500;
}

.meta-list dt:last-of-type,
.meta-list dd:last-of-type {
  border-bottom: none;
}

.leaflet-div-icon.map-pin {
  background: transparent !important;
  border: none !important;
}

/* ----- フォーム ----- */

.form-stack {
  display: grid;
  gap: 14px;
  max-width: 720px;
}

.form-stack label {
  display: grid;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="file"],
select,
textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(1.05);
  text-decoration: none;
}

.btn--secondary {
  background: #f1f5f9;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--secondary:hover {
  background: #e2e8f0;
}

.btn--danger {
  background: var(--danger);
  color: #fff;
}

.btn--danger:hover {
  filter: brightness(1.08);
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  margin-bottom: 16px;
}

.list-toolbar--actions {
  align-items: center;
}

.list-toolbar__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
}

.list-toolbar__label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.list-toolbar select {
  min-width: 160px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font: inherit;
  font-size: 0.875rem;
  background: #fff;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  font-size: 0.875rem;
}

.pager__link,
.pager__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.pager__num.is-current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.pager__link--disabled {
  opacity: 0.45;
  cursor: default;
}

.pager__gap {
  padding: 0 4px;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 0.875rem;
  margin-bottom: 14px;
}

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0 0 12px;
}

/* ----- ログイン ----- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #0f172a 0%, #1e3a5f 45%, #0f172a 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 700;
}

.auth-card .sub {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-card .btn {
  width: 100%;
  margin-top: 4px;
}

/* ----- レガシー互換（狭いコンテナ等） ----- */

.container {
  max-width: 960px;
  margin: 24px auto;
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.narrow {
  max-width: 480px;
}

/* レスポンシブ: サイドバー折りたたみ風 */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar__brand {
    flex: 1;
    border-bottom: none;
    border-right: 1px solid var(--sidebar-border);
  }

  .sidebar__nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1 1 100%;
    padding: 8px;
  }

  .sidebar__footer {
    flex: 1 1 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .page-main {
    padding: 16px;
  }
}

/* ----- 画像ライトボックス ----- */

.js-lightbox {
  cursor: zoom-in;
}

.thumb-lightbox {
  display: inline-block;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: zoom-in;
  vertical-align: middle;
  border-radius: 8px;
  line-height: 0;
}

.thumb-lightbox:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.thumb-lightbox:focus:not(:focus-visible) {
  outline: none;
}

.thumb-lightbox .thumb {
  display: block;
}

.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 16px 16px;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.22s ease;
}

.img-lightbox.img-lightbox--open {
  opacity: 1;
}

.img-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.88);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.26s ease;
}

.img-lightbox--open .img-lightbox__backdrop {
  opacity: 1;
}

.img-lightbox__frame {
  position: relative;
  z-index: 2;
  max-width: min(96vw, 1400px);
  max-height: 90vh;
  margin: auto;
  transform: scale(0.92) translateY(16px);
  opacity: 0;
  transition:
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.26s ease;
}

.img-lightbox--open .img-lightbox__frame {
  transform: scale(1) translateY(0);
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .img-lightbox,
  .img-lightbox__backdrop,
  .img-lightbox__frame {
    transition: none;
  }
}

.img-lightbox__frame img {
  display: block;
  max-width: min(96vw, 1400px);
  max-height: 88vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
}

.img-lightbox__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.img-lightbox__close:hover {
  background: #fff;
}
