* { box-sizing: border-box; }
html, body { height: 100%; }

/* HTML の hidden 属性を確実に効かせる。
   header a 等に display:inline-flex を指定していると hidden が上書きされて
   見えてしまうので、属性セレクタで !important を付けて優先する。 */
[hidden] { display: none !important; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic",
    "Noto Sans JP", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
  color: #111827;
  background: #f6f7f9;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 4px;
}

header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: #1f2937;
  color: #fff;
  flex-wrap: wrap;
}
header h1 {
  font-size: 17px;
  margin: 0;
  flex: 1 1 auto;
  letter-spacing: 0.02em;
}
header .muted { color: rgba(255,255,255,0.75); font-size: 13px; }
header a, header button {
  color: #e5e7eb;
  background: transparent;
  border: 1px solid #4b5563;
  font-size: 14px;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
header a:hover, header button:hover { background: #374151; }
header a#adminLink {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
header a#adminLink:hover { background: #1d4ed8; border-color: #1d4ed8; }

main { padding: 20px; max-width: 1100px; margin: 0 auto; }

.hint {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  padding: 14px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  margin-bottom: 16px;
}
.controls label { font-size: 12px; color: #4b5563; display: block; margin-bottom: 4px; }
.controls input, .controls select {
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  min-height: 36px;
}
.controls input:focus, .controls select:focus { border-color: #2563eb; }

.btn {
  padding: 8px 14px;
  font-size: 14px;
  background: #2563eb;
  color: #fff;
  border: 1px solid #2563eb;
  border-radius: 6px;
  cursor: pointer;
  min-height: 36px;
  line-height: 1.2;
}
.btn:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn:disabled { background: #9ca3af; border-color: #9ca3af; cursor: not-allowed; }
.btn.secondary { background: #fff; color: #374151; border-color: #d1d5db; }
.btn.secondary:hover { background: #f3f4f6; }

.table-wrap {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 520px; }
th, td {
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
th { background: #f9fafb; font-weight: 600; color: #374151; }
tr:hover td { background: #f9fafb; }

.status {
  padding: 8px 0;
  color: #6b7280;
  font-size: 14px;
}
.status.error { color: #b91c1c; }
.status.success { color: #15803d; }

.empty { padding: 48px 20px; text-align: center; color: #9ca3af; font-size: 14px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.tabs button {
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  cursor: pointer;
  color: #6b7280;
  min-height: 40px;
}
.tabs button:hover { color: #374151; }
.tabs button.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 600;
}
.panel { background: #fff; padding: 18px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.panel + .panel { margin-top: 16px; }
.panel h2 { font-size: 15px; margin: 0 0 8px; color: #374151; }
.panel .note { color: #6b7280; font-size: 13px; margin: 0 0 12px; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.muted { color: #9ca3af; }
.danger { color: #b91c1c; }

input.input, select.input {
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  min-height: 36px;
  background: #fff;
}
input.input:focus, select.input:focus { border-color: #2563eb; }

code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.note-small {
  font-size: 12px;
  color: #6b7280;
  margin: -8px 0 14px;
}

.location-label {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: #111827;
}
.location-label .loc-id {
  margin-left: 8px;
  color: #6b7280;
  font-weight: 400;
  font-size: 13px;
}
.location-label .loc-expires {
  margin-left: 8px;
  color: #b45309;
  font-weight: 400;
  font-size: 12px;
}
.location-missing {
  color: #b91c1c;
  font-size: 14px;
  padding: 8px 0;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { background: #f3f4f6; }
th.sortable .sort-icon {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  color: #9ca3af;
}
th.sortable.sort-asc .sort-icon::after { content: "▲"; color: #2563eb; }
th.sortable.sort-desc .sort-icon::after { content: "▼"; color: #2563eb; }
th.sortable:not(.sort-asc):not(.sort-desc) .sort-icon::after { content: "⇅"; }

/* --- Login page ----------------------------------------------------------- */
.auth-body {
  background: linear-gradient(180deg, #e0e7ff 0%, #f6f7f9 40%);
}
.auth-main {
  padding: 40px 16px;
  max-width: 460px;
  margin: 0 auto;
}
.auth-card {
  background: #fff;
  padding: 28px 28px 24px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  margin-top: 40px;
}
.auth-title {
  font-size: 18px;
  margin: 0 0 18px;
  color: #1f2937;
  text-align: center;
  letter-spacing: 0.02em;
}
.auth-form h2 {
  font-size: 16px;
  margin: 0 0 8px;
  color: #111827;
}
.auth-lead { margin: 0 0 16px; font-size: 13px; }
.auth-form label {
  display: block;
  font-size: 13px;
  color: #374151;
  margin: 12px 0 4px;
}
.auth-form .input { width: 100%; }
.auth-form .btn {
  width: 100%;
  margin-top: 18px;
  font-size: 15px;
  padding: 10px 14px;
}
.auth-error {
  margin-top: 12px;
  padding: 8px 12px;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 6px;
  font-size: 13px;
}
.auth-help {
  margin: 16px 0 0;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
}

.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 44px; }
.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: #6b7280;
  border-radius: 6px;
}
.pw-toggle:hover { color: #111827; background: #f3f4f6; }
.pw-toggle:focus-visible { outline: 2px solid #2563eb; outline-offset: 1px; }
.pw-toggle svg { width: 20px; height: 20px; display: block; }
.pw-toggle .icon-eye-off { display: none; }
.pw-toggle[aria-pressed="true"] .icon-eye { display: none; }
.pw-toggle[aria-pressed="true"] .icon-eye-off { display: block; }

/* --- ファイル名クリック用のリンク / サムネモーダル --------------------- */
a.filename-link {
  color: #2563eb;
  text-decoration: underline;
  cursor: pointer;
  word-break: break-all;
}
a.filename-link:hover { color: #1d4ed8; }
a.filename-link:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; border-radius: 2px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}
.modal-dialog {
  position: relative;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
  padding: 18px 18px 22px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.modal-close {
  position: absolute;
  right: 8px;
  top: 6px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #6b7280;
  border-radius: 6px;
}
.modal-close:hover { background: #f3f4f6; color: #111827; }
.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  max-width: 80vw;
  word-break: break-all;
  padding-right: 28px;
}
.modal-body {
  min-width: 240px;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
}
.modal-hint { color: #6b7280; font-size: 13px; }
.modal-error { color: #b91c1c; font-size: 14px; padding: 24px 8px; }
.thumb-image {
  max-width: 80vw;
  max-height: 72vh;
  display: block;
  border-radius: 6px;
  background: #000;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 720px) {
  main { padding: 14px; }
  header { padding: 10px 14px; gap: 10px; }
  header h1 { font-size: 15px; width: 100%; }
  header .muted { width: 100%; margin-top: -4px; }
  .controls { gap: 8px; padding: 12px; }
  .controls > div { width: 100%; }
  .controls input, .controls select { width: 100%; }
  .btn { width: 100%; }
  .row-actions .btn { width: auto; }
  .tabs button { padding: 10px 12px; font-size: 13px; }
  table { min-width: 0; }
  th, td { padding: 8px 10px; font-size: 13px; }
}
