﻿/* =============================
   更新期限管理アプリ（外部ライブラリなし）
   - データ：画面内配列（必須）
   - 任意：localStorage（ON/OFF）
   - 追加：一覧の見出しクリックでソート（昇順/降順）
   - 追加：期限切れのみ / 種別フィルタ
   - 追加：スマホはカード表示
   ============================= */

:root {
  --bg: #0b1220;
  --card: rgba(255,255,255,0.06);
  --card2: rgba(255,255,255,0.08);
  --text: #e9eefc;
  --muted: rgba(233,238,252,0.72);
  --line: rgba(255,255,255,0.14);
  --shadow: 0 18px 45px rgba(0,0,0,0.35);
  --r: 18px;

  --ok: #60d394;
  --caution: #ff9f1c; /* 見やすいオレンジ寄り */
  --warning: #ff1b1b; /* 真っ赤 */
  --expired: #b388ff;

  --focus: rgba(96, 211, 148, 0.35);

  --pill-bg: rgba(255,255,255,0.04);
  --field-bg: rgba(8,14,28,.55);
  --thead-bg: rgba(15, 24, 44, 0.92);
  --thead-hover: rgba(18, 30, 56, 0.92);
  --thead-text: rgba(233,238,252,0.85);
  --row-hover: rgba(255,255,255,0.03);
}

/* ===== Light mode ===== */
body[data-theme="light"] {
  --bg: #f4f6fb;
  --card: rgba(0,0,0,0.04);
  --card2: rgba(0,0,0,0.06);
  --text: #0b1220;
  --muted: rgba(11,18,32,0.65);
  --line: rgba(0,0,0,0.14);
  --shadow: 0 18px 45px rgba(0,0,0,0.15);

  --pill-bg: rgba(255,255,255,0.7);
  --field-bg: rgba(255,255,255,0.92);
  --thead-bg: rgba(255,255,255,0.92);
  --thead-hover: rgba(255,255,255,0.96);
  --thead-text: rgba(11,18,32,0.78);
  --row-hover: rgba(0,0,0,0.03);
}

* { box-sizing: border-box; }

/* iPhone等で初回だけ横にはみ出す現象の対策 */
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: radial-gradient(1200px 800px at 10% 10%, rgba(96, 211, 148, 0.12), transparent 60%),
              radial-gradient(900px 700px at 90% 30%, rgba(179, 136, 255, 0.12), transparent 55%),
              var(--bg);
  color: var(--text);
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 22px 16px 40px;
}

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.03em;
}

.sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.pillbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  max-width: 100%;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--pill-bg);
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  max-width: 100%;
}

.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok), transparent 55%); }
.pill.caution { color: var(--caution); border-color: color-mix(in srgb, var(--caution), transparent 55%); }
.pill.warning { color: var(--warning); border-color: color-mix(in srgb, var(--warning), transparent 55%); }
.pill.expired { color: var(--expired); border-color: color-mix(in srgb, var(--expired), transparent 55%); }

.pill strong { color: inherit; font-weight: 700; white-space: nowrap; }

.grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 14px;
}

@media (max-width: 920px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}

.card .head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 25%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.card .head h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: color-mix(in srgb, var(--text), transparent 12%);
}

.card .body {
  padding: 14px;
}

label {
  display: block;
  margin: 10px 0 6px;
  font-size: 12px;
  color: var(--muted);
}

input[type="text"],
input[type="date"],
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--line), transparent 20%);
  background: var(--field-bg);
  color: var(--text);
  outline: none;
  max-width: 100%;
}

input[type="text"]:focus,
input[type="date"]:focus,
select:focus {
  border-color: rgba(96, 211, 148, 0.55);
  box-shadow: 0 0 0 4px var(--focus);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

button {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--line), transparent 20%);
  background: var(--pill-bg);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0.02em;
  max-width: 100%;
}

button.primary {
  border-color: rgba(96, 211, 148, 0.35);
  background: linear-gradient(180deg, rgba(96, 211, 148, 0.22), rgba(96, 211, 148, 0.12));
}

.hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
}

.tools input[type="text"] {
  max-width: 260px;
  padding: 9px 10px;
  border-radius: 999px;
}

.tools select {
  width: auto;
  min-width: 180px;
  border-radius: 999px;
  padding: 9px 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--pill-bg);
  user-select: none;
  white-space: nowrap;
}

.toggle input { transform: translateY(1px); }

.tablewrap { overflow-x: auto; overflow-y: hidden; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
}

th, td {
  padding: 12px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 30%);
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: var(--thead-bg);
  backdrop-filter: blur(6px);
  z-index: 1;
  color: var(--thead-text);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { background: var(--thead-hover); }
th.sortable:focus {
  outline: 2px solid rgba(96, 211, 148, 0.55);
  outline-offset: -2px;
}
.thwrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.thsort {
  font-size: 11px;
  color: color-mix(in srgb, var(--thead-text), transparent 15%);
}
th.sortable[data-dir="asc"] .thsort::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid currentColor;
}
th.sortable[data-dir="desc"] .thsort::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid currentColor;
}
th.sortable:not([data-dir]) .thsort::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid currentColor;
  opacity: 0.25;
}

tr:hover td { background: var(--row-hover); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--line), transparent 10%);
  background: var(--pill-bg);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: currentColor;
}

.b-ok { border-color: color-mix(in srgb, var(--ok), transparent 65%); }
.b-caution { border-color: color-mix(in srgb, var(--caution), transparent 60%); }
.b-warning { border-color: color-mix(in srgb, var(--warning), transparent 55%); }
.b-expired { border-color: color-mix(in srgb, var(--expired), transparent 55%); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}

.ok { color: var(--ok); }
.caution { color: var(--caution); }
.warning { color: var(--warning); }
.expired { color: var(--expired); }

.muted { color: var(--muted); }

.danger {
  border-color: color-mix(in srgb, var(--warning), transparent 55%);
  background: color-mix(in srgb, var(--warning), transparent 88%);
}

.empty {
  padding: 26px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.btn-mini {
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 12px;
}

/* ===== smartphone ===== */
@media (max-width: 600px) {
  .wrap {
    max-width: 100%;
    padding: 16px 12px 28px;
  }

  header { gap: 10px; }

  /* ピルが「最後だけ全幅」になりやすいので、2列グリッドにして整える */
  .pillbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    justify-content: stretch;
  }

  /* テーマ切替だけは1行を使う */
  #themeToggle {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .pill {
    width: 100%;
    justify-content: center;
    white-space: normal;
    line-height: 1.25;
  }

  .tools {
    justify-content: flex-start;
  }
  .tools input[type="text"],
  .tools select {
    max-width: 100%;
    min-width: 0;
    width: 100%;
  }

  .tablewrap { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  table { min-width: 0; }

  tr {
    padding: 10px 12px;
    border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 20%);
  }

  td {
    padding: 6px 0;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: normal;
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 5.5em;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.02em;
  }

  td[data-label="状態"],
  td[data-label="操作"] {
    justify-content: flex-end;
  }
}
