:root {
  color-scheme: light dark;
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-alt: #f1f3f7;
  --sidebar-bg: #1e1e2e;
  --sidebar-fg: #cdd6f4;
  --sidebar-muted: #7f849c;
  --sidebar-hover: rgba(250, 179, 135, 0.15);
  --sidebar-active: rgba(250, 179, 135, 0.22);
  --ink: #1e1e2e;
  --muted: #6c7086;
  --line: #e0e2e8;
  --accent: #e8720e;
  --accent-hover: #c45f0a;
  --accent-soft: rgba(232, 114, 14, 0.10);
  --accent-badge: rgba(232, 114, 14, 0.12);
  --accent-badge-fg: #b85a0b;
  --danger: #dc3545;
  --danger-hover: #bb2d3b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 0.2s ease;
  --font: "Inter", "Segoe UI", "Yu Gothic UI", "Meiryo", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg: #11111b;
  --surface: #1e1e2e;
  --surface-alt: #181825;
  --sidebar-bg: #11111b;
  --sidebar-fg: #cdd6f4;
  --sidebar-muted: #585b70;
  --sidebar-hover: rgba(232, 114, 14, 0.12);
  --sidebar-active: rgba(232, 114, 14, 0.18);
  --ink: #cdd6f4;
  --muted: #a6adc8;
  --line: #313244;
  --accent: #e8720e;
  --accent-hover: #f09040;
  --accent-soft: rgba(232, 114, 14, 0.10);
  --accent-badge: rgba(232, 114, 14, 0.15);
  --accent-badge-fg: #f09540;
  --danger: #f38ba8;
  --danger-hover: #eba0ac;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand p {
  color: var(--sidebar-muted);
  font-size: 12px;
  margin-top: 1px;
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: transparent;
  color: var(--sidebar-muted);
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.nav-button:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-fg);
}

.nav-button.active {
  background: var(--sidebar-active);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: transparent;
  color: var(--sidebar-muted);
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.theme-toggle:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-fg);
}

.theme-icon-moon {
  display: none;
}

[data-theme="dark"] .theme-icon-sun {
  display: none;
}

[data-theme="dark"] .theme-icon-moon {
  display: block;
}

.main {
  min-width: 0;
  padding: 28px 32px;
  padding-bottom: 40px;
  overflow-y: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
}

.topbar h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.primary-button,
.ghost-button,
.danger-button,
.file-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0 16px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  transition: all var(--transition);
}

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

.primary-button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.ghost-button {
  border-color: var(--line);
}

.ghost-button:hover {
  background: var(--surface-alt);
}

.danger-button {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.danger-button:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  padding: 0;
  border-color: var(--line);
  font-size: 16px;
}

.icon-button:hover {
  background: var(--surface-alt);
}

.file-button {
  display: inline-grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.15s ease;
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  transition: all var(--transition);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 16px;
}

.members-layout {
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--line);
  transition: all var(--transition);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  margin-bottom: 12px;
}

.panel h3 {
  font-size: 16px;
  font-weight: 700;
}

.submission-list,
.member-list,
.reminder-box {
  display: grid;
}

.submission-list.wide {
  max-width: 960px;
}

.submission-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
  transition: background var(--transition);
}

.submission-card:hover {
  background: var(--accent-soft);
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
  border-radius: var(--radius-sm);
}

.submission-card:first-child {
  border-top: 0;
}

.submission-card h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.submission-card p {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--accent-badge);
  color: var(--accent-badge-fg);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge.done {
  background: rgba(34, 197, 94, 0.12);
  color: #16a34a;
}

.badge.late {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
}

.badge.soon {
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
}

