:root {
  color-scheme: light;
  --bg: #eef5fc;
  --panel: #ffffff;
  --ink: #102033;
  --muted: #5d6f86;
  --line: #c9d9ec;
  --line-strong: #99bde4;
  --primary: #127ee3;
  --primary-dark: #0a5fb0;
  --primary-soft: #e6f2ff;
  --primary-pale: #f3f9ff;
  --danger: #c93645;
  --warning: #b96c12;
  --success: #12805c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 0 12px;
}

button:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button.secondary {
  background: #0e6fc8;
  border-color: #0e6fc8;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.warning {
  background: var(--warning);
  border-color: var(--warning);
}

button.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

button.ghost:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
}

button.icon-button {
  width: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input,
select {
  min-height: 38px;
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  padding: 10px;
}

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

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 22px;
}

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

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.brand strong {
  display: block;
  color: var(--primary-dark);
  font-size: 18px;
}

.brand small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.nav button {
  justify-content: flex-start;
  min-height: 42px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  text-align: left;
}

.nav button.active {
  border-color: var(--line-strong);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.content {
  min-width: 0;
}

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

.login-card {
  display: grid;
  width: min(100%, 440px);
  gap: 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 28px;
  box-shadow: 0 18px 48px rgba(16, 32, 51, 0.12);
}

.login-logo {
  width: 116px;
  max-height: 70px;
  object-fit: contain;
}

.login-card h1,
.topbar h1 {
  margin: 0;
  color: var(--primary-dark);
  font-size: 24px;
}

.login-card p {
  margin: -6px 0 2px;
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.workspace {
  min-height: 100vh;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  margin-bottom: 16px;
  padding: 16px 18px;
}

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

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  align-items: start;
  gap: 14px;
  margin-bottom: 14px;
}

.stat,
.catalog-card,
.edit-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.catalog-card {
  display: flex;
  min-width: 0;
  max-height: 560px;
  flex-direction: column;
}

.stat span {
  color: var(--muted);
  font-weight: 700;
}

.stat strong {
  display: block;
  color: var(--primary-dark);
  font-size: 26px;
  margin-top: 5px;
}

.toolbar,
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.edit-panel {
  margin-bottom: 14px;
}

.edit-panel h2,
.catalog-card h2 {
  margin: 0 0 12px;
  color: var(--primary-dark);
  font-size: 17px;
}

.avatar-row {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.avatar-row img {
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--primary-soft);
  object-fit: cover;
}

.avatar-row label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px #fff;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  table-layout: fixed;
}

.excel-table {
  min-width: 2200px;
}

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

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.excel-table th,
.excel-table td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.excel-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.excel-table td {
  background: #fff;
  font-size: 12px;
}

.code-link {
  min-height: auto;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--primary-dark);
  padding: 0;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.code-link:hover,
.code-link:focus-visible {
  background: transparent;
  color: var(--primary);
  outline: 2px solid var(--primary-soft);
  outline-offset: 2px;
}

.excel-table tr:nth-child(even) td {
  background: var(--primary-pale);
}

.excel-table td.actions {
  display: flex;
  min-width: 220px;
  flex-wrap: wrap;
  gap: 5px;
}

.excel-table td.actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-cell img {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--primary-soft);
  object-fit: cover;
}

.pill {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.catalog-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.catalog-list {
  display: grid;
  gap: 8px;
  max-height: 430px;
  margin-top: 12px;
  overflow: auto;
  padding-right: 4px;
}

.catalog-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--primary-pale);
  padding: 8px;
}

.catalog-row span {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
  white-space: normal;
}

.catalog-row div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.catalog-row button {
  min-height: 32px;
  padding: 0 10px;
  white-space: nowrap;
}

.toast,
.message {
  color: var(--danger);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px 14px;
  box-shadow: 0 14px 32px rgba(16, 32, 51, 0.16);
}

.app-footer {
  margin-top: 22px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 32, 51, 0.46);
}

.modal-card {
  position: relative;
  width: min(1120px, 100%);
  max-height: min(88vh, 860px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(16, 32, 51, 0.26);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--primary-soft);
  padding: 16px 18px;
}

.modal-header h2 {
  margin: 0;
  color: var(--primary-dark);
  font-size: 20px;
}

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

.modal-body {
  max-height: calc(min(88vh, 860px) - 74px);
  overflow: auto;
  padding: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 14px;
}

.detail-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.detail-section h3 {
  margin: 0 0 10px;
  color: var(--primary-dark);
  font-size: 16px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

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

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

.kv strong {
  font-size: 14px;
}

.detail-actions,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.timeline {
  display: grid;
  gap: 10px;
}

.comment-item {
  border-left: 3px solid var(--primary);
  background: var(--primary-pale);
  padding: 10px 12px;
}

.comment-item strong {
  display: block;
}

.comment-item small {
  color: var(--muted);
}

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

.attachments a {
  color: var(--primary-dark);
  font-weight: 700;
  text-decoration: none;
}

.empty-state {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 14px;
}

.assign-list {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
  margin: 12px 0;
}

.assign-user {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.assign-user.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.assign-user img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 12px;
  }

  .brand {
    align-items: flex-start;
  }

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

  .nav button {
    min-height: 40px;
    padding: 0 6px;
    text-align: center;
  }

  .workspace {
    padding: 12px;
  }

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

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

@media (max-width: 640px) {
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .stats,
  .catalog-grid {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 20px;
  }

  .modal {
    padding: 8px;
  }

  .modal-card {
    max-height: 92vh;
  }
}
