:root {
  color-scheme: light;
  --bg: #f4f2ec;
  --surface: #fffefb;
  --surface-soft: #fbfaf6;
  --ink: #1d1c1a;
  --muted: #6e6a62;
  --line: #e5e1d8;
  --accent: #2f5bea;
  --accent-dark: #2346c0;
  --accent-soft: #edf1ff;
  --danger: #c0392b;
  --danger-soft: #fdeeec;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow-card: 0 1px 2px rgba(29, 28, 26, .04), 0 10px 28px -18px rgba(29, 28, 26, .35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 100% -8%, #e7edff 0%, rgba(231, 237, 255, 0) 62%),
    radial-gradient(820px 460px at -8% 0%, #fdf0e2 0%, rgba(253, 240, 226, 0) 58%),
    var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------- header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 242, 236, .84);
  border-bottom: 1px solid rgba(229, 225, 216, .9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 20px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #4b74ff 0%, #2346c0 100%);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 6px 14px -8px rgba(35, 70, 192, .9), inset 0 1px 0 rgba(255, 255, 255, .35);
}

.brand-text {
  min-width: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.25;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: .02em;
  white-space: nowrap;
}

.today-chip {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 254, 251, .8);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .03em;
  font-variant-numeric: tabular-nums;
}

/* ---------- layout ---------- */

.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ---------- sync ---------- */

.sync-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: -10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 254, 251, .72);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.sync-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: #b3ada2;
}

.sync-bar[data-state="synced"] .sync-dot {
  background: #2f9e6b;
}

.sync-bar[data-state="syncing"] .sync-dot {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.sync-bar[data-state="offline"] .sync-dot {
  background: #d18a2d;
}

.sync-bar[data-state="auth"] .sync-dot,
.sync-bar[data-state="error"] .sync-dot {
  background: var(--danger);
}

.sync-text {
  flex: 1;
  min-width: 0;
}

.sync-open {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 7px;
  margin: -5px -7px -5px 0;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.sync-open:hover {
  background: var(--accent-soft);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* ---------- form ---------- */

.form-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: box-shadow .25s ease, border-color .25s ease;
}

.form-card.is-editing {
  border-color: rgba(47, 91, 234, .45);
  box-shadow: 0 0 0 3px rgba(47, 91, 234, .08), var(--shadow-card);
}

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .04em;
}

.ghost-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  margin: -6px -10px -6px 0;
  border-radius: 9px;
  cursor: pointer;
}

.ghost-btn:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  position: relative;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .08em;
}

input[type="date"],
input[type="text"],
input[type="search"],
input[type="password"],
textarea {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"] {
  min-height: 48px;
  font-variant-numeric: tabular-nums;
}

input::placeholder,
textarea::placeholder {
  color: #767168;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 91, 234, .13);
}

textarea {
  min-height: 148px;
  line-height: 1.75;
  resize: none;
  overflow-y: auto;
  padding-bottom: 30px;
}

.counter {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(251, 250, 246, 0), var(--surface-soft) 30%);
  padding-left: 10px;
}

.primary-btn {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #3d68f2 0%, var(--accent) 55%, var(--accent-dark) 100%);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .12em;
  cursor: pointer;
  box-shadow: 0 10px 20px -12px rgba(35, 70, 192, .85), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .12s ease, filter .15s ease, box-shadow .15s ease;
}

.primary-btn:hover {
  filter: brightness(1.05);
}

.primary-btn:active {
  transform: translateY(1px) scale(.995);
  box-shadow: 0 5px 12px -10px rgba(35, 70, 192, .9);
}

.primary-btn:focus-visible,
.ghost-btn:focus-visible,
.action-btn:focus-visible,
.dialog-btn:focus-visible {
  outline: 3px solid rgba(47, 91, 234, .35);
  outline-offset: 2px;
}

.form-note {
  margin: -6px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- list ---------- */

.list-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.list-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .05em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 254, 251, .75);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}

.search-wrap {
  position: relative;
  flex: 0 1 240px;
  min-width: 160px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: #9a958b;
  pointer-events: none;
}

.search-wrap input[type="search"] {
  padding: 9px 12px 9px 34px;
  font-size: 14px;
  border-radius: 999px;
  background: rgba(255, 254, 251, .8);
}

.search-wrap input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.report-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.report-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px 12px;
  box-shadow: 0 1px 2px rgba(29, 28, 26, .03);
  animation: rise .4s cubic-bezier(.2, .7, .3, 1) both;
  animation-delay: var(--delay, 0ms);
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