.progress-block {
  min-width: 0;
  text-align: right;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.progress-number {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.progress-track {
  overflow: hidden;
  height: 4px;
  margin-top: 8px;
  border-radius: 999px;
  background: var(--line);
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  max-width: 960px;
  margin-bottom: 16px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  flex: 1;
  max-width: 320px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: var(--surface);
  transition: border-color var(--transition);
}

.search-wrap:focus-within {
  border-color: var(--accent);
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color var(--transition), background var(--transition);
}

select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

select,
input {
  min-height: 38px;
  padding: 0 10px;
  font-size: 13px;
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 10px 12px;
  font-size: 13px;
}

.form-stack,
.form-grid {
  display: grid;
  gap: 14px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}

label input,
label select {
  width: 100%;
}

.member-group + .member-group {
  margin-top: 16px;
}

.member-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.member-row:first-of-type {
  border-top: 0;
}

.member-row strong {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.member-row > div > span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.reminder-item {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.reminder-item:first-child {
  border-top: 0;
}

.reminder-item strong {
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
}

.reminder-item textarea {
  min-height: 80px;
  font-size: 12px;
  background: var(--surface-alt);
}

.settings-panel {
  max-width: 640px;
}

.settings-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-md), 0 0 0 1px var(--line);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}

.modal {
  display: grid;
  gap: 16px;
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal h3 {
  font-size: 18px;
  font-weight: 700;
}

.detail-modal p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.detail-summary {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.summary-cell {
  padding: 14px 16px;
}

.summary-cell + .summary-cell {
  border-left: 1px solid var(--line);
}

.summary-cell span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-cell strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  font-weight: 700;
}

.status-table {
  display: grid;
}

.status-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.status-name {
  font-weight: 600;
}

.status-actions {
  display: flex;
  gap: 4px;
}

.status-btn {
  min-height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 0 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.status-btn:hover {
  background: var(--surface-alt);
  color: var(--ink);
}

.status-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.status-row.header {
  min-height: 32px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-top: 0;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 8px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(12px);
  opacity: 0;
  max-width: 360px;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  transition: all 0.25s ease;
  pointer-events: none;
  z-index: 100;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.empty {
  min-height: 100px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px 16px;
    flex-direction: row;
    align-items: center;
    gap: 16px;
  }

  .brand {
    margin-bottom: 0;
    flex-shrink: 0;
  }

  .nav {
    flex: 1;
    flex-direction: row;
    gap: 4px;
  }

  .nav-button {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 40px;
    padding: 6px;
    font-size: 11px;
  }

  .nav-icon {
    width: 18px;
    height: 18px;
  }

  .sidebar-footer {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
    flex-shrink: 0;
  }

  .theme-toggle {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 40px;
    font-size: 11px;
    padding: 6px;
  }

  .theme-toggle .nav-icon {
    width: 18px;
    height: 18px;
  }

  .main {
    padding: 20px;
    padding-bottom: 32px;
  }

  .metric-grid,
  .content-grid,
  .members-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    padding-bottom: 72px;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    flex-direction: row;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }

  .brand {
    display: none;
  }

  .sidebar-footer {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
    flex-shrink: 0;
  }

  .nav {
    flex: 1;
    flex-direction: row;
    gap: 4px;
  }

  .nav-button {
    min-height: 50px;
    border-radius: var(--radius-sm);
  }

  .nav-icon {
    width: 20px;
    height: 20px;
  }

  .theme-toggle {
    min-height: 50px;
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    padding: 4px 8px;
  }

  .theme-toggle .nav-icon {
    width: 20px;
    height: 20px;
  }

  .main {
    padding: 16px 14px 20px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 20px;
  }

  .topbar h2 {
    font-size: 22px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 38px 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    padding: 16px;
  }

  .metric strong {
    font-size: 26px;
  }

  .panel {
    padding: 16px;
  }

  .toolbar {
    flex-direction: column;
  }

  .search-wrap {
    max-width: none;
  }

  .submission-card,
  .status-row,
  .form-grid,
  .detail-summary {
    grid-template-columns: 1fr;
  }

  .progress-block {
    text-align: left;
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .progress-track {
    flex: 1;
    margin-top: 0;
  }

  .summary-cell + .summary-cell {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions button {
    width: 100%;
  }

  dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .modal {
    max-height: calc(100dvh - 16px);
    overflow: auto;
    padding: 18px;
  }

  .toast {
    right: 12px;
    left: 12px;
    bottom: 80px;
    max-width: none;
  }
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

.auth-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.auth-brand h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.auth-brand p {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 0;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.auth-tab {
  padding: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-form {
  display: none;
  grid-gap: 14px;
}

.auth-form.active {
  display: grid;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  min-height: 0;
}

@media (max-width: 640px) {
  .auth-card {
    padding: 24px 20px;
  }
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  padding-top: 8px;
}

.user-name {
  font-size: 12px;
  color: var(--sidebar-muted);
  font-weight: 500;
}

.logout-button {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  background: transparent;
  color: var(--sidebar-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.logout-button:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-fg);
}

.logout-button svg {
  width: 16px;
  height: 16px;
}

.help-content {
  display: grid;
  gap: 16px;
  max-width: 640px;
}

.help-body {
  font-size: 15px;
  line-height: 1.9;
}

.help-body ol {
  padding-left: 1.5em;
}

.help-body li {
  margin-bottom: 6px;
}

.help-note {
  margin-top: 14px;
  padding: 14px 18px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 2;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  display: grid;
  place-items: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.loading-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.bulk-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.bulk-label {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

@media print {
  .sidebar,
  .topbar-actions,
  .bulk-actions,
  .modal-actions,
  .icon-button,
  .toast,
  .loading-overlay,
  .theme-toggle,
  .logout-button,
  .search-wrap,
  .toolbar select { display: none !important; }

  .app-shell { display: block; }

  .main {
    padding: 0;
  }

  body {
    background: #fff;
    color: #000;
  }

  .panel {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .submission-card {
    break-inside: avoid;
  }

  .badge { border: 1px solid #999; }
}
