:root {
  --bg: #f6f5f3;
  --panel: #ffffff;
  --border: #e2ded8;
  --text: #2b2823;
  --muted: #8a8378;
  --accent: #c8763a;
  --accent-dark: #a35f2c;
  --used-bg: #e8f3e4;
  --danger: #b8483d;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---------- Login screen ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 20px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.login-card button {
  width: 100%;
}

#login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
  min-height: 16px;
}

/* ---------- App layout ---------- */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 16px;
  margin: 0;
}

.header-actions button {
  margin-left: 8px;
}
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-left: 8px;
}
.view-toggle .view-btn {
  margin: 0;
  border: none;
  border-radius: 0;
}
.view-btn.active {
  background: var(--accent);
  color: white;
}

#right-panel.collapsed { display: none; }

/* ---------- Многоколоночный компактный список ---------- */
#designs-columns {
  column-width: 220px;
  column-gap: 18px;
}
.design-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  break-inside: avoid;
  cursor: pointer;
  font-size: 13px;
}
.design-row:hover { background: #faf7f2; }
.design-row.selected { background: var(--used-bg); }
.design-row .row-thumb {
  width: 22px; height: 22px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.design-row .row-thumb-empty {
  width: 22px; height: 22px;
  border-radius: 5px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: #f6f5f3;
}
.design-row .row-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Плитка ---------- */
#designs-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}
.tile {
  aspect-ratio: 1;
  border-radius: 8px;
  background: #f6f5f3;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.tile .tile-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  font-size: 10px; padding: 2px 4px;
  background: rgba(255,255,255,0.85);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Цвета скрепок ---------- */
.clip-color-purple { border-color: #7F77DD !important; }
.clip-color-teal { border-color: #1D9E75 !important; }
.clip-color-coral { border-color: #D85A30 !important; }
.clip-color-pink { border-color: #D4537E !important; }
.clip-color-blue { border-color: #378ADD !important; }
.clip-color-green { border-color: #639922 !important; }
.clip-color-amber { border-color: #BA7517 !important; }
.clip-color-red { border-color: #E24B4A !important; }
.clip-color-gray { border-color: #888780 !important; }
.clip-color-dark { border-color: #2C2C2A !important; }

.color-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-block;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected { border-color: var(--text); }
.color-swatches { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.clip-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.main-columns {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 16px 20px;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#left-panel { flex: 1.4; }
#right-panel { flex: 1; }

.panel h2 {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.filter-row {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 13px;
  align-items: center;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: #f1efec; }
button.danger { background: var(--danger); }
button.danger:hover { background: #96382f; }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
thead th {
  text-align: left;
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  color: var(--muted);
  font-weight: 600;
}
tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid #f0eee9;
}
tbody tr.used { background: var(--used-bg); }
.thumb {
  width: 32px; height: 32px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  border: 1px solid var(--border);
  background: #f1efe8;
}
.thumb-placeholder {
  width: 32px; height: 32px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  background: #f6f5f3;
}
.thumb-large {
  width: 140px; height: 140px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 10px;
}
tbody tr:hover { background: #faf7f2; }
tbody tr.selected { outline: 2px solid var(--accent); outline-offset: -2px; }

#designs-table-wrap, #clip-contents-wrap, #clips-list-wrap {
  overflow: auto;
  flex: 1;
}

#clips-list-wrap { flex: 0 0 auto; max-height: 220px; margin-bottom: 12px; }

.clip-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 4px;
}
.clip-item:hover { background: #faf7f2; }
.clip-item.selected { background: var(--used-bg); font-weight: 600; }

.clip-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px;
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow: auto;
}
.modal h3 { margin-top: 0; }
.modal textarea, .modal input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 10px;
}
.modal textarea { min-height: 140px; font-family: monospace; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.status-msg {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  min-height: 16px;
}

pre.log {
  font-size: 12px;
  white-space: pre-wrap;
  font-family: monospace;
}
