:root {
  color-scheme: dark;
  --bg: #080b12;
  --panel: #111724;
  --panel-2: #171f2f;
  --text: #f5f7fb;
  --muted: #a9b3c5;
  --line: #283247;
  --accent: #ff4f64;
  --accent-2: #ff7a45;
  --focus: #8cc8ff;
  --safe: #61d69c;
  --warning: #ffd166;
  --danger: #ff8190;
  font-family: Inter, "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 85% 10%, rgb(255 79 100 / 14%), transparent 28rem),
    radial-gradient(circle at 10% 90%, rgb(255 122 69 / 8%), transparent 24rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.65rem 0.9rem;
  color: #08101c;
  background: var(--focus);
  border-radius: 0.5rem;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.2rem;
  height: 2.2rem;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 0.65rem;
  box-shadow: 0 0 1.75rem rgb(255 79 100 / 25%);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(0, 1.1fr) minmax(22rem, 0.9fr);
}

.login-intro,
.login-area {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(2rem, 7vw, 7rem);
}

.eyebrow {
  margin: 0 0 0.75rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

.login-intro h1 {
  max-width: 12ch;
  margin: 2.2rem 0 1rem;
  font-size: clamp(2.5rem, 7vw, 5.8rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.lead {
  max-width: 40rem;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.8;
}

.login-card,
.panel {
  border: 1px solid var(--line);
  background: rgb(17 23 36 / 88%);
  border-radius: 1rem;
  box-shadow: 0 1.5rem 5rem rgb(0 0 0 / 30%);
}

.login-card {
  width: min(100%, 29rem);
  padding: clamp(1.5rem, 4vw, 2.5rem);
}

.login-card h2 {
  margin-bottom: 0.5rem;
  font-size: 1.55rem;
}

.subtle {
  color: var(--muted);
  line-height: 1.6;
}

.field {
  display: grid;
  gap: 0.5rem;
  margin-top: 1.2rem;
}

.field label {
  font-size: 0.9rem;
  font-weight: 700;
}

.field input {
  width: 100%;
  padding: 0.85rem 0.95rem;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 0.55rem;
}

.field input:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.button {
  min-height: 2.75rem;
  padding: 0.7rem 1rem;
  color: white;
  font-weight: 800;
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 0.55rem;
  cursor: pointer;
}

.button-block {
  width: 100%;
  margin-top: 1.4rem;
}

.button-secondary {
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.button:disabled {
  color: #8a93a3;
  background: #222a38;
  cursor: not-allowed;
}

.message {
  min-height: 1.5rem;
  margin: 1rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.5rem;
  padding: 0.75rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid var(--line);
  background: rgb(8 11 18 / 90%);
  backdrop-filter: blur(16px);
}

.account {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.account-copy {
  display: grid;
  text-align: right;
}

.account-copy span {
  color: var(--muted);
  font-size: 0.8rem;
}

.dashboard {
  width: min(100% - 2rem, 78rem);
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 4rem) 0;
}

.dashboard-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dashboard-heading h1 {
  margin-bottom: 0.3rem;
  font-size: clamp(2rem, 5vw, 3.5rem);
  letter-spacing: -0.04em;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 0.65rem;
  color: var(--warning);
  border: 1px solid rgb(255 209 102 / 35%);
  background: rgb(255 209 102 / 8%);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel {
  padding: 1.25rem;
}

.metric-label {
  margin-bottom: 0.65rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.metric-value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
}

.safe {
  color: var(--safe);
}

.warning {
  color: var(--warning);
}

.app-nav {
  display: flex;
  gap: 1rem;
  margin: 0 auto;
}

.app-nav a {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-decoration: none;
}

.app-nav a:hover {
  color: var(--text);
}

.metric-card {
  min-width: 0;
}

.console-section {
  margin-top: 1rem;
  scroll-margin-top: 6rem;
}

.section-heading,
.record-heading,
.progress-label,
.record-meta,
.safety-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-heading {
  align-items: flex-end;
  margin-bottom: 1rem;
}

.section-heading h2,
.safety-panel h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.section-kicker {
  margin-bottom: 0.3rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.filters {
  display: flex;
  align-items: flex-end;
  gap: 0.7rem;
}

.filters label,
.compact-filter {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.filters input,
.filters select,
.compact-filter select {
  min-height: 2.5rem;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 0.5rem;
}

select:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.button-compact {
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

.resource-state {
  min-height: 5rem;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 0.7rem;
}

.resource-state.error {
  color: var(--danger);
  border-color: rgb(255 129 144 / 45%);
}

.resource-state.loading::before {
  width: 1rem;
  height: 1rem;
  margin-right: 0.6rem;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  content: "";
  animation: spin 0.8s linear infinite;
}

.resource-state.loading {
  display: flex;
}

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

.project-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.sync-overview {
  margin-bottom: 1rem;
}

.production-overview {
  margin-bottom: 1rem;
}

.operations-grid {
  display: grid;
  grid-template-columns: 0.8fr 0.8fr 1.4fr;
  gap: 0.8rem;
}

.operation-card {
  min-width: 0;
  padding: 0.9rem;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 0.7rem;
}

.operation-card p:last-child {
  margin-bottom: 0;
}

.recovery-card {
  border-color: rgb(255 209 102 / 30%);
}

.metric-value.danger {
  color: var(--danger);
}

.sync-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.sync-card {
  min-width: 0;
  padding: 0.9rem;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 0.7rem;
}

.sync-card-error {
  border-color: rgb(255 129 144 / 35%);
}

.sync-facts,
.source-facts {
  display: grid;
  gap: 0.35rem;
  margin: 0.75rem 0;
}

.sync-facts div,
.source-facts div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.75rem;
}

.sync-facts dt,
.source-facts dt {
  color: var(--muted);
}

.sync-facts dd,
.source-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.sync-error,
.sync-ok {
  min-height: 0 !important;
  margin: 0.6rem 0 0;
  font-size: 0.76rem !important;
}

.sync-error {
  color: var(--danger) !important;
}

.sync-ok {
  color: var(--safe) !important;
}

.project-card,
.record-card {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 0.75rem;
}

.project-card h3,
.record-card h3 {
  margin: 0.85rem 0 0.45rem;
  overflow-wrap: anywhere;
}

.project-card p,
.record-card p {
  min-height: 2.6em;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.status,
.read-only-label,
.score {
  display: inline-flex;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
}

.status-good { color: var(--safe); border-color: rgb(97 214 156 / 35%); }
.status-bad { color: var(--danger); border-color: rgb(255 129 144 / 35%); }
.status-warn { color: var(--warning); border-color: rgb(255 209 102 / 35%); }
.status-neutral, .read-only-label, .score { color: var(--muted); }

.record-id,
.record-meta,
.progress-label {
  color: var(--muted);
  font-size: 0.75rem;
}

.progress {
  height: 0.45rem;
  overflow: hidden;
  background: var(--bg);
  border-radius: 999px;
}

.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.console-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 1rem;
}

.record-list {
  display: grid;
  gap: 0.75rem;
}

.record-meta {
  margin: 0.8rem 0;
}

.audit-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.audit-table th,
.audit-table td {
  padding: 0.75rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.audit-table th {
  color: var(--muted);
}

.trace {
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.safety-panel {
  align-items: flex-start;
  margin-top: 1rem;
  border-color: rgb(255 209 102 / 30%);
}

.danger-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.workspace {
  display: grid;
  grid-template-columns: 1.45fr 0.85fr;
  gap: 1rem;
}

.panel h2 {
  font-size: 1.05rem;
}

.empty-state {
  min-height: 15rem;
  display: grid;
  place-content: center;
  padding: 2rem;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 0.7rem;
}

.empty-state strong {
  margin-bottom: 0.5rem;
}

.action-list {
  display: grid;
  gap: 0.8rem;
}

.action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 0.7rem;
}

.action strong,
.action span {
  display: block;
}

.action span {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.session-alert {
  position: fixed;
  z-index: 30;
  right: 1rem;
  bottom: 1rem;
  max-width: 25rem;
  padding: 1rem;
  border: 1px solid var(--danger);
  background: #33151c;
  border-radius: 0.7rem;
}

[hidden] {
  display: none !important;
}

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

  .login-intro {
    padding-bottom: 0;
  }

  .login-area {
    padding-top: 2rem;
  }

  .login-intro h1 {
    margin-top: 1.5rem;
  }

  .status-grid,
  .workspace,
  .project-grid,
  .sync-grid,
  .operations-grid {
    grid-template-columns: 1fr;
  }

  .console-grid {
    grid-template-columns: 1fr;
  }

  .app-nav {
    display: none;
  }

  .dashboard-heading {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .account-copy {
    display: none;
  }

  .app-header .button {
    min-height: 2.4rem;
    padding: 0.5rem 0.7rem;
  }

  .action {
    align-items: stretch;
    flex-direction: column;
  }

  .section-heading,
  .safety-panel,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .filters label,
  .compact-filter {
    width: 100%;
  }

  .danger-actions {
    justify-content: stretch;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
