:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #18202f;
  --muted: #657083;
  --accent: #2364aa;
  --accent-dark: #173b66;
  --ok: #0f766e;
  --warn: #9a3412;
  --danger: #b42318;
  --chip: #eef2f7;
  --shadow: 0 10px 28px rgba(24, 32, 47, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

.wrap {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 14px 16px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(246, 247, 249, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.header-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.header-side {
  display: grid;
  gap: 8px;
  justify-items: end;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.meta,
.view-meta,
.small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.meta { margin: 5px 0 0; }

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.pill {
  min-height: 30px;
  padding: 5px 10px;
  background: var(--chip);
  color: #334155;
}

.controls {
  display: grid;
  gap: 9px;
  padding-top: 0;
}

.search-row,
.filter-row,
.action-row {
  display: grid;
  gap: 8px;
}

.search-row {
  grid-template-columns: minmax(220px, 1fr) 92px;
}

.filter-row {
  grid-template-columns: repeat(4, minmax(128px, 1fr));
}

.action-row {
  grid-template-columns: max-content max-content;
  justify-content: end;
}

input,
select,
.button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 11px;
  cursor: pointer;
  background: #eaf1fa;
  border-color: #c8d7ec;
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

.button.secondary {
  background: #f8fafc;
  color: #475569;
}

.filter-toggle {
  display: none;
  width: auto;
  gap: 6px;
}

.filter-count {
  min-width: 19px;
  min-height: 19px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  line-height: 1.4;
}

.button:hover,
.link-button:hover {
  filter: brightness(0.97);
}

.file-button {
  width: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.main {
  padding-top: 12px;
}

.view-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.table-shell {
  overflow: auto;
  max-height: calc(100vh - 244px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 1260px;
  border-collapse: separate;
  border-spacing: 0;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f8;
  color: #263548;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

th:last-child,
td:last-child {
  border-right: 0;
}

tbody tr:hover {
  background: #f8fbff;
}

.item-title {
  font-weight: 800;
  line-height: 1.35;
}

.status-cell {
  display: grid;
  gap: 6px;
  min-width: 104px;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.checkline input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  padding: 0;
}

.badge {
  min-width: 25px;
  min-height: 24px;
  padding: 2px 8px;
  background: #edf2f7;
  font-weight: 800;
}

.priority-S { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
.priority-A { background: #dff4ef; color: var(--ok); border-color: #b8e2d8; }
.priority-B { background: #e5eefb; color: var(--accent); border-color: #c9dbf4; }
.priority-C { background: #fef3c7; color: var(--warn); border-color: #fde68a; }

.product {
  display: grid;
  gap: 6px;
  min-width: 220px;
}

.product-name {
  font-weight: 750;
  line-height: 1.35;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #1f4f82;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.link-button.exact {
  background: #e8f5f2;
  border-color: #b8e2d8;
  color: #0f5f57;
}

.link-button.search {
  color: #526173;
}

.memo-box {
  display: grid;
  gap: 6px;
  min-width: 260px;
}

.note-input {
  min-height: 72px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}

.cards {
  display: none;
}

.card {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.card h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
}

.kv {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 7px 8px;
}

.kv b {
  color: #475569;
  font-size: 12px;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 920px) {
  .wrap {
    padding: 12px;
  }

  .header-grid {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 10px;
    align-items: start;
  }

  h1 {
    font-size: 21px;
  }

  .meta {
    font-size: 11px;
  }

  .header-side {
    display: contents;
  }

  .filter-toggle {
    display: inline-flex;
    min-height: 34px;
    padding: 6px 10px;
    border-radius: 999px;
  }

  .summary {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

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

  .pill {
    min-height: 26px;
    padding: 4px 8px;
    font-size: 12px;
  }

  .controls {
    display: none;
    gap: 8px;
    padding-top: 0;
    padding-bottom: 10px;
  }

  .app-header.controls-open .controls {
    display: grid;
  }

  .app-header.has-active-filters .filter-toggle {
    border-color: #9fbce3;
    background: #dceafb;
  }

  .search-row,
  .filter-row,
  .action-row {
    grid-template-columns: 1fr 1fr;
  }

  .search-row input {
    grid-column: 1 / -1;
  }

  .action-row {
    justify-content: stretch;
  }

  .button {
    width: 100%;
  }

  .view-meta {
    flex-direction: column;
    gap: 4px;
  }

  .table-shell {
    display: none;
  }

  .cards {
    display: block;
  }

  .kv {
    grid-template-columns: 76px 1fr;
  }
}

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

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

  .kv b {
    margin-top: 4px;
  }
}
