:root {
    color-scheme: light;
    --bg: #eef1f5;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --ink: #17202c;
    --muted: #677384;
    --faint: #8c97a8;
    --line: #d9dee8;
    --line-soft: #e8ecf3;
    --primary: #2457a6;
    --primary-strong: #143f80;
    --primary-soft: #e7eefb;
    --success: #1f7a4d;
    --success-soft: #e7f5ee;
    --warning-soft: #fff5d8;
    --danger: #b3261e;
    --danger-soft: #fdebea;
    --shadow: 0 18px 45px rgba(26, 36, 55, 0.12);
  }

  * { box-sizing: border-box; }

  html,
  body {
    height: 100%;
  }

  body {
    margin: 0;
    min-width: 320px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
  }

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

  button {
    border: 0;
  }

  #app {
    display: grid;
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    min-height: 620px;
    overflow: hidden;
  }

  #sidebar {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
  }

  #sidebar-header {
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--line-soft);
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  }

  .sidebar-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
  }

  #sidebar-header h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    letter-spacing: 0;
  }

  #sidebar-header p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 12px;
  }

  .lang-picker {
    display: grid;
    gap: 6px;
    min-width: 120px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
  }

  .lang-picker span {
    text-align: right;
  }

  #sidebar-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
  }

  .stat-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 9px;
    color: var(--primary-strong);
    background: var(--primary-soft);
    border: 1px solid #ccdaf1;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
  }

  #search-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 116px;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line-soft);
    background: var(--surface);
  }

  #search-input,
  #language-mode,
  #filter-edited,
  #review_select,
  .field-group input[type=number],
  .field-group textarea {
    width: 100%;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  }

  #search-input {
    min-width: 0;
    padding: 9px 11px;
  }

  #language-mode,
  #filter-edited {
    padding: 9px 10px;
  }

  #search-input:focus,
  #language-mode:focus,
  #filter-edited:focus,
  #review_select:focus,
  .field-group input[type=number]:focus,
  .field-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(36, 87, 166, 0.12);
  }

  #row-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
    background: var(--surface-soft);
  }

  .row-item {
    display: block;
    width: 100%;
    min-height: 82px;
    margin-bottom: 8px;
    padding: 12px;
    text-align: left;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
  }

  .row-item:hover {
    border-color: #b8c7de;
    box-shadow: 0 10px 24px rgba(23, 32, 44, 0.08);
    transform: translateY(-1px);
  }

  .row-item.active {
    border-color: var(--primary);
    box-shadow: inset 4px 0 0 var(--primary), 0 14px 28px rgba(36, 87, 166, 0.14);
  }

  .row-topline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
  }

  .img-name {
    min-width: 0;
    color: var(--primary-strong);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .row-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
  }

  .chip {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--surface-soft);
    border: 1px solid var(--line-soft);
    color: var(--muted);
    white-space: nowrap;
  }

  .chip-edited {
    color: var(--success);
    background: var(--success-soft);
    border-color: #bfe6d1;
    font-weight: 700;
  }

  .chip-review {
    color: #6b4f00;
    background: var(--warning-soft);
    border-color: #efd88a;
    font-weight: 700;
  }

  .row-submeta {
    display: block;
    margin-top: 8px;
    color: var(--faint);
    font-size: 11px;
    line-height: 1.4;
  }

  #pagination {
    display: grid;
    flex: 0 0 auto;
    grid-template-columns: 76px minmax(0, 1fr) 76px;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  #pagination button,
  .btn {
    min-height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    transition: background .15s ease, border-color .15s ease, color .15s ease, opacity .15s ease;
  }

  #pagination button {
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
  }

  #pagination button:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
  }

  #pagination button:disabled {
    opacity: .42;
    cursor: default;
  }

  #pagination span {
    min-width: 0;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
  }

  #detail {
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
  }

  .empty-state,
  .loading-state {
    display: grid;
    min-height: 100%;
    place-items: center;
    padding: 32px;
    color: var(--muted);
    text-align: center;
  }

  .empty-state-inner {
    max-width: 420px;
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    box-shadow: var(--shadow);
  }

  .empty-state h2 {
    margin: 0 0 8px;
    color: var(--ink);
    font-size: 20px;
  }

  .empty-state p {
    margin: 0;
    line-height: 1.6;
  }

  .detail-shell {
    max-width: 1280px;
    margin: 0 auto;
    padding: 22px;
  }

  .record-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    margin: -22px -22px 20px;
    padding: 18px 22px;
    background: rgba(238, 241, 245, .94);
    border-bottom: 1px solid rgba(217, 222, 232, .9);
    backdrop-filter: blur(12px);
  }

  .record-title {
    min-width: 0;
  }

  .record-title h2 {
    margin: 0;
    color: var(--ink);
    font-size: 22px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .record-subtitle {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
  }

  .action-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
  }

  .btn-save {
    min-width: 132px;
    padding: 0 18px;
    color: #fff;
    background: var(--primary);
  }

  .btn-secondary {
    min-width: 124px;
    padding: 0 16px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
  }

  .btn-save:hover:not(:disabled) {
    background: var(--primary-strong);
  }

  .btn-secondary:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
  }

  .btn:disabled {
    opacity: .55;
    cursor: default;
  }

  .status-msg {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    max-width: 320px;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
  }

  .status-ok {
    color: var(--success);
    background: var(--success-soft);
  }

  .status-err {
    color: var(--danger);
    background: var(--danger-soft);
  }

  .detail-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
  }

  .side-panel {
    position: sticky;
    top: 92px;
    display: grid;
    gap: 14px;
  }

  .img-wrap,
  .meta-panel,
  .ai-eval-box,
  .section,
  .summary-section {
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(26, 36, 55, 0.06);
  }

  .img-wrap {
    display: grid;
    place-items: center;
    min-height: 420px;
    padding: 12px;
    overflow: hidden;
  }

  .img-wrap img {
    display: block;
    width: 100%;
    max-height: min(62vh, 620px);
    object-fit: contain;
    border-radius: 8px;
  }

  .meta-panel {
    padding: 14px;
  }

  .meta-grid {
    display: grid;
    gap: 10px;
  }

  .meta-item {
    display: grid;
    gap: 5px;
    padding: 10px;
    background: var(--surface-soft);
    border: 1px solid var(--line-soft);
    border-radius: 8px;
  }

  .meta-item .lbl,
  .field-group label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
  }

  .meta-item .val {
    min-height: 20px;
    font-size: 14px;
    font-weight: 800;
    overflow-wrap: anywhere;
  }

  #review_select {
    min-height: 38px;
    padding: 8px 10px;
    font-weight: 700;
  }

  .score-total {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-width: 78px;
    min-height: 42px;
    padding: 6px 14px;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid #bfd0ee;
    border-radius: 8px;
    font-size: 22px;
    font-weight: 900;
  }

  .main-panel {
    display: grid;
    gap: 14px;
    min-width: 0;
  }

  .ai-eval-box {
    padding: 16px;
  }

  .panel-title {
    margin: 0 0 10px;
    color: var(--ink);
    font-size: 14px;
    font-weight: 900;
  }

  .ai-eval-text {
    max-height: 260px;
    overflow: auto;
    padding: 12px;
    color: #344052;
    background: var(--surface-soft);
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.65;
  }

  .ai-eval-text .val {
    white-space: pre-wrap;
  }

  .ai-eval-text .lbl {
    font-weight: 700;
  }

  .section,
  .summary-section {
    overflow: hidden;
  }

  .section-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    background: #fbfcfe;
    border-bottom: 1px solid var(--line-soft);
  }

  .section-title {
    min-width: 0;
    font-size: 14px;
    font-weight: 900;
    overflow-wrap: anywhere;
  }

  .score-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 58px;
    min-height: 28px;
    padding: 4px 9px;
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid #bfd0ee;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
  }

  .section-body {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    padding: 14px 16px 16px;
  }

  .section-body.full {
    grid-template-columns: minmax(0, 1fr);
  }

  .field-group {
    display: grid;
    align-content: start;
    gap: 6px;
    min-width: 0;
  }

  .field-wide {
    grid-column: span 2;
  }

  .field-group input[type=number] {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 16px;
    font-weight: 800;
  }

  .field-group textarea {
    min-height: 92px;
    padding: 9px 10px;
    resize: vertical;
    line-height: 1.55;
  }

  .field-group textarea[rows="4"] {
    min-height: 124px;
  }

  .readonly-field {
    color: var(--muted);
    background: #f3f6fb;
  }

  .readonly-field:focus {
    border-color: var(--line);
    box-shadow: none;
  }

  .summary-section .section-header {
    background: var(--warning-soft);
  }

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

  @media (max-width: 1040px) {
    #app {
      grid-template-columns: 330px minmax(0, 1fr);
    }

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

    .side-panel {
      position: static;
      grid-template-columns: minmax(240px, .9fr) minmax(240px, 1fr);
    }

    .img-wrap {
      min-height: 340px;
    }
  }

  @media (max-width: 820px) {
    #app {
      grid-template-columns: 1fr;
      grid-template-rows: 42vh 58vh;
      grid-template-rows: 42dvh 58dvh;
      height: 100vh;
      height: 100dvh;
      min-height: 720px;
    }

    #sidebar {
      border-right: 0;
      border-bottom: 1px solid var(--line);
    }

    #search-bar {
      grid-template-columns: minmax(0, 1fr) 108px;
    }

    .sidebar-header-top {
      flex-direction: column;
    }

    .lang-picker {
      width: 100%;
    }

    .lang-picker span {
      text-align: left;
    }

    .detail-shell {
      padding: 16px;
    }

    .record-header {
      position: static;
      grid-template-columns: 1fr;
      margin: -16px -16px 16px;
      padding: 16px;
    }

    .action-bar {
      justify-content: flex-start;
      flex-wrap: wrap;
    }

    .side-panel {
      grid-template-columns: 1fr;
    }

    .section-body {
      grid-template-columns: 1fr;
    }

    .field-wide {
      grid-column: auto;
    }
  }
