:root {
  --bg: #f3f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fbfe;
  --line: #d8e1ea;
  --line-dark: #b9c8d7;
  --text: #17212d;
  --muted: #657486;
  --blue: #2e6fae;
  --blue-dark: #20496f;
  --blue-soft: #dcecf8;
  --green: #2e9c74;
  --green-soft: #d9f3e9;
  --orange: #c77c2c;
  --orange-soft: #ffe5c8;
  --red: #b74c4c;
  --red-soft: #ffe0e0;
  --shadow: 0 20px 50px rgba(38, 74, 110, 0.11);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1080px;
  background:
    linear-gradient(135deg, rgba(202, 224, 243, 0.45), transparent 34%),
    linear-gradient(315deg, rgba(232, 240, 247, 0.9), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: "Yu Gothic UI", "Meiryo", "Hiragino Kaku Gothic ProN", sans-serif;
}

button,
input,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

button {
  cursor: pointer;
}

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

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-card {
  width: min(460px, 100%);
  padding: 28px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 24px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.login-form input {
  height: 46px;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--text);
}

.login-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-height: 100vh;
  overflow: auto;
  padding: 28px 22px;
  background: rgba(255, 255, 255, 0.78);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #eff7fd, #d5e7f5);
  box-shadow: inset 0 0 0 1px #eaf2f8;
}

.brand-mark span {
  width: 22px;
  height: 32px;
  display: block;
  clip-path: polygon(0 15%, 50% 0, 100% 15%, 100% 86%, 50% 100%, 0 86%);
  background: linear-gradient(90deg, #c5d8e7 0 48%, #5ba2c7 49% 100%);
}

.brand-kicker,
.eyebrow,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.brand h1 {
  margin: 3px 0 0;
  font-size: 20px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  color: #253546;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--blue-soft);
  border-color: #c1d8eb;
  color: #102d48;
}

.nav-item.is-active {
  box-shadow: inset 4px 0 0 #6aa5c9;
}

.nav-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #edf4fa;
  color: var(--blue-dark);
}

