/* Dark theme (default) */
html[data-theme="dark"],
body[data-theme="dark"] {
  background: linear-gradient(180deg, #0b0f14 0%, #0e141c 100%);
}

body[data-theme="dark"] {
  --bg: #0b0f14;
  --card: #121922;
  --muted: #9db0c6;
  --text: #e7eef7;
  --accent: #4da3ff;
  --warn: #ff7b6b;
  --ok: #63d297;
  --border: #253041;
}

/* Light theme */
body[data-theme="light"] {
  --bg: #f5f7fa;
  --card: #ffffff;
  --muted: #6b7280;
  --text: #1f2937;
  --accent: #2563eb;
  --warn: #dc2626;
  --ok: #16a34a;
  --border: #e5e7eb;
}

html[data-theme="light"],
body[data-theme="light"] {
  background: linear-gradient(180deg, #f5f7fa 0%, #e5e7eb 100%);
}

body[data-theme="light"] .app-header {
  background: #fffffff0;
}

body[data-theme="light"] .kpi-item {
  background: linear-gradient(135deg, #ffffff 0%, #f3f4f6 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
body[data-theme="light"] .kpi-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}
body[data-theme="light"] .kpi-item.warn {
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
}
body[data-theme="light"] .kpi-item span {
  color: #1f2937;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

body[data-theme="light"] .table th { background: #f9fafb; }
body[data-theme="light"] .table th:first-child {
  background: #f9fafb;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.08);
}
body[data-theme="light"] .table td:first-child {
  background: #ffffff;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.08);
}
body[data-theme="light"] .table tr:hover td { background: #f3f4f6; }
body[data-theme="light"] .table tr:hover td:first-child {
  background: #f3f4f6;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.08);
}

body[data-theme="light"] .btn { background: #f3f4f6; color: #1f2937; }
body[data-theme="light"] .btn:hover { background: #e5e7eb; border-color: #9ca3af; }
body[data-theme="light"] .primary { background: #dbeafe; border-color: #60a5fa; color: #1e40af; }
body[data-theme="light"] .btn.primary:hover { background: #bfdbfe; border-color: #3b82f6; }
body[data-theme="light"] .btn-secondary { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
body[data-theme="light"] .btn-tertiary { background: #f9fafb; border-color: #d1d5db; color: #4b5563; }
body[data-theme="light"] .btn-danger { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
body[data-theme="light"] .btn-danger:hover { background: #fecaca; border-color: #f87171; }

body[data-theme="light"] .input { background: #ffffff; color: #1f2937; border-color: #d1d5db; }
body[data-theme="light"] .input::placeholder { color: #9ca3af; }
body[data-theme="light"] .input:focus { background: #ffffff; border-color: #2563eb; }

body[data-theme="light"] label { color: #4b5563; }

body[data-theme="light"] .input-hint { color: #6b7280; }

body[data-theme="light"] .qr:empty { background: #f9fafb; }
body[data-theme="light"] .qr:not(:empty) { background: #ffffff; border-color: #d1d5db; }
body[data-theme="light"] .audit-box { background: #f9fafb; }
body[data-theme="light"] .mobile-menu { background: #ffffff; }

body[data-theme="light"] .lifecycle {
  background: #f9fafb;
  border-color: #e5e7eb;
}

body[data-theme="light"] .lifecycle-step {
  background: #ffffff;
  border-left-color: #2563eb;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, #0b0f14 0%, #0e141c 100%);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", "Apple Color Emoji","Segoe UI Emoji";
}

a { color: var(--accent); }
.app-header, .app-footer { padding: 16px; background: transparent; }
.app-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: #0b0f14b3;
  position: sticky;
  top: 0;
  backdrop-filter: blur(6px);
  z-index: 50;
  padding: 12px 16px;
}
.header-left { /* spacer */ }
.header-center {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.app-header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header-tagline {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}
.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.mobile-menu-btn { display: none; }
.mobile-menu {
  position: absolute;
  top: 60px;
  right: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  z-index: 100;
  min-width: 220px;
}
.mobile-menu.hidden { display: none; }

.container { width: min(1100px, 92%); margin: 20px auto 40px; display: grid; gap: 16px; }


.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-header h2 { margin: 0 0 10px; font-size: 18px; }
.card-body { padding: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.kpi { display: flex; gap: 16px; flex-wrap: wrap; }
.kpi-item {
  background: linear-gradient(135deg, #0e1520 0%, #1a2332 100%);
  border: 1px solid var(--border);
  padding: 16px 20px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  min-width: 120px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.kpi-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.kpi-item.warn {
  border-color: var(--warn);
  background: linear-gradient(135deg, #2a1a1a 0%, #3d2020 100%);
}
.kpi-item span {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.table-wrapper { overflow: auto; border: 1px solid var(--border); border-radius: 12px; max-height: 70vh; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; color: var(--text); }
.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  background: #0d1520;
  position: sticky;
  top: 0;
  z-index: 2;
}
.table th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #0d1520;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
}
.table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card);
  font-weight: 500;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
}
.table tr:hover td { background: #0f1725; }
.table tr:hover td:first-child {
  background: #0f1725;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3);
}
.empty-state { text-align: center; color: var(--muted); font-style: italic; padding: 40px 20px !important; white-space: normal; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #1a2332;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .05s ease, background .2s ease, border-color .2s ease;
  font-weight: 500;
  font-size: 14px;
}
.btn:hover { background: #243143; border-color: #3a4e6b; }
.btn:active { transform: translateY(1px) scale(.99); }
.primary {
  background: #1e3a5f;
  border-color: #2d5a99;
  color: #a8c5e8;
}
.btn.primary:hover {
  background: #254875;
  border-color: #3b6fb3;
  color: #d1e3f8;
}
.btn-secondary {
  background: #3d2020;
  border-color: #7d4545;
  color: #ffb8b8;
}
.btn-secondary:hover {
  background: #4d2828;
  border-color: #9d5555;
}
.btn-tertiary {
  background: #1a2129;
  border-color: #344151;
  color: #c7d3e6;
}
.btn-sm { min-width: 44px; min-height: 44px; padding: 6px 10px; font-size: 13px; }
.warn-text { color: var(--warn); }
.ok-text { color: var(--ok); }

.theme-icon {
  font-size: 18px;
  display: inline-block;
  line-height: 1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

.required {
  color: #ff6b6b;
  font-weight: 700;
  margin-left: 4px;
}

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0e1622;
  color: var(--text);
  font-size: 14px;
}
.input::placeholder {
  color: #5a6d85;
}
.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
  background: #121b2a;
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon {
  position: absolute;
  left: 12px;
  font-size: 18px;
  pointer-events: none;
  z-index: 1;
}
.input-datetime {
  padding-left: 42px;
  cursor: pointer;
}
.input-datetime::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 1;
  filter: brightness(1.5) contrast(1.2);
  transition: filter 0.2s;
}
.input-datetime::-webkit-calendar-picker-indicator:hover {
  filter: brightness(2) contrast(1.5);
}

.input-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bullet-list { margin: 6px 0 0 16px; padding: 0; }
.bullet-list li { margin: 4px 0; }

dialog { border: none; padding: 0; border-radius: 14px; background: transparent; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.modal { background: var(--card); padding: 16px; border: 1px solid var(--border); border-radius: 14px; min-width: min(720px, 92vw); }
.modal h3 { margin: 6px 0 12px; }

.modal-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin: 16px 0 0 0;
  padding: 0;
}

.btn-delete {
  align-self: flex-start;
  font-size: 13px;
  padding: 7px 12px;
  opacity: 0.85;
  transition: opacity 0.2s, transform 0.05s;
}
.btn-delete:hover {
  opacity: 1;
}
.btn-danger {
  background: #3d2020;
  border-color: #7d4545;
  color: #ffb8b8;
}
.btn-danger:hover {
  background: #4d2828;
  border-color: #9d5555;
}
.delete-icon {
  font-size: 14px;
  margin-right: 4px;
}

.qr-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.qr-block h4 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.qr {
  width: 210px;
  height: 210px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 12px;
  font-size: 13px;
  text-align: center;
  padding: 10px;
  margin-bottom: 12px;
  position: relative;
}

/* Empty state - dark background with text */
.qr:empty {
  background: #0e1520;
  color: var(--muted);
}
.qr:empty::before {
  content: "ボタンを押してQRコードを生成";
}

/* QR code displayed - white background */
.qr:not(:empty) {
  background: #ffffff;
  padding: 12px;
  border: 1px solid var(--border);
}

.qr-info {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  font-family: monospace;
  word-break: break-all;
  display: none;
}
.qr-info.show {
  display: block;
}

.audit-box {
  background: #0e1520; border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; max-height: 60vh; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono","Noto Sans Mono", monospace;
  white-space: pre-wrap;
}

.modal-help {
  max-width: min(800px, 92vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.help-content {
  overflow-y: auto;
  padding: 8px 0;
  flex: 1;
  margin-bottom: 12px;
  color: var(--text);
}

.help-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.help-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.help-section h4 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.help-section ol,
.help-section ul {
  margin: 0;
  padding-left: 24px;
  line-height: 1.7;
  color: var(--text);
}

.help-section li {
  margin-bottom: 12px;
  color: var(--text);
}

.help-section li strong {
  color: var(--accent);
  font-weight: 600;
}

.help-section br {
  line-height: 1.7;
}

.lifecycle {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: #0e1520;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.lifecycle-step {
  padding: 10px 14px;
  background: #1a2332;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  line-height: 1.6;
  color: var(--text);
}

.lifecycle-arrow {
  text-align: center;
  font-size: 20px;
  color: var(--accent);
  margin: 4px 0;
}

.import-label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.app-footer .footer {
  width: min(1100px, 92%); margin: 0 auto 20px; text-align: center; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 16px;
}

@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .modal { min-width: 92vw; }

  .app-header {
    grid-template-columns: 1fr auto;
    padding: 10px 12px;
  }
  .header-left { display: none; }
  .header-center {
    text-align: left;
    gap: 2px;
  }
  .app-header h1 { font-size: 19px; }
  .header-tagline { font-size: 12px; }

  .header-actions > *:not(.mobile-menu-btn) { display: none; }
  .mobile-menu-btn { display: inline-flex; }
}
