:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #eef4f2;
  --line: #d8e0df;
  --text: #16201f;
  --muted: #687674;
  --teal: #0f766e;
  --teal-soft: #dff5f0;
  --green: #23734f;
  --amber: #a16207;
  --amber-soft: #fff4d7;
  --red: #b42318;
  --red-soft: #ffe7e4;
  --blue: #2454a6;
  --violet: #6d3f8e;
  --shadow: 0 14px 36px rgba(22, 32, 31, 0.08);
  font-family: "Segoe UI", "Yu Gothic UI", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  background: #172321;
  color: #f5fbfa;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0;
  background: #24423d;
}

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

.brand span {
  color: #b9c9c6;
  font-size: 12px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-btn,
.ghost-btn,
.primary-btn,
.secondary-btn,
.plain-btn,
.danger-btn {
  border: 0;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  font-weight: 700;
}

.nav-btn {
  text-align: left;
  color: #d7e5e2;
  background: transparent;
}

.nav-btn.active,
.nav-btn:hover {
  background: #dff5f0;
  color: #12302c;
}

.operator-box {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: #d7e5e2;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding-top: 16px;
}

.operator-box span {
  color: #9eb0ad;
  font-size: 12px;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.workspace {
  min-width: 0;
  padding: 22px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.search {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.search input,
.form-grid input,
.form-grid select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.primary-btn {
  background: var(--teal);
  color: #fff;
}

.secondary-btn {
  background: var(--teal-soft);
  color: #0b6159;
}

.plain-btn {
  background: #eef1f1;
  color: #263331;
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(112px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 74px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  align-content: center;
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  font-size: 28px;
  line-height: 1.1;
}

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

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 388px;
  gap: 16px;
  align-items: start;
}

.main-panel,
.detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 640px;
  box-shadow: var(--shadow);
}

.main-panel {
  padding: 16px;
}

.detail-panel {
  position: sticky;
  top: 16px;
  padding: 16px;
}

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

.panel-head h2,
.detail h2 {
  margin: 0;
  font-size: 18px;
}

.panel-head p,
.detail p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.flow-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.flow-steps div {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  display: grid;
  align-content: center;
  gap: 3px;
}

.flow-steps strong {
  font-size: 16px;
}

.flow-steps span {
  color: var(--muted);
  font-size: 13px;
}

.flow-steps.rules div {
  background: #fbfcfc;
}

.task-list {
  display: grid;
  gap: 10px;
}

.task-card {
  width: 100%;
  min-height: 94px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
}

.task-card:hover,
.task-card.selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.task-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.task-main strong {
  font-size: 16px;
  white-space: nowrap;
}

.task-main span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-sub {
  grid-column: 1 / -1;
  color: var(--muted);
  line-height: 1.45;
}

.task-due {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.lane {
  min-height: 320px;
  border: 1px solid var(--line);
  background: #fbfcfc;
  border-radius: 8px;
  padding: 10px;
}

.lane h3 {
  margin: 0 0 8px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.queue-list {
  display: grid;
  gap: 8px;
}

.queue-card {
  width: 100%;
  min-height: 112px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  display: grid;
  align-content: start;
  gap: 8px;
}

.queue-card:hover,
.queue-card.selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.queue-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: start;
}

.card-name {
  font-size: 15px;
}

.card-meta,
.card-next {
  color: var(--muted);
  line-height: 1.45;
  display: block;
}

.card-next {
  color: #23312f;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef1f1;
  color: #354240;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.high,
.pill.critical {
  background: var(--red-soft);
  color: var(--red);
}

.pill.medium {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.good {
  background: #e2f5e9;
  color: var(--green);
}

.pill.info {
  background: #e7effd;
  color: var(--blue);
}

.detail {
  display: grid;
  gap: 14px;
}

.kv {
  display: grid;
  gap: 8px;
}

.kv-row {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  min-height: 28px;
}

.kv-row span:first-child {
  color: var(--muted);
  font-size: 12px;
}

.action-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.full {
  grid-column: 1 / -1;
}

.assistant-box,
.draft-box,
.timeline,
.form-box,
.table-wrap {
  border: 1px solid var(--line);
  background: #fbfcfc;
  border-radius: 8px;
  padding: 12px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.info-grid section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 10px;
}

.info-grid h3 {
  margin: 0 0 6px;
  font-size: 13px;
}

.info-grid p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.assistant-box h3,
.draft-box h3,
.timeline h3,
.form-box h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.assistant-item {
  display: grid;
  gap: 8px;
}

.assistant-item strong {
  font-size: 14px;
}

.timeline ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.timeline li {
  border-left: 3px solid var(--line);
  padding-left: 10px;
  color: #273532;
}

.timeline time {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

.draft-box textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.55;
}

.draft-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.row-actions.tight {
  margin-top: 0;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  background: #f8faf9;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.plain-link {
  border: 0;
  background: transparent;
  color: var(--teal);
  padding: 0;
  font-weight: 700;
  text-align: left;
}

.compact-select {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.compact-select select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 6px 10px;
}

.sales-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.sales-summary div {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  display: grid;
  align-content: center;
}

.sales-summary span {
  color: var(--muted);
  font-size: 12px;
}

.sales-summary strong {
  font-size: 20px;
}

.integration-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.integration-grid div,
.one-time-secret {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 10px;
  display: grid;
  gap: 4px;
}

.integration-grid span,
.one-time-secret span {
  color: var(--muted);
  font-size: 12px;
}

.one-time-secret strong {
  font-family: Consolas, "Courier New", monospace;
  overflow-wrap: anywhere;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.user-form-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.2fr) minmax(160px, .7fr);
}

.form-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.mail-list,
.incident-list,
.product-list {
  display: grid;
  gap: 10px;
}

.work-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  background: #fff;
}

.work-item h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.work-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.empty {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

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

.auth-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.auth-brand {
  color: var(--text);
  margin-bottom: 16px;
}

.auth-brand .brand-mark {
  color: #f5fbfa;
}

.auth-panel h1 {
  margin: 0 0 14px;
  font-size: 24px;
  letter-spacing: 0;
}

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

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.auth-form input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.auth-note {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  min-width: 260px;
  max-width: min(520px, calc(100vw - 24px));
  background: #172321;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .brand div,
  .operator-box strong,
  .operator-box span {
    display: none;
  }

  .nav-btn {
    text-align: center;
    padding: 0 6px;
  }

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

  .detail-panel {
    position: static;
    min-height: auto;
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 8px;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .sidebar::-webkit-scrollbar {
    display: none;
  }

  .brand {
    min-width: 36px;
    min-height: 36px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .nav {
    display: flex;
    gap: 6px;
  }

  .nav-btn {
    min-width: 44px;
    min-height: 34px;
    padding: 0 6px;
    font-size: 13px;
  }

  .operator-box {
    display: none;
  }

  .workspace {
    padding: 12px;
  }

  .topbar,
  .top-actions {
    display: grid;
    align-items: stretch;
  }

  .metrics,
  .lane-grid,
  .flow-steps,
  .form-grid,
  .sales-summary,
  .integration-grid {
    grid-template-columns: 1fr;
  }

  .task-card {
    grid-template-columns: 1fr;
  }

  .task-main {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .main-panel,
  .detail-panel {
    min-height: auto;
  }
}