.role-card {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.avatar {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e7eef5;
  color: var(--blue-dark);
  font-weight: 700;
}

.role-switch {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.role-switch input {
  width: 44px;
  height: 24px;
  accent-color: var(--blue);
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.topbar h2 {
  margin: 4px 0 0;
  font-size: 30px;
}

.top-actions,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.searchbox {
  min-width: 320px;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: var(--panel);
  border: 1px solid var(--line-dark);
  border-radius: var(--radius);
}

.searchbox input,
.compact-input,
select {
  height: 42px;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

.searchbox input {
  width: 100%;
  border: 0;
  outline: 0;
}

.primary-button,
.ghost-button,
.text-button,
.icon-button,
.danger-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 16px;
}

.primary-button {
  color: #fff;
  background: linear-gradient(180deg, #3478bb, #2b649e);
  box-shadow: 0 8px 18px rgba(46, 111, 174, 0.22);
}

.ghost-button {
  color: var(--blue-dark);
  background: #fff;
  border-color: var(--line-dark);
}

.danger-button {
  color: #fff;
  background: linear-gradient(180deg, #b85757, #954040);
  box-shadow: 0 8px 18px rgba(149, 64, 64, 0.18);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  box-shadow: none;
}

.text-button {
  color: var(--blue);
  background: transparent;
}

.icon-button {
  width: 40px;
  padding: 0;
  background: #f4f8fb;
  border-color: var(--line);
}

.full {
  width: 100%;
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

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

.metric-card,
.panel,
.filter-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
}

.metric-card p {
  margin: 0;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 8px 0 3px;
  font-size: 34px;
}

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

.split-layout {
  display: grid;
  grid-template-columns: 0.92fr 1.08fr;
  gap: 18px;
}

.panel {
  padding: 18px;
}

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

.panel-header h3,
.filter-panel h3 {
  margin: 4px 0 0;
  font-size: 22px;
}

.status-stack {
  display: grid;
  gap: 10px;
}

.status-row {
  display: grid;
  grid-template-columns: 96px 1fr 42px;
  align-items: center;
  gap: 12px;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #e8eef4;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--blue);
}

.mini-timeline,
#historyList {
  display: grid;
  gap: 10px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 98px 1fr auto;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
}

.filter-panel {
  align-self: start;
  display: grid;
  gap: 14px;
  padding: 18px;
}

.filter-panel label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
}

.filter-panel input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.table-panel {
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

.table-panel .panel-header {
  padding: 18px 18px 0;
}

.table-wrap {
  overflow: auto;
  border-top: 1px solid var(--line);
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f7fa;
  color: #192638;
  font-weight: 700;
}

td:first-child,
th:first-child {
  border-left: 0;
}

tbody tr:hover {
  background: #f8fbff;
}

.thumb {
  width: 56px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: linear-gradient(145deg, #eef5fb, #d8e7f2);
  border: 1px solid #d9e3ec;
  overflow: hidden;
}

.thumb svg {
  width: 46px;
  height: 34px;
}

td:nth-child(1),
td:nth-child(4),
td:nth-child(5),
td:nth-child(7),
th:nth-child(1),
th:nth-child(4),
th:nth-child(5),
th:nth-child(7) {
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 7px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.blue {
  color: #1f5790;
  background: var(--blue-soft);
}

.badge.green {
  color: #20775a;
  background: var(--green-soft);
}

.badge.orange {
  color: #9a5b1d;
  background: var(--orange-soft);
}

.badge.red {
  color: #9a3d3d;
  background: var(--red-soft);
}

.doc-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 2px 4px 2px 0;
  color: #2d4961;
  white-space: nowrap;
}

.file-icon {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 30px;
  border-radius: 4px;
  color: #fff;
  background: #bf5151;
  font-size: 10px;
  font-weight: 700;
}

.file-icon.jpg {
  background: #3f807c;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 7px;
}

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

.history-panel {
  grid-column: 1 / -1;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(420px, 1.18fr);
  gap: 18px;
}

.detail-summary-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.back-button {
  margin-bottom: 14px;
}

.detail-list {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 12px 16px;
  margin: 18px 0 0;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
  min-width: 0;
}

.detail-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.detail-action {
  min-width: 112px;
}

.upload-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.upload-form input {
  max-width: 260px;
}

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

.document-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.document-card:hover {
  border-color: var(--line-dark);
  background: #fff;
}

.document-card small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.document-link {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.document-link strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-delete {
  min-height: 34px;
  padding: 0 11px;
}

.doc-count {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  padding: 0 9px;
  color: #2d4961;
  background: #edf4fa;
  border-radius: 7px;
  white-space: nowrap;
}

.empty-state {
  margin: 0;
  padding: 18px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px dashed var(--line-dark);
  border-radius: var(--radius);
}

.setting-row {
  display: flex;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.setting-copy {
  color: var(--muted);
  line-height: 1.8;
}

.ok {
  color: var(--green);
}

dialog {
  width: min(720px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 30px 90px rgba(20, 44, 70, 0.28);
}

dialog::backdrop {
  background: rgba(23, 33, 45, 0.35);
  backdrop-filter: blur(3px);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  padding: 20px 22px 12px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h3 {
  margin: 4px 0 0;
  font-size: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 20px 22px;
}

.field {
  display: grid;
  gap: 6px;
}

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

.field label {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius);
  padding: 9px 11px;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding: 0 22px 20px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  transform: translateY(24px);
  opacity: 0;
  min-width: 280px;
  padding: 14px 16px;
  color: #fff;
  background: #1d3e5f;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: 180ms ease;
  pointer-events: none;
}

.toast[data-tone="error"] {
  background: #8f3434;
}

.toast[data-tone="warn"] {
  background: #89581d;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.is-readonly .admin-only,
.is-readonly .danger-action,
.is-readonly .mutating-action {
  display: none;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    padding: 14px;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    overflow: auto;
  }

  .nav-item {
    justify-content: center;
    min-width: 112px;
  }

  .role-card {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .inline-actions {
    flex-wrap: wrap;
  }

  .searchbox,
  .compact-input {
    min-width: 0;
    width: 100%;
  }

  .metric-grid,
  .split-layout,
  .workspace,
  .settings-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
