:root {
  --bg0: #0c1b2a;
  --bg1: #16324a;
  --ink: #eef4f8;
  --muted: #9db2c4;
  --accent: #2bb0a6;
  --accent-2: #f0a202;
  --panel: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --radius: 18px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --font: "Noto Sans SC", "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg0), var(--bg1) 55%, #0f2436);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.15;
  background-image:
    linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 28px 28px;
}

.page {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 22px 16px 48px;
  position: relative;
  z-index: 1;
}

.hero { padding: 8px 4px 18px; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { margin: 0; color: var(--accent); font-size: 0.82rem; letter-spacing: 0.18em; }
.hero h1 { margin: 8px 0; font-size: clamp(1.8rem, 6vw, 2.4rem); }
.sub { margin: 0; color: var(--muted); line-height: 1.55; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.field { display: grid; gap: 8px; margin-bottom: 14px; }
.field span { font-size: 0.9rem; color: var(--muted); }
.field em { color: var(--accent-2); font-style: normal; font-size: 0.8rem; margin-left: 6px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(8, 20, 32, 0.55);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px;
  font: inherit;
  outline: none;
}

textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
input[readonly] { opacity: 0.92; }

.voice-row { margin-bottom: 14px; }
.mic-btn {
  width: 100%;
  min-height: 64px;
  border: 0;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: #06231f;
  background: linear-gradient(135deg, #3fd0c3, #2bb0a6);
}
.mic-btn.recording { background: linear-gradient(135deg, #ff7a59, #e4572e); color: #fff; }
.status { text-align: center; color: var(--muted); font-size: 0.85rem; }

.primary-btn, .ghost-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 14px;
}
.primary-btn {
  width: 100%;
  min-height: 52px;
  border: 0;
  font-weight: 700;
  color: #162028;
  background: linear-gradient(135deg, #ffd166, var(--accent-2));
}
.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 8px 12px;
  font-size: 0.85rem;
  text-decoration: none;
}
.ghost-btn.danger-btn {
  border-color: rgba(255, 155, 130, 0.45);
  color: #ff9b82;
}
.ghost-btn.danger-btn:disabled {
  opacity: 0.4;
}

.msg { min-height: 1.4em; font-size: 0.9rem; color: var(--muted); }
.msg.ok { color: #7ddeb0; }
.msg.err { color: #ff9b82; }

.sop-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sop-head h2 { margin: 0; font-size: 1.05rem; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.fields-grid { margin: 0; display: grid; gap: 10px; }
.fields-grid div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0,0,0,0.12);
}
.fields-grid dt { margin: 0; color: var(--muted); font-size: 0.85rem; }
.fields-grid dd { margin: 0; word-break: break-word; }

.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history-list li {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: rgba(0,0,0,0.12);
}
.history-item { cursor: pointer; transition: background 0.15s; }
.history-item:hover { background: rgba(43,176,166,0.08); border-color: rgba(43,176,166,0.5); }
.history-list .meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 0.8rem; margin-bottom: 6px; }
.history-list .snippet { font-size: 0.9rem; line-height: 1.45; }
.empty { color: var(--muted); }

.auth-page { max-width: 480px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; padding: 4px; border-radius: 14px; background: rgba(0,0,0,0.18); border: 1px solid var(--line); }
.auth-tab { border: 0; border-radius: 10px; min-height: 42px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.auth-tab.active { background: linear-gradient(135deg, #3fd0c3, #2bb0a6); color: #06231f; }
.auth-hint { margin: 0 0 14px; color: var(--muted); font-size: 0.86rem; line-height: 1.5; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #132a3f;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-actions { margin-top: 12px; }

.nav-panel { text-align: center; }
.nav-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  line-height: 52px;
}
.back-link { text-decoration: none; }

.select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0,0,0,0.12);
}
.check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}
.check-label input[type="checkbox"],
.record-check {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.selected-count { color: var(--muted); font-size: 0.85rem; }

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.record-check-wrap {
  padding-top: 2px;
  cursor: pointer;
  flex-shrink: 0;
}
.history-body { flex: 1; min-width: 0; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.page-info { margin: 0; color: var(--muted); font-size: 0.85rem; }
.page-btns { display: flex; gap: 8px; }
.page-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.pdf-modal { padding: 0; align-items: stretch; }
.pdf-panel {
  width: 100%;
  max-width: 100%;
  max-height: 100vh;
  height: 100%;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
}
.pdf-frame-wrap {
  flex: 1;
  min-height: 50vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  margin-bottom: 12px;
}
.pdf-frame-wrap iframe {
  width: 100%;
  height: 100%;
  min-height: 50vh;
  border: 0;
}
.pdf-actions {
  display: flex;
  justify-content: center;
  padding-top: 4px;
}
.pdf-save-btn {
  width: 50%;
  min-width: 140px;
  max-width: 240px;
  display: block;
  text-align: center;
  text-decoration: none;
  line-height: 48px;
  min-height: 48px;
}
.pdf-frame-wrap[hidden] { display: none; }
.pdf-inapp-tip {
  padding: 20px 16px;
  margin-bottom: 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}
.pdf-inapp-tip[hidden] { display: none; }

@media (max-width: 480px) {
  .head-actions { width: 100%; justify-content: flex-end; }
  .head-actions .ghost-btn { flex: 1; min-width: 0; text-align: center; }
  .history-list .meta { flex-direction: column; align-items: flex-start; }
  .pagination { flex-direction: column; align-items: stretch; }
  .page-btns { width: 100%; }
  .page-btns .ghost-btn { flex: 1; text-align: center; }
  .fields-grid div { grid-template-columns: 1fr; }
}
