@media (min-width: 801px) {
  .app-shell { display: block; }
  .content {
    width: calc(100% - 250px);
    max-width: 1500px;
    margin: 0 0 0 250px;
  }
}

.case-create-panel {
  margin: 18px 0;
  border-top: 3px solid var(--green);
}

.case-automation {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  margin: 0 0 16px;
  padding: 16px 18px;
  border: 1px solid #d8e1dc;
  border-radius: 14px;
  background: linear-gradient(135deg, #f7faf8, #fff);
  box-shadow: 0 4px 16px rgba(21, 52, 40, .04);
}

.case-automation.is-active { border-color: #b9dacb; background: linear-gradient(135deg, #eff8f3, #fff); }
.case-automation.is-paused { border-color: #dedbd5; background: #f7f6f3; }
.case-automation.has-error { border-color: #e2b8b1; }
.case-automation-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.case-automation-main p { margin: 4px 0 0; color: #52645c; font-size: 12px; line-height: 1.55; }
.case-automation-title { display: flex; align-items: center; gap: 9px; }
.case-automation-title strong { color: #183b2f; font-size: 14px; }
.case-automation-title span { padding: 3px 8px; border-radius: 999px; background: #e8eeeb; color: #53635c; font-size: 10px; font-weight: 700; }
.case-automation.is-active .case-automation-title span { background: #d8efe3; color: #176542; }
.case-automation-indicator { width: 14px; height: 14px; flex: 0 0 auto; border: 3px solid #c9d2cd; border-radius: 50%; }
.case-automation.is-active .case-automation-indicator { border-color: #37a86f; background: #37a86f; box-shadow: 0 0 0 5px rgba(55, 168, 111, .12); }
.case-automation.is-processing .case-automation-indicator { border-color: #cfe8da; border-top-color: #168a56; background: transparent; animation: case-automation-spin .8s linear infinite; }
@keyframes case-automation-spin { to { transform: rotate(360deg); } }
.case-automation-stats { display: flex; gap: 14px; white-space: nowrap; }
.case-automation-stats span { display: grid; gap: 2px; color: #68756f; font-size: 10px; text-align: center; }
.case-automation-stats strong { color: #203f33; font-size: 15px; }
.case-automation-actions { display: flex; gap: 8px; }
.case-automation-actions button { padding: 8px 11px; font-size: 11px; white-space: nowrap; }

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

.case-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.case-form-grid .case-form-wide { grid-column: 1 / -1; }
.case-form-grid input,
.case-form-grid select,
.case-form-grid textarea { width: 100%; }

.case-dashboard {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 10px;
  margin: 22px 0 12px;
}

.case-metric {
  min-height: 84px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 5px 16px rgba(21, 34, 29, .04);
}

.case-metric span,
.case-metric small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.case-metric strong {
  display: block;
  margin-top: 8px;
  color: var(--green);
  font-size: 25px;
  line-height: 1;
}

.case-metric.overdue strong { color: #b33d32; }
.case-metric.amount strong { font-size: 20px; }

.case-toolbar {
  position: sticky;
  z-index: 5;
  top: -1px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 8px 24px rgba(21, 34, 29, .055);
  backdrop-filter: blur(10px);
}

.case-search {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid #ccd8ce;
  border-radius: 9px;
  background: var(--white);
  color: var(--green);
}

.case-search:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 80, 55, .11);
}

.case-search input {
  width: 100%;
  padding: 11px 0;
  border: 0;
  outline: 0;
  background: transparent;
}

.case-filter-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-top: 10px;
}

.case-filter-row label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding-left: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f8faf8;
  font-size: 11px;
}

.case-filter-row select {
  width: 100%;
  border: 0;
  background: transparent;
}

.case-toolbar-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 26px;
  margin-top: 8px;
}

.case-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(255px, 1fr));
  gap: 12px;
  min-height: 280px;
  padding: 2px 2px 16px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
}

.case-loading,
.case-empty {
  grid-column: 1 / -1;
  padding: 46px 24px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: #fafcfb;
  text-align: center;
}

.case-column {
  align-self: start;
  min-height: 230px;
  padding: 10px;
  border: 1px solid #dfe7e0;
  border-radius: 13px;
  background: #f4f7f4;
  scroll-snap-align: start;
}

.case-column-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 4px 11px;
  color: var(--ink);
}

.case-column-head strong { font-size: 13px; }
.case-column-head span {
  min-width: 25px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #e4ece6;
  color: var(--green);
  font-size: 11px;
  text-align: center;
}

.case-column[data-status="won"] { background: #eef7f1; }
.case-column[data-status="lost"] { background: #f7f4f3; }
.case-column[data-status="completed"] { background: #f2f4f3; }

.case-column-body {
  display: grid;
  gap: 9px;
}

.case-card {
  position: relative;
  padding: 13px;
  border: 1px solid #d6dfd8;
  border-left: 4px solid #87a895;
  border-radius: 10px;
  background: var(--white);
  box-shadow: 0 4px 12px rgba(21, 34, 29, .045);
}

.case-card.priority-high { border-left-color: #c44b3d; }
.case-card.is-overdue { box-shadow: inset 0 0 0 1px #d5786d, 0 4px 12px rgba(21, 34, 29, .045); }
.case-card.is-focus { animation: case-focus 2.2s ease; }

@keyframes case-focus {
  0%, 35% { box-shadow: 0 0 0 4px rgba(29, 80, 55, .22); }
  100% { box-shadow: 0 4px 12px rgba(21, 34, 29, .045); }
}

.case-card-number {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .03em;
}

.case-card h4 {
  margin: 8px 0 4px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.case-card-customer {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.case-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 10px 0;
}

.case-tag {
  padding: 3px 7px;
  border-radius: 999px;
  background: #edf3ee;
  color: #345744;
  font-size: 10px;
  font-weight: 700;
}

.case-tag.high { background: #fff0ed; color: #9f392d; }
.case-tag.overdue { background: #fff0ed; color: #9f392d; }
.case-tag.amount { background: #eef4fb; color: #315f82; }
.case-tag.ai { background: #e6f5ed; color: #146a43; }
.case-automation-reason { display: flex; gap: 5px; margin: 8px 0 0; color: #44675a; font-size: 10px; line-height: 1.5; }
.case-automation-reason span { color: #1c8d59; }

.case-card-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.case-card-controls label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}

.case-card-controls select,
.case-card-controls input {
  width: 100%;
  min-height: 34px;
  padding: 6px 7px;
  border: 1px solid #d5ded7;
  border-radius: 7px;
  background: #fbfcfb;
  color: var(--ink);
  font-size: 11px;
}

.case-card-controls.readonly {
  grid-template-columns: 1fr;
  padding: 8px;
  border-radius: 7px;
  background: #f7f9f7;
  color: var(--muted);
  font-size: 11px;
}

.case-card-meta {
  display: grid;
  grid-template-columns: minmax(0, .75fr) minmax(0, 1.25fr);
  gap: 6px;
  margin-top: 9px;
}

.case-card-meta span {
  min-width: 0;
  overflow: hidden;
  padding: 7px 8px;
  border-radius: 7px;
  background: #f4f7f5;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-card-meta small { display: block; margin-bottom: 2px; color: var(--muted); font-size: 8px; font-weight: 700; }

.case-open-button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  margin-top: 9px;
  padding: 8px 10px;
  border: 1px solid #c9d8cd;
  border-radius: 7px;
  background: #fff;
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}

.case-open-button:hover { border-color: var(--green); background: #f3f8f5; }
.case-open-button span:last-child { font-size: 17px; line-height: 1; }

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

.case-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.case-detail-grid .case-detail-wide { grid-column: 1 / -1; }

.case-detail-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.case-detail-form input,
.case-detail-form select,
.case-detail-form textarea { width: 100%; font-size: 12px; }
.case-detail-form textarea { min-height: 130px; resize: vertical; }

.case-detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.case-detail-actions button { padding: 7px 10px; font-size: 11px; }
.case-source-link { margin-right: auto; }

body.case-drawer-open { overflow: hidden; }

.case-drawer-backdrop {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: flex;
  justify-content: flex-end;
  background: rgba(16, 28, 22, .42);
  backdrop-filter: blur(2px);
}

.case-drawer-backdrop.hidden { display: none; }

.case-drawer {
  display: flex;
  width: min(680px, 92vw);
  height: 100%;
  flex-direction: column;
  background: #f7faf8;
  box-shadow: -12px 0 36px rgba(16, 32, 23, .2);
  animation: case-drawer-in .2s ease-out;
}

@keyframes case-drawer-in { from { transform: translateX(24px); opacity: .75; } to { transform: translateX(0); opacity: 1; } }

.case-drawer-head {
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid #dce5de;
  background: #fff;
}

.case-drawer-head p { margin: 0 0 3px; }
.case-drawer-head strong { color: var(--ink); font-size: 15px; }
.case-drawer-close { width: 38px; height: 38px; padding: 0; border: 1px solid #d5dfd8; border-radius: 50%; background: #fff; color: #365747; font-size: 24px; line-height: 1; cursor: pointer; }
.case-drawer-close:hover { background: #edf4ef; }

.case-drawer-body { overflow-y: auto; padding: 22px; }
.case-drawer-title-block { padding: 0 2px 18px; }
.case-drawer-title-block h3 { margin: 10px 0 5px; color: var(--ink); font-size: 22px; line-height: 1.45; }
.case-drawer-title-block > p { margin: 0; color: var(--muted); font-size: 13px; }
.case-drawer-title-block .case-card-tags { margin-bottom: 0; }

.case-drawer-section { margin-bottom: 14px; padding: 17px; border: 1px solid #dae4dc; border-radius: 12px; background: #fff; }
.case-drawer-section-title { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 13px; }
.case-drawer-section-title span { color: var(--ink); font-size: 13px; font-weight: 800; }
.case-drawer-section-title small { color: var(--muted); font-size: 10px; }

.case-drawer-controls,
.case-drawer-readonly { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.case-drawer-controls label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 700; }
.case-drawer-controls select,
.case-drawer-controls input { width: 100%; min-height: 40px; font-size: 12px; }
.case-drawer-readonly span { padding: 10px; border-radius: 8px; background: #f4f7f5; color: var(--ink); font-size: 12px; font-weight: 700; }
.case-drawer-readonly small { display: block; margin-bottom: 3px; color: var(--muted); font-size: 9px; }
.case-drawer-section > .case-attachments { margin-top: 0; border: 0; padding: 0; background: transparent; }

.case-timeline { min-height: 44px; }
.case-timeline-list { position: relative; display: grid; gap: 8px; }
.case-timeline-list::before { position: absolute; top: 12px; bottom: 12px; left: 8px; width: 1px; background: #d9e4dc; content: ''; }
.case-timeline-entry {
  position: relative;
  display: grid;
  grid-template-columns: 17px minmax(0, 1fr);
  gap: 9px;
  margin: 0;
  padding: 10px 11px 10px 5px;
  border: 1px solid #e0e8e2;
  border-radius: 9px;
  background: #fbfcfb;
}
.case-timeline-entry.hidden { display: none; }
.case-timeline-dot { position: relative; z-index: 1; width: 9px; height: 9px; margin: 5px 0 0; border: 2px solid #fff; border-radius: 50%; background: #7d9e8a; box-shadow: 0 0 0 1px #bfd0c4; }
.case-timeline-entry.inbound .case-timeline-dot { background: #1f7a4e; }
.case-timeline-entry.outbound .case-timeline-dot { background: #3978a4; }
.case-timeline-entry.ai .case-timeline-dot { background: #9d6a20; }
.case-timeline-main { min-width: 0; }
.case-timeline-main > strong { display: block; overflow: hidden; margin-top: 2px; color: var(--ink); font-size: 11px; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.case-timeline-main > small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.case-timeline-label { display: inline-block; padding: 2px 6px; border-radius: 999px; background: #e9f1eb; color: #376349; font-size: 8px; font-weight: 800; }
.case-timeline-entry.outbound .case-timeline-label { background: #e9f1f8; color: #35617e; }
.case-timeline-entry.ai .case-timeline-label { background: #fff3dc; color: #825819; }
.case-timeline-preview { display: block; overflow: hidden; margin-top: 6px; color: #4d6257; font-size: 10px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.case-timeline-entry.activity p { margin: 6px 0 0; color: #40584c; font-size: 10px; line-height: 1.55; }
.case-timeline-entry.email { display: block; padding: 0; }
.case-timeline-entry.email > summary { display: grid; grid-template-columns: 17px minmax(0, 1fr) 14px; gap: 9px; padding: 10px 11px 10px 5px; list-style: none; cursor: pointer; }
.case-timeline-entry.email > summary::-webkit-details-marker { display: none; }
.case-timeline-arrow { align-self: center; color: #769184; font-size: 17px; transition: transform .18s ease; }
.case-timeline-entry.email[open] .case-timeline-arrow { transform: rotate(90deg); }
.case-timeline-email-body { padding: 0 12px 12px 31px; }
.case-timeline-email-body .conversation-body { max-height: 280px; overflow-y: auto; padding: 10px; border-radius: 7px; background: #fff; }
.case-timeline-email-body .conversation-latest { margin: 0; color: var(--ink); font-size: 11px; line-height: 1.65; white-space: pre-wrap; }
.case-timeline-email-body .conversation-quoted { margin-top: 8px; font-size: 10px; }
.case-timeline-more { width: 100%; margin-top: 9px; padding: 8px; border: 1px solid #cfddd3; border-radius: 7px; background: #fff; color: var(--green); font-size: 10px; font-weight: 800; cursor: pointer; }
.case-timeline-more:hover { background: #f1f6f3; }
.case-timeline-loading,
.case-timeline-empty { padding: 13px; border-radius: 8px; background: #f7f9f7; color: var(--muted); font-size: 10px; text-align: center; }
.case-timeline-loading span { display: inline-block; width: 13px; height: 13px; margin-right: 6px; border: 2px solid #c7d8cc; border-top-color: var(--green); border-radius: 50%; vertical-align: -2px; animation: case-ai-spin .75s linear infinite; }
.case-timeline-empty.is-error { color: #9f392d; background: #fff1ef; }
.case-timeline-empty button { margin-left: 6px; color: inherit; text-decoration: underline; }

@media (max-width: 980px) {
  .case-automation { grid-template-columns: 1fr auto; }
  .case-automation-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .case-dashboard { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .case-filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .case-automation { grid-template-columns: 1fr; gap: 10px; padding: 14px; }
  /* 締切ポリシーのタグは確認用。狭い画面では畳んで案件へ早く着かせる */
  .case-automation-policy { display: none; }
  .case-automation-stats { gap: 6px; }
  .case-automation-stats { justify-content: space-between; }
  .case-automation-actions { grid-column: auto; justify-content: stretch; }
  .case-automation-actions button { flex: 1; }
  /* 1列に積むと案件カードまで2000px近くスクロールが必要になるため、
     集計は3列、絞り込みは2列に詰める。 */
  .case-dashboard { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 14px 0 10px; }
  .case-metric { min-height: 0; padding: 9px 10px; gap: 2px; }
  .case-metric span,
  .case-metric small { font-size: 9px; }
  .case-metric strong { font-size: 17px; }
  .case-metric.amount strong { font-size: 17px; }
  .case-filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .case-form-grid { grid-template-columns: 1fr; }
  .case-form-grid .case-form-wide { grid-column: auto; }
  .case-board { grid-template-columns: repeat(7, minmax(84vw, 1fr)); }
  .case-toolbar { position: static; }
  .case-drawer { width: 100vw; }
  .case-drawer-head { padding: 14px 16px; }
  .case-drawer-body { padding: 16px; }
  .case-drawer-section { padding: 14px; }
  .case-drawer-controls,
  .case-drawer-readonly,
  .case-detail-grid { grid-template-columns: 1fr; }
  .case-detail-grid .case-detail-wide { grid-column: auto; }
}


/* Case workflow automation */
.case-automation-policy { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.case-automation-policy span { padding: 4px 7px; border-radius: 999px; background: #e4f2e9; color: #246744; font-size: 9px; font-weight: 800; }
.case-metric.due-soon strong { color: #a96b12; }
.case-tag.due-soon { border-color: #e7cf9e; background: #fff7e4; color: #915f13; }

/* Case attachments: storage is free of AI calls until the user requests analysis. */
.case-attachments {
  display: grid;
  gap: 9px;
  margin-top: 10px;
  padding: 11px;
  border: 1px solid #dce6df;
  border-radius: 9px;
  background: #f7faf8;
}

.case-attachments > header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.case-attachments > header strong,
.case-attachments > header small { display: block; }
.case-attachments > header strong { color: var(--ink); font-size: 12px; }
.case-attachments > header small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.case-attachments > header > span {
  padding: 3px 7px;
  border-radius: 999px;
  background: #e7f2eb;
  color: #276646;
  font-size: 9px;
  font-weight: 800;
  white-space: nowrap;
}

.case-attachment-upload {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border: 1px dashed #b8cbbd;
  border-radius: 8px;
  background: #fff;
}

.case-attachment-upload label { min-width: 0; }
.case-attachment-upload input { width: 100%; font-size: 10px; }
.case-attachment-upload label span { display: none; }
.case-attachment-upload button { padding: 7px 9px; font-size: 10px; white-space: nowrap; }
.case-attachment-upload > small { grid-column: 1 / -1; color: #537263; font-size: 9px; }
.case-attachment-list { display: grid; gap: 7px; }

.case-attachment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid #dfe7e1;
  border-radius: 8px;
  background: #fff;
}

.case-attachment-item.is-analyzing { border-color: #6eaa87; box-shadow: 0 0 0 2px rgba(36, 116, 75, .09); }
.case-attachment-file { display: flex; min-width: 0; gap: 8px; align-items: center; }
.case-file-icon {
  display: grid;
  flex: 0 0 28px;
  width: 28px;
  height: 32px;
  place-items: center;
  border-radius: 6px;
  background: #e9f1eb;
  color: var(--green);
  font-size: 13px;
}
.case-attachment-file > div { min-width: 0; }
.case-attachment-file strong,
.case-attachment-file small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.case-attachment-file strong { color: var(--ink); font-size: 10px; }
.case-attachment-file small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.case-attachment-actions { display: flex; gap: 5px; align-items: center; }
.case-attachment-actions a { font-size: 9px; }
.case-attachment-actions button { padding: 6px 8px; font-size: 9px; white-space: nowrap; }

.case-attachment-analysis,
.case-attachment-result { grid-column: 1 / -1; }
.case-attachment-analysis {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 7px;
  background: #edf7f1;
  color: #275e43;
}
.case-attachment-analysis.is-error { display: grid; background: #fff1ef; color: #97392f; }
.case-attachment-analysis strong,
.case-attachment-analysis small { display: block; font-size: 9px; }
.case-attachment-analysis small { margin-top: 2px; opacity: .8; }
.case-ai-spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 2px solid #b9dcc8;
  border-top-color: #1d7148;
  border-radius: 50%;
  animation: case-ai-spin .75s linear infinite;
}
@keyframes case-ai-spin { to { transform: rotate(360deg); } }

.case-attachment-result {
  padding-top: 5px;
  border-top: 1px solid #e1e8e2;
}
.case-attachment-result > summary {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0;
  color: #1f6843;
  cursor: pointer;
  font-size: 9px;
  font-weight: 800;
}
.case-attachment-result > summary small { color: var(--muted); font-weight: 500; }
.case-attachment-result-body { display: grid; gap: 7px; padding-top: 8px; }
.case-result-summary,
.case-attachment-result-body section { padding: 8px; border-radius: 7px; background: #f6f9f7; }
.case-result-summary strong,
.case-attachment-result-body section > strong { display: block; margin-bottom: 4px; color: #315b45; font-size: 9px; }
.case-result-summary p { margin: 0; color: var(--ink); font-size: 10px; line-height: 1.6; }
.case-attachment-result-body ul { margin: 0; padding-left: 17px; color: var(--ink); font-size: 9px; line-height: 1.6; }
.case-attachment-loading,
.case-attachment-empty { padding: 12px; border-radius: 7px; background: #fff; color: var(--muted); font-size: 9px; text-align: center; }
.case-attachment-empty.is-error { color: #9f392d; background: #fff1ef; }

@media (max-width: 620px) {
  .case-attachment-upload,
  .case-attachment-item { grid-template-columns: 1fr; }
  .case-attachment-actions { justify-content: flex-end; }
}

.case-tag.delegation { border-color: #cdd8e4; background: #eef3f9; color: #2f5677; }
.case-tag.delegation.manual { border-color: #d9d2c4; background: #f7f3ea; color: #6f5a2c; }
.case-tag.delegation.propose { border-color: #cfd9e8; background: #eef2fb; color: #33528a; }
.case-tag.delegation.internal { border-color: #c6ddd0; background: #eaf5ef; color: #196a45; }
.case-tag.delegation.full { border-color: #cbc2e6; background: #f1edfb; color: #4b3a92; }

.case-delegation { display: grid; gap: 8px; }
.case-delegation-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr) auto; gap: 8px; align-items: end; }
.case-delegation-row button { justify-self: end; padding: 8px 12px; font-size: 10px; white-space: nowrap; }
.case-delegation-row label { display: grid; gap: 4px; color: var(--muted); font-size: 9px; font-weight: 800; }
.case-delegation-row select,
.case-delegation-row input { padding: 7px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: 10px; }
.case-delegation-hint { margin: 0; color: var(--muted); font-size: 9px; line-height: 1.6; }
.case-delegation-hint strong { color: var(--ink); }
.case-delegation-warning { margin: 0; padding: 7px 9px; border-radius: 7px; background: #fff7e4; color: #915f13; font-size: 9px; font-weight: 700; }
.case-delegation-updated { color: var(--muted); font-size: 9px; }
.case-delegation.is-readonly { padding: 9px; border-radius: 7px; background: #f6f9f7; }
.case-delegation-current { margin: 0 0 4px; color: var(--ink); font-size: 11px; font-weight: 800; }

.case-manual-progress { display: grid; gap: 9px; }
.case-manual-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; }
.case-manual-step { display: flex; gap: 6px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: 10px; }
.case-manual-step input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--green);
}
.case-manual-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.case-manual-grid label { display: grid; gap: 4px; color: var(--muted); font-size: 9px; font-weight: 800; }
.case-manual-grid input,
.case-manual-grid textarea { padding: 7px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: 10px; font-family: inherit; }
.case-manual-wide { grid-column: 1 / -1; }
.case-manual-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; justify-content: space-between; }
.case-manual-actions button { padding: 8px 14px; font-size: 10px; white-space: nowrap; }
.case-manual-updated { color: var(--muted); font-size: 9px; }
.case-manual-progress.is-readonly { display: grid; gap: 5px; padding: 9px; border-radius: 7px; background: #f6f9f7; color: var(--ink); font-size: 10px; }
.case-manual-progress.is-readonly p { margin: 0; }

.case-automation-delegation { display: grid; gap: 8px; grid-column: 1 / -1; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.case-automation-delegation-details > summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  cursor: pointer;
  list-style: none;
}
.case-automation-delegation-details > summary::-webkit-details-marker { display: none; }
.case-automation-delegation-details > summary::after {
  content: '▾';
  color: var(--muted);
  font-size: 11px;
}
.case-automation-delegation-details[open] > summary::after { content: '▴'; }
.case-automation-delegation-current {
  margin-left: auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e4f2e9;
  color: #246744;
  font-size: 9px;
  font-weight: 800;
}
.case-automation-delegation-details > *:not(summary) { margin-top: 8px; }
.case-automation-delegation-head { display: flex; gap: 8px; align-items: baseline; }
.case-automation-delegation-head strong { color: var(--ink); font-size: 10px; }
.case-automation-delegation-head small { color: var(--muted); font-size: 9px; }
.case-automation-delegation-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.case-automation-delegation-grid label { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 6px; color: var(--muted); font-size: 9px; font-weight: 800; }
.case-automation-delegation-grid label > span { grid-column: 1 / -1; }
.case-automation-delegation-grid label > small { font-size: 10px; font-weight: 700; }
.case-automation-delegation-grid select,
.case-automation-delegation-grid input[type="number"] { grid-column: 1; padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: 11px; }
.case-automation-delegation-check { flex-direction: row; align-items: center; display: flex !important; gap: 6px; }
.case-automation-delegation-check input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--green);
}
.case-automation-delegation-check span { flex: 1; min-width: 0; }
.case-automation-delegation-hint { margin: 0; color: var(--muted); font-size: 9px; line-height: 1.6; }
.case-automation-delegation-actions { display: flex; justify-content: flex-end; }

/* 「対象外」の件数の下に、AIが見送った理由をそのまま並べる。 */
.case-automation-skipped { grid-column: 1 / -1; }
.case-automation-skipped:empty { display: none; }
.case-automation-skipped-details > summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  padding: 7px 0;
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}
.case-automation-skipped-details > summary::-webkit-details-marker { display: none; }
.case-automation-skipped-details > summary::after { content: '▾'; margin-left: auto; color: var(--muted); font-size: 11px; }
.case-automation-skipped-details[open] > summary::after { content: '▴'; }
.case-automation-skipped-details > summary small { color: var(--muted); font-size: 9px; font-weight: 700; }
.case-automation-skipped-list { display: grid; gap: 6px; margin: 6px 0 0; padding: 0; list-style: none; }
.case-automation-skipped-list button {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}
.case-automation-skipped-list button:hover { border-color: #b9dacb; background: #f4faf6; }
.case-automation-skipped-list strong { color: var(--ink); font-size: 11px; }
.case-automation-skipped-list span { color: #52645c; font-size: 10px; line-height: 1.55; }
.case-automation-skipped-list small { color: var(--muted); font-size: 9px; }

.case-automation-failed { grid-column: 1 / -1; }
.case-automation-failed:empty { display: none; }
.case-automation-failed-details > summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  padding: 7px 0;
  color: #8a3b2f;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}
.case-automation-failed-details > summary::-webkit-details-marker { display: none; }
.case-automation-failed-details > summary::after { content: '▾'; margin-left: auto; color: var(--muted); font-size: 11px; }
.case-automation-failed-details[open] > summary::after { content: '▴'; }
.case-automation-failed-details > summary small { color: var(--muted); font-size: 9px; font-weight: 700; }
.case-automation-failed-list { display: grid; gap: 6px; margin: 6px 0 0; padding: 0; list-style: none; }
.case-automation-failed-list button,
.case-automation-failed-list .case-automation-failed-static {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #e6c4bd;
  border-radius: 9px;
  background: #fdf6f4;
  text-align: left;
}
.case-automation-failed-list button { cursor: pointer; }
.case-automation-failed-list button:hover { border-color: #d9a498; background: #fbeeea; }
.case-automation-failed-list strong { color: var(--ink); font-size: 11px; }
.case-automation-failed-list span { color: #7a4238; font-size: 10px; line-height: 1.55; }
.case-automation-failed-list .case-automation-failed-step { color: #52645c; }
.case-automation-failed-list small { color: var(--muted); font-size: 9px; }

@media (max-width: 620px) {
  .case-delegation-row,
  .case-manual-grid { grid-template-columns: 1fr; }
  .case-delegation-row button { justify-self: end; }
  .case-document-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.case-documents { display: grid; gap: 9px; }
.case-documents > header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.case-documents > header small { color: var(--muted); font-size: 9px; font-weight: 800; }
.case-documents > header button { padding: 7px 11px; font-size: 10px; white-space: nowrap; }
.case-document-alerts { display: flex; flex-wrap: wrap; gap: 5px; }
.case-document-alert { padding: 4px 7px; border-radius: 999px; background: #fff7e4; color: #915f13; font-size: 9px; font-weight: 800; }
.case-document-alert.is-overdue { background: #fff0ed; color: #9f392d; }
.case-document-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.case-document-totals span { display: grid; gap: 2px; padding: 7px 8px; border-radius: 7px; background: #f6f9f7; }
.case-document-totals small { color: var(--muted); font-size: 9px; font-weight: 800; }
.case-document-totals strong { color: var(--ink); font-size: 12px; }
.case-document-totals span.is-outstanding { background: #fff0ed; }
.case-document-totals span.is-outstanding strong { color: #9f392d; }
.case-document-list { display: grid; gap: 6px; }
.case-document-row { display: grid; gap: 4px; width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-align: left; cursor: pointer; }
.case-document-row:hover { border-color: #b9c8d8; background: #fbfdff; }
.case-document-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.case-document-head strong { color: var(--ink); font-size: 10px; }
.case-document-subject { color: var(--ink); font-size: 11px; font-weight: 700; }
.case-document-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; justify-content: space-between; }
.case-document-meta small { color: var(--muted); font-size: 9px; }
.case-document-total { color: var(--ink); font-size: 12px; font-weight: 800; }
.case-document-balance { color: #9f392d; font-size: 9px; font-weight: 800; }
.case-document-loading,
.case-document-empty { padding: 12px; border-radius: 7px; background: #fff; color: var(--muted); font-size: 9px; text-align: center; }
.case-document-empty.is-error { background: #fff1ef; color: #9f392d; }


.case-filter-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}
.case-toolbar.filters-open .case-filter-toggle { background: #eef4f0; border-color: #c6ddd0; }

/* ---- スマホ：案件へ早くたどり着くための並べ替えと省略 ---- */
@media (max-width: 620px) {
  /* 日々使うのは案件一覧。AIの稼働状況は確認用なので一番下へ回す。 */
  /* .view{display:none} より ID が強いため、必ず .active を伴わせる。
     これを外すと案件管理がどの画面でも表示されてしまう。 */
  #view-cases.active { display: flex; flex-direction: column; }
  #view-cases > .section-head { order: 0; }
  #view-cases > .case-create-panel { order: 1; }
  #view-cases > .case-toolbar { order: 2; }
  #view-cases > .case-dashboard { order: 3; }
  #view-cases > #caseBoard { order: 4; }
  #view-cases > #caseAutomation { order: 5; margin-top: 18px; }

  /* 見出しの説明とポリシータグは畳む（上部バーとタグで足りる） */
  #view-cases .case-automation-policy { display: none; }
  #view-cases #caseAutomationMessage { display: none; }

  /* 絞り込みは既定で隠し、必要なときだけ開く */
  .case-toolbar .case-filter-row { display: none; }
  .case-toolbar.filters-open .case-filter-row { display: grid; }
  .case-filter-toggle { display: inline-flex; }
}

/* ---- 失注理由 ---- */
.case-lost-host { display: grid; gap: 8px; margin-top: 10px; }
.case-lost-form { display: grid; gap: 8px; padding: 12px; border: 1px solid #e6c9c4; border-radius: 10px; background: #fff6f4; }
.case-lost-title { margin: 0; color: #9f392d; font-size: 11px; font-weight: 800; }
.case-lost-form label { display: grid; gap: 4px; color: var(--muted); font-size: 9px; font-weight: 800; }
.case-lost-form select,
.case-lost-form input { padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: 11px; }
.case-lost-actions { display: flex; gap: 8px; justify-content: flex-end; }
.case-lost-actions button { padding: 8px 14px; font-size: 10px; }
.case-lost-summary { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0 0; color: var(--ink); font-size: 10px; }
.case-lost-summary small { color: var(--muted); font-size: 9px; }
.case-tag.lost { border-color: #e6c9c4; background: #fff0ed; color: #9f392d; }

/* ---- 失注の内訳 ---- */
.case-lost-breakdown { margin: 0 0 14px; }
.case-lost-breakdown-details { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); }
.case-lost-breakdown-details > summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; }
.case-lost-breakdown-details > summary::-webkit-details-marker { display: none; }
.case-lost-breakdown-details > summary::after { content: '▾'; color: var(--muted); font-size: 11px; }
.case-lost-breakdown-details[open] > summary::after { content: '▴'; }
.case-lost-breakdown-details summary strong { color: var(--ink); font-size: 11px; }
.case-lost-breakdown-details summary small { margin-left: 8px; color: var(--muted); font-size: 9px; }
.case-lost-top { padding: 4px 8px; border-radius: 999px; background: #fff0ed; color: #9f392d; font-size: 9px; font-weight: 800; }
.case-lost-bars { display: grid; gap: 7px; margin: 12px 0 0; padding: 0; list-style: none; }
.case-lost-bars li { display: grid; grid-template-columns: minmax(84px, 1fr) minmax(0, 2fr) auto; gap: 8px; align-items: center; }
.case-lost-bar-label { color: var(--ink); font-size: 10px; font-weight: 700; }
.case-lost-bar { height: 8px; border-radius: 999px; background: #f0f3f1; overflow: hidden; }
.case-lost-bar > span { display: block; height: 100%; border-radius: 999px; background: #c9705f; }
.case-lost-bar-count { color: var(--muted); font-size: 9px; font-weight: 800; white-space: nowrap; }
.case-lost-hint { margin: 10px 0 0; color: var(--muted); font-size: 9px; line-height: 1.6; }

@media (max-width: 620px) {
  .case-lost-bars li { grid-template-columns: minmax(70px, 1fr) minmax(0, 1.4fr) auto; }
  #view-cases > .case-lost-breakdown { order: 3; }
}

/* ---- 進捗の移動（ワンタップ／ドラッグ） ---- */
.case-card-foot { display: grid; gap: 6px; margin-top: 10px; }
.case-advance {
  padding: 9px 12px;
  border: 1px solid #c6ddd0;
  border-radius: 8px;
  background: #eef6f1;
  color: #175f45;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}
.case-advance:hover { background: #e2efe8; }
.case-advance:disabled { opacity: .55; cursor: progress; }
.case-card.is-dragging { opacity: .5; }
.case-column.is-drop-target { outline: 2px dashed #7fae95; outline-offset: -4px; background: #f2f8f4; }

@media (max-width: 620px) {
  .case-card-foot { grid-template-columns: 1fr auto; align-items: center; }
  .case-advance { white-space: nowrap; }
}

/* ---- カードに出す「次の対応」 ---- */
.case-card-next {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: baseline;
  margin: 8px 0 0;
  padding: 7px 9px;
  border-radius: 8px;
  background: #f3f7f4;
  color: var(--ink);
  font-size: 10px;
  line-height: 1.5;
}
.case-card-next > span[aria-hidden] { color: #4d7a63; }
.case-card-next time { margin-left: auto; color: var(--muted); font-size: 9px; white-space: nowrap; }
.case-card-next.is-late { background: #fff0ed; }
.case-card-next.is-late time { color: #9f392d; font-weight: 800; }

/* ---- まとめて操作 ---- */
.case-select { display: inline-flex; align-items: center; margin-right: 8px; cursor: pointer; }
.case-select input[type="checkbox"] { width: 17px; height: 17px; min-width: 17px; margin: 0; padding: 0; accent-color: var(--green); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.case-card.is-selected { border-color: #7fae95; box-shadow: 0 0 0 2px #7fae9540; }

.case-selection-bar {
  position: sticky;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid #c6ddd0;
  border-radius: 12px;
  background: #f4faf6;
  box-shadow: 0 10px 24px #16321f1f;
}
.case-selection-count { color: var(--ink); font-size: 11px; white-space: nowrap; }
.case-selection-count strong { color: var(--green); font-size: 15px; }
.case-selection-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.case-selection-fields label { display: grid; gap: 4px; color: var(--muted); font-size: 9px; font-weight: 800; }
.case-selection-fields select,
.case-selection-fields input { padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font-size: 11px; }
.case-selection-actions { display: flex; gap: 8px; }
.case-selection-actions button { padding: 9px 14px; font-size: 10px; white-space: nowrap; }

@media (max-width: 620px) {
  #view-cases > .case-selection-bar { order: 4; }
  .case-selection-bar { grid-template-columns: 1fr; gap: 9px; padding: 11px 12px calc(11px + env(safe-area-inset-bottom, 0px)); }
  .case-selection-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-selection-fields label:last-child { grid-column: 1 / -1; }
  .case-selection-actions { justify-content: flex-end; }
}
