:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #151922;
  --muted: #667085;
  --border: #d9dee7;
  --primary: #1f3a5f;
  --primary-hover: #172b47;
  --danger: #9b1c1c;
  --success: #166534;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-header {
  background: #101828;
  color: white;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
}

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

.header-links a {
  color: white;
  opacity: 0.9;
}

.container {
  width: min(1180px, calc(100% - 24px));
  margin: 22px auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

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

.page-title h1 {
  margin: 0;
  font-size: 1.7rem;
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2,
.card h3 {
  margin-top: 0;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.btn,
button {
  display: inline-block;
  background: var(--primary);
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover,
button:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

.btn-secondary {
  background: #eef2f7;
  color: var(--text);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-danger,
button.btn-danger {
  background: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 11px;
  margin-top: 6px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  font: inherit;
}

textarea {
  min-height: 110px;
}

label {
  font-weight: 600;
  font-size: 0.92rem;
}

.form-section {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 18px;
}

.form-section:first-child {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.form-section h2 {
  font-size: 1.1rem;
  margin: 0 0 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f7;
  font-size: 0.82rem;
  font-weight: 700;
}

.badge-graded {
  background: #fff7ed;
  color: #9a3412;
}

.badge-raw {
  background: #ecfdf3;
  color: var(--success);
}

.item-list {
  display: grid;
  gap: 12px;
}

.item-row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 14px;
  align-items: center;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.thumb {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #eef2f7;
}

.thumb-placeholder {
  width: 76px;
  height: 76px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.item-title {
  font-weight: 800;
  margin-bottom: 4px;
}

.item-meta {
  color: var(--muted);
  font-size: 0.92rem;
}

.photo-large {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.login-box {
  max-width: 430px;
  margin: 60px auto;
}

@media (max-width: 760px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }

  .page-title {
    flex-direction: column;
  }

  .item-row {
    grid-template-columns: 64px 1fr;
  }

  .item-row .actions {
    grid-column: 1 / -1;
  }

  .thumb,
  .thumb-placeholder {
    width: 64px;
    height: 64px;
  }
}

.cm-autocomplete {
  position: relative;
}

.cm-results {
  display: none;
  position: absolute;
  z-index: 50;
  left: 0;
  right: 0;
  top: calc(100% - 10px);
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}

.cm-result {
  width: 100%;
  display: block;
  text-align: left;
  background: white;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 11px 12px;
  cursor: pointer;
}

.cm-result:hover {
  background: #f8fafc;
}

.cm-result strong,
.cm-result span,
.cm-result small {
  display: block;
}

.cm-result span {
  color: var(--muted);
  font-weight: 500;
  margin-top: 2px;
}

.cm-result small {
  color: var(--muted);
  margin-top: 2px;
}

/* Mobile refinements */
.table-wrap {
  -webkit-overflow-scrolling: touch;
}

.table-wrap table {
  min-width: 760px;
}

@media (max-width: 760px) {
  body {
    background: #f6f7fa;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .brand {
    font-size: 1.05rem;
  }

  .header-links {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    white-space: nowrap;
  }

  .header-links a {
    background: rgba(255, 255, 255, 0.12);
    padding: 8px 10px;
    border-radius: 999px;
    font-size: 0.9rem;
    flex: 0 0 auto;
  }

  .container {
    width: calc(100% - 16px);
    margin: 12px auto;
  }

  .panel,
  .card {
    padding: 14px;
    border-radius: 12px;
  }

  .page-title {
    gap: 10px;
    margin-bottom: 12px;
  }

  .page-title h1 {
    font-size: 1.35rem;
  }

  .page-title .actions {
    width: 100%;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .actions .btn,
  .actions button,
  .btn,
  button {
    width: 100%;
    text-align: center;
  }

  input,
  select,
  textarea {
    font-size: 16px;
    padding: 12px;
  }

  label {
    font-size: 0.9rem;
  }

  .item-row {
    grid-template-columns: 72px 1fr;
    align-items: start;
    padding: 10px;
  }

  .thumb,
  .thumb-placeholder {
    width: 72px;
    height: 72px;
  }

  .item-title {
    font-size: 1rem;
  }

  .item-meta {
    font-size: 0.86rem;
    line-height: 1.35;
  }

  .badge {
    margin-bottom: 4px;
  }

  .photo-large {
    max-height: 70vh;
    object-fit: contain;
    background: #f8fafc;
  }

  .cm-results {
    position: fixed;
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 12px;
    max-height: 55vh;
    border-radius: 16px;
  }

  .cm-result {
    padding: 14px;
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 0.9rem;
  }

  .login-box {
    margin: 32px auto;
  }
}

@media (max-width: 420px) {
  .page-title h1 {
    font-size: 1.22rem;
  }

  .item-row {
    grid-template-columns: 60px 1fr;
  }

  .thumb,
  .thumb-placeholder {
    width: 60px;
    height: 60px;
  }

  .panel,
  .card {
    padding: 12px;
  }
}
