
  :root {
    --bg: #f5f0e8;
    --surface: #fffdf8;
    --surface2: #f0ebe0;
    --border: #d6cdb8;
    --border-dark: #b8a98a;
    --text: #2a2218;
    --text-muted: #7a6e5e;
    --accent: #8b4513;
    --accent-light: #c4763a;
    --accent-bg: #fdf3e7;
    --danger: #c0392b;
    --danger-bg: #fdf2f0;
    --success: #2e7d52;
    --success-bg: #edf7f2;
    --shadow: 0 2px 12px rgba(42,34,24,0.08);
    --shadow-lg: 0 8px 32px rgba(42,34,24,0.14);
    --radius: 6px;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
  }

  /* HEADER */
  header {
    background: var(--text);
    color: var(--bg);
    padding: 20px 40px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 16px rgba(0,0,0,0.25);
  }
  header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex: 1;
  }
  header .paw { font-size: 20px; }
  .header-actions { display: flex; gap: 8px; }

  /* UPLOAD SCREEN */
  #loadScreen,
  #uploadScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 66px);
    padding: 40px;
  }
  .load-card,
  .upload-card {
    background: var(--surface);
    border: 2px dashed var(--border-dark);
    border-radius: 12px;
    padding: 60px 80px;
    text-align: center;
    max-width: 460px;
    width: 100%;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
  }
  .upload-card:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
  }
  .load-card .load-icon,
  .upload-card .upload-icon { font-size: 48px; margin-bottom: 16px; }
  .load-card h2,
  .upload-card h2 {
    font-family: 'Playfair Display', serif;
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text);
  }
  .load-card p,
  .upload-card p { color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }
  #fileInput { display: none; }
  .btn-load,
  .btn-upload {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 28px;
    border-radius: var(--radius);
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
  }
  .btn-load:hover,
  .btn-upload:hover { background: var(--accent-light); }

  /* MAIN LAYOUT */
  #editor { display: none; }
  .editor-body {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: calc(100vh - 66px);
  }

  /* SIDEBAR */
  .sidebar {
    background: var(--text);
    color: var(--bg);
    padding: 24px 0;
    position: sticky;
    top: 66px;
    height: calc(100vh - 66px);
    overflow-y: auto;
  }
  .sidebar-section {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
  }
  .sidebar-section-title {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(245,240,232,0.45);
    padding: 8px 20px 4px;
  }
  .sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: rgba(245,240,232,0.75);
    cursor: pointer;
    font-size: 13.5px;
    transition: background 0.15s, color 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: 'DM Sans', sans-serif;
  }
  .sidebar-link:hover { background: rgba(255,255,255,0.06); color: var(--bg); }
  .sidebar-link.active { background: rgba(139,69,19,0.35); color: white; }
  .sidebar-link .icon { font-size: 15px; width: 20px; text-align: center; }
  .sidebar-link .badge {
    margin-left: auto;
    background: rgba(255,255,255,0.12);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-family: 'DM Mono', monospace;
  }

  /* CONTENT */
  .content {
    padding: 32px 36px;
    overflow-y: auto;
  }

  /* PANELS */
  .panel { display: none; }
  .panel.active { display: block; }

  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
  }
  .panel-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 24px;
  }

  /* BUTTONS */
  .btn {
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
  }
  .btn-primary { background: var(--accent); color: white; }
  .btn-primary:hover { background: var(--accent-light); }
  .btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
  .btn-secondary:hover { background: var(--border); }
  .btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #f0c0bb; }
  .btn-danger:hover { background: #fae0dd; }
  .btn-success { background: var(--success-bg); color: var(--success); border: 1px solid #b0ddc4; }
  .btn-success:hover { background: #d0eddf; }
  .btn-sm { padding: 5px 10px; font-size: 12px; }
  .btn-icon { padding: 6px 8px; font-size: 14px; }
  .btn-ghost { background: none; color: var(--text-muted); border: 1px solid transparent; }
  .btn-ghost:hover { background: var(--surface2); border-color: var(--border); color: var(--text); }

  /* TABLES */
  .table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
  }
  table { width: 100%; border-collapse: collapse; }
  th {
    background: var(--surface2);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
  }
  td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }
  tr:last-child td { border-bottom: none; }
  tr:hover td { background: var(--accent-bg); }
  .id-badge {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    background: var(--surface2);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--text-muted);
  }

  /* INLINE EDIT INPUT */
  .inline-input {
    border: 1px solid transparent;
    background: transparent;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px;
    color: var(--text);
    width: 100%;
    transition: border 0.15s, background 0.15s;
  }
  .inline-input:hover { border-color: var(--border); background: var(--surface); }
  .inline-input:focus { border-color: var(--accent); background: var(--surface); outline: none; box-shadow: 0 0 0 3px rgba(139,69,19,0.12); }

  /* DOG SELECTOR */
  .dog-selector-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    position: relative;
  }
  .dog-selector-bar label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    white-space: nowrap;
  }
  .dog-search-wrap {
    flex: 1;
    position: relative;
  }
  #dogSearchInput {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--bg);
    padding: 8px 12px 8px 34px;
    border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: var(--text);
    transition: border 0.15s, box-shadow 0.15s;
  }
  #dogSearchInput:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(139,69,19,0.1); }
  .search-icon {
    position: absolute;
    left: 10px; top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    pointer-events: none;
    color: var(--text-muted);
  }
  #dogDropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 260px;
    overflow-y: auto;
  }
  #dogDropdown.open { display: block; }
  .dog-option {
    padding: 9px 14px;
    cursor: pointer;
    display: flex;
    align-items: baseline;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
  }
  .dog-option:last-child { border-bottom: none; }
  .dog-option:hover, .dog-option.focused { background: var(--accent-bg); }
  .dog-option .opt-reg { font-size: 13.5px; font-weight: 500; }
  .dog-option .opt-call { font-size: 12px; color: var(--text-muted); }
  .dog-option .opt-key {
    margin-left: auto;
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface2);
    border: 1px solid var(--border);
    padding: 1px 5px;
    border-radius: 3px;
  }
  .dog-option em { font-style: normal; background: #ffe0b0; border-radius: 2px; }
  .no-results {
    padding: 16px 14px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
  }

  /* DOG DETAIL */
  .dog-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
  }
  .dog-detail-header {
    background: var(--surface2);
    padding: 16px 22px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--border);
  }
  .dog-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    color: white;
  }
  .dog-avatar.female { background: #c4763a; }
  .dog-detail-header-info { flex: 1; min-width: 0; }
  .dog-detail-header-info .reg-name {
    font-family: 'Playfair Display', serif;
    font-size: 17px;
    font-weight: 600;
  }
  .dog-detail-header-info .call-name {
    font-size: 12.5px;
    color: var(--text-muted);
  }
  .dog-key {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 4px;
  }
  .dog-detail-body { padding: 22px; }
  .field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
  }
  .field-row.full { grid-template-columns: 1fr; }
  .field-row.three { grid-template-columns: 1fr 1fr 1fr; }
  .field-group { display: flex; flex-direction: column; gap: 3px; }
  .field-label {
    font-size: 10.5px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
  }
  .field-input {
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 7px 10px;
    border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    color: var(--text);
    width: 100%;
    transition: border 0.15s, box-shadow 0.15s;
  }
  .field-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(139,69,19,0.1); }
  select.field-input { cursor: pointer; }
  select[multiple].field-input { height: auto; min-height: 72px; padding: 4px; }
  select[multiple].field-input option { padding: 3px 6px; border-radius: 3px; }
  select[multiple].field-input option:checked { background: var(--accent); color: white; }

  /* REGISTRATIONS */
  .reg-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
  .reg-row { display: flex; gap: 6px; align-items: center; }
  .reg-row select.field-input { flex: 0 0 90px; width: 90px; }
  .reg-row input.field-input { flex: 1; }

  /* IMAGE CHECKBOXES */
  .checkbox-row { display: flex; gap: 16px; }
  .checkbox-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--text-muted); cursor: pointer;
  }
  .checkbox-label input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
  .checkbox-label:hover { color: var(--text); }

  .dog-detail-footer {
    padding: 12px 22px;
    border-top: 1px solid var(--border);
    background: var(--surface2);
    display: flex;
    justify-content: flex-end;
  }

  /* EMPTY / NO SELECTION */
  .no-dog-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    color: var(--text-muted);
    text-align: center;
  }
  .no-dog-selected .big-icon { font-size: 40px; margin-bottom: 14px; }
  .no-dog-selected p { font-size: 13.5px; line-height: 1.6; }

  /* TAG PILLS */
  .tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-bg);
    border: 1px solid #e8c89a;
    color: var(--accent);
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 20px;
  }

  /* TOAST */
  #toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: var(--text);
    color: var(--bg);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  #toast.show { opacity: 1; transform: translateY(0); }

  /* MODAL */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(42,34,24,0.55);
    z-index: 500;
    align-items: center;
    justify-content: center;
  }
  .modal-overlay.open { display: flex; }
  .modal {
    background: var(--surface);
    border-radius: 10px;
    padding: 28px;
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
  }
  @keyframes modalIn { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  .modal h3 {
    font-family: 'Playfair Display', serif;
    font-size: 18px;
    margin-bottom: 16px;
  }
  .modal .field-group { margin-bottom: 14px; }
  .modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

  /* TITLE PILL WIDGET */
  .title-widget { display: flex; flex-direction: column; gap: 6px; }
  .title-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    min-height: 32px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 7px;
    align-items: center;
  }
  .title-pills:empty::after {
    content: 'None';
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
  }
  .title-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent);
    color: white;
    font-size: 11.5px;
    font-weight: 500;
    padding: 3px 8px 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
    font-family: 'DM Mono', monospace;
  }
  .title-pill button {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 0 0 0 2px;
    display: flex;
    align-items: center;
  }
  .title-pill button:hover { color: white; }
  .title-add-row { display: flex; gap: 6px; }
  .title-add-row select.field-input { flex: 1; }

  /* SEARCHABLE SELECT */
  .ss-wrap { position: relative; }
  .ss-input-row { display: flex; gap: 6px; }
  .ss-input {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--bg);
    padding: 7px 10px;
    border-radius: 4px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px;
    color: var(--text);
    transition: border 0.15s;
  }
  .ss-input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(139,69,19,0.1); }
  .ss-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    max-height: 220px;
    overflow-y: auto;
  }
  .ss-dropdown.open { display: block; }
  .ss-option {
    padding: 7px 12px;
    cursor: pointer;
    display: flex;
    align-items: baseline;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background 0.1s;
  }
  .ss-option:last-child { border-bottom: none; }
  .ss-option:hover, .ss-option.focused { background: var(--accent-bg); }
  .ss-option .ss-opt-main { flex: 1; font-weight: 500; }
  .ss-option .ss-opt-sub { font-size: 11.5px; color: var(--text-muted); }
  .ss-option em { font-style: normal; background: #ffe0b0; border-radius: 2px; }
  .ss-no-results { padding: 10px 12px; color: var(--text-muted); font-size: 12px; text-align: center; }

  /* SECTION DIVIDER */
  .section-divider {
    font-size: 10.5px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 10px 0 6px;
    border-top: 1px solid var(--border);
    margin-top: 12px;
    margin-bottom: 8px;
  }

  /* EMPTY STATE */
  .empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
  }
  .empty-state .icon { font-size: 36px; margin-bottom: 12px; }
  .empty-state p { font-size: 13px; }

  /* SCROLLBAR */
  ::-webkit-scrollbar { width: 7px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--border-dark); }
  /* IMAGE MANAGER */
  .image-manager { display: flex; flex-direction: column; gap: 16px; }
  .img-section { display: flex; flex-direction: column; gap: 8px; }
  .img-section-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
  .img-preview-row { display: flex; align-items: center; gap: 12px; }
  .img-upload-actions { display: flex; flex-direction: column; gap: 6px; }

  .img-thumb-wrap {
    width: 72px; height: 72px; border-radius: 8px;
    border: 2px solid var(--border); overflow: hidden;
    background: var(--bg-subtle); flex-shrink: 0; position: relative;
  }
  .img-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
  .img-thumb-missing { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; font-size: 10px; color: var(--text-muted); text-align: center; padding: 4px; }
  .img-thumb-wrap.missing .img-thumb { display: none; }
  .img-thumb-wrap.missing .img-thumb-missing { display: flex; }

  .img-photos-grid { display: flex; flex-wrap: wrap; gap: 8px; }
  .photo-thumb-wrap {
    width: 72px; height: 72px; border-radius: 8px;
    border: 2px solid var(--border); overflow: hidden;
    background: var(--bg-subtle); flex-shrink: 0; position: relative;
  }
  .photo-thumb-num {
    position: absolute; bottom: 2px; left: 4px;
    font-size: 10px; font-weight: 700; color: rgba(255,255,255,0.9);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  }
  .photo-thumb-del {
    position: absolute; top: 2px; right: 2px;
    background: rgba(0,0,0,0.5); border: none; color: #fff;
    font-size: 10px; width: 16px; height: 16px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    padding: 0; line-height: 1;
  }
  .photo-thumb-del:hover { background: rgba(220,38,38,0.8); }
  .photo-thumb-wrap.missing .img-thumb { display: none; }
  .photo-thumb-wrap.missing .img-thumb-missing { display: flex; }