@media (hover: hover) {
  .report-card:hover {
    border-color: #d8d3c8;
    box-shadow: var(--shadow-card);
    transform: translateY(-1px);
  }
}

.report-card.just-saved {
  animation: saved 1.6s ease;
}

.report-top {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 12px;
}

.date-badge {
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  border: 1px solid rgba(47, 91, 234, .12);
}

.date-day {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

.date-wd {
  font-size: 10.5px;
  font-weight: 600;
  margin-top: 3px;
}

.report-meta {
  min-width: 0;
  flex: 1;
}

.report-date {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  letter-spacing: .01em;
}

.relative-chip {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
  letter-spacing: .04em;
}

.report-name {
  margin: 4px 0 0;
  font-size: 14.5px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-name.is-empty {
  color: var(--muted);
  font-weight: 500;
}

.report-body {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #2b2926;
}

.report-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.action-btn .icon {
  width: 15px;
  height: 15px;
}

.action-btn:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.action-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- empty ---------- */

.empty-state {
  text-align: center;
  padding: 40px 24px 44px;
  border: 1.5px dashed #dcd6ca;
  border-radius: var(--radius-lg);
  background: rgba(255, 254, 251, .5);
}

.empty-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: rgba(47, 91, 234, .07);
  color: var(--accent);
  display: grid;
  place-items: center;
}

.empty-icon svg {
  width: 28px;
  height: 28px;
}

.empty-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
}

.empty-text {
  margin: 7px 0 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}

/* ---------- footer ---------- */

.app-footer {
  padding: 10px 0 30px;
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .02em;
}

/* ---------- dialog ---------- */

.confirm-dialog {
  border: 0;
  padding: 24px;
  border-radius: 20px;
  width: min(340px, calc(100vw - 40px));
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(20, 18, 16, .45);
}

.confirm-dialog::backdrop {
  background: rgba(24, 22, 19, .42);
  backdrop-filter: blur(3px);
}

.confirm-dialog h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .02em;
}

.confirm-dialog p {
  margin: 8px 0 20px;
  font-size: 13px;
  color: var(--muted);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dialog-btn {
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.dialog-btn:hover {
  background: #f2f0ea;
}

.dialog-btn.danger {
  border-color: transparent;
  background: var(--danger);
  color: #fff;
}

.dialog-btn.danger:hover {
  background: #a93226;
}

.dialog-btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.dialog-btn.primary:hover {
  background: var(--accent-dark);
}

.dialog-btn:disabled {
  opacity: .6;
  cursor: default;
}

.sync-dialog .sync-description {
  margin: 8px 0 16px;
}

.sync-dialog .field {
  gap: 6px;
}

.sync-error {
  margin: 10px 0 0 !important;
  color: var(--danger);
  font-size: 12.5px !important;
  font-weight: 600;
  line-height: 1.5;
}

.sync-disconnect {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 6px;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.sync-disconnect:hover {
  text-decoration: underline;
}

.sync-dialog .sync-note {
  margin: 14px 0 0 !important;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 100;
  max-width: calc(100vw - 40px);
  padding: 11px 20px;
  border-radius: 999px;
  background: rgba(29, 28, 26, .94);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  text-align: center;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .5);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* ---------- animations ---------- */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes saved {
  0% {
    background: #eef3ff;
    border-color: rgba(47, 91, 234, .5);
  }
  100% {
    background: var(--surface);
    border-color: var(--line);
  }
}

/* ---------- responsive ---------- */

@media (max-width: 560px) {
  .header-inner {
    padding-left: 16px;
    padding-right: 16px;
  }

  .app-main {
    padding: 16px 14px 4px;
    gap: 22px;
  }

  .form-card {
    padding: 16px;
    border-radius: 18px;
  }

  .list-head {
    align-items: stretch;
  }

  .search-wrap {
    flex: 1 1 100%;
  }

  .search-wrap input[type="search"] {
    font-size: 16px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .report-card {
    padding: 14px 15px 10px;
  }

  .action-btn {
    padding: 8px 9px;
    min-height: 42px;
  }

  .toast {
    bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 430px) {
  .brand-text p {
    display: none;
  }

  .field-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  input[type="date"],
  input[type="text"] {
    padding-left: 11px;
    padding-right: 9px;
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-delay: 0ms !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
