:root {
  --bg: #f3f4f6; --panel: #ffffff; --panel-header: #f9fafb;
  --text: #1f2937; --text-secondary: #4b5563; --text-tertiary: #9ca3af;
  --border: #e5e7eb; --accent: #3b82f6; --accent-light: #eff6ff;
  --accent-border: #bfdbfe;
  
  --diff-bg: #fffbeb; --diff-border: #f59e0b;
  --crit-bg: #fef2f2; --crit-border: #ef4444; --crit-text: #b91c1c;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; height: 100vh; display: flex; flex-direction: column; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.topbar { display: flex; gap: 12px; align-items: center; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); z-index: 20; flex-shrink: 0; }
.paramlabel { font-size: 14px; color: var(--text-secondary); white-space: nowrap; }
.paraminput { flex: 1; background: var(--bg); border: 1px solid var(--border); padding: 8px 12px; border-radius: 6px; outline: none; font-size: 14px; }
.paraminput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.btn { background: var(--accent); color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.btn:disabled { background: #9ca3af; cursor: not-allowed; }
.btn.done { background: #10b981; }
.status { min-width: 150px; color: var(--text-tertiary); font-size: 16px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; padding: 16px; flex: 1; min-height: 0; }
.col { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.coltitle { padding: 10px 16px; background: var(--panel-header); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 600; color: var(--text-secondary); flex-shrink: 0; }
.hint { font-weight: 400; color: var(--text-tertiary); font-size: 12px; margin-left: 8px;}
.badge { display: inline-flex; align-items: center; justify-content: center; background: var(--text-secondary); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 12px; margin-left: 8px; min-width: 36px; }
.iconbtn { background: transparent; border: 1px solid var(--border); padding: 4px 8px; border-radius: 6px; cursor: pointer; font-size: 11px; text-transform: uppercase; }
.iconbtn:hover { background: var(--bg); }
.list { overflow-y: auto; padding: 12px; height: 100%; background: var(--panel); outline: none; }

.row { 
    display: flex; flex-direction: column; gap: 4px; padding: 8px 12px; 
    margin-bottom: 8px; border-radius: 8px; border: 1px solid transparent; 
    box-sizing: border-box; min-height: 60px; cursor: pointer; 
    transition: background 0.1s; border-left: 4px solid transparent;
    position: relative;
}
.row:hover { background: var(--bg); border-color: var(--border); }
.row.selected { background: var(--accent-light) !important; border: 1px solid var(--accent-border); border-left-color: var(--accent); }
.row.diff { background: var(--diff-bg); border: 1px solid var(--diff-border); border-left-color: var(--diff-border); }
.row.critical { background: var(--crit-bg); border: 1px solid var(--crit-border); border-left-color: var(--crit-border); }
.row.critical .txt { color: var(--crit-text); font-weight: 500; }

.row .meta { 
    display: flex; justify-content: space-between; font-size: 11px; 
    color: var(--text-tertiary); font-family: monospace; user-select: none;
    padding-right: 25px;
}
.meta-left, .meta-right { display: flex; align-items: center; gap: 6px; }
.stat-item { background: rgba(0,0,0,0.04); padding: 1px 5px; border-radius: 4px; }
.cps-ok { color: #059669; }
.cps-warn { color: #d97706; font-weight: bold; }
.cps-crit { color: #dc2626; font-weight: bold; }

.row .txt { font-size: 15px; line-height: 1.5; color: var(--text); white-space: pre-wrap; word-wrap: break-word; padding: 2px; transition: background-color 0.5s; }
.row .txt[contenteditable="true"]:focus { background: #fff; border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-light); }

/* Debug Button */
.debug-btn { 
    position: absolute;
    top: 6px;
    right: 6px;
    cursor: pointer; 
    opacity: 0.8;
    font-size: 14px; 
    transition: all 0.2s; 
    user-select: none;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    width: 24px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}
.debug-btn:hover { 
    transform: scale(1.1); 
    opacity: 1;
    border-color: #d1d5db;
    background: #f9fafb;
}

/* Rephrase Button (below bug button) */
.rephrase-btn {
    position: absolute;
    top: 32px;
    right: 6px;
    cursor: pointer;
    opacity: 0.8;
    font-size: 12px;
    transition: all 0.2s;
    user-select: none;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    width: 24px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}
.rephrase-btn:hover {
    transform: scale(1.1);
    opacity: 1;
    border-color: #d1d5db;
    background: #f9fafb;
}

.ctxmenu { position: fixed; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 4px; z-index: 9999; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }
.ctxitem { padding: 8px 12px; cursor: pointer; font-size: 13px; border-radius: 4px; }
.ctxitem:hover { background: var(--bg); }
.hidden { display: none; }
/* Debug Modal */
.modal { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }

.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }

.modal-panel {
  position: relative;
  width: min(900px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 10px 14px;
  background: var(--panel-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-title { font-size: 14px; font-weight: 700; color: var(--text-secondary); }
.modal-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
}
.modal-close:hover { background: var(--bg); }

.modal-body { padding: 12px 14px; overflow: auto; }
.modal-subtitle { font-size: 12px; color: var(--text-tertiary); margin-bottom: 8px; }

.modal-text {
  margin: 0;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;     /* перенос строк + сохранение \n */
  word-break: break-word;    /* перенос длинных токенов */
}

.modal-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.headbtns {
  display: flex;
  gap: 8px;
  align-items: center;
}