/* View-specific styling: login, item grid, command palette, projects, editors, viewer. */

/* ---------------------------------------------------------------------------- login */
#login-view {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 388px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 30px 28px 26px;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--t-slow) var(--ease-out);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

/* The lockup ships in two tones: navy for light backgrounds, lifted for dark ones.
   Both are in the markup and CSS picks one, so the swap is instant when the theme
   toggles - no reload, no flash of the wrong one. */
.login-logo {
  width: min(210px, 62%);
  height: auto;
  display: none;
}

:root[data-theme="light"] .login-logo-light { display: block; }
:root:not([data-theme="light"]) .login-logo-dark { display: block; }

.login-otp {
  letter-spacing: 0.44em;
  text-align: center;
  font-size: var(--text-lg);
  font-weight: 600;
  font-family: var(--font-mono);
  padding-left: 0.44em;    /* compensates the trailing letter-space so digits look centred */
}

.login-foot {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-faint);
  line-height: 1.6;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid transparent;
}

.alert-info { background: var(--accent-soft); color: var(--accent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-success { background: var(--success-soft); color: var(--success); }

/* ------------------------------------------------------------------------- item grid */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: 12px;
}

@media (max-width: 560px) {
  .item-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}

.item-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--t-fast), transform var(--t-fast) var(--ease),
              box-shadow var(--t-fast);
}

.item-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.item-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* A 3px colour rail at the top of each card encodes the item type, so a mixed grid is
   scannable at a glance before any label is read. */
.item-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--type-color, var(--accent));
  opacity: 0.9;
}

.item-thumb {
  aspect-ratio: 16 / 10;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-thumb .type-glyph {
  color: var(--type-color, var(--text-faint));
  opacity: 0.55;
}

.item-thumb-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

.item-meta {
  padding: 10px 11px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.item-title {
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.item-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--text-faint);
  min-width: 0;
}

.item-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.item-card:hover .item-actions,
.item-card:focus-within .item-actions { opacity: 1; }

.item-actions .icon-btn {
  width: 28px;
  height: 28px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
}

.item-star {
  position: absolute;
  top: 8px;
  left: 8px;
  color: var(--warning);
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

/* Touch devices have no hover, so the action affordances stay visible. */
@media (hover: none) {
  .item-actions { opacity: 1; }
}

/* ------------------------------------------------------------------------- item list */
.item-list {
  display: flex;
  flex-direction: column;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background var(--t-fast);
}

.item-row:last-child { border-bottom: none; }
.item-row:hover { background: var(--surface-hover); }
.item-row.selected { background: var(--accent-soft); }

.item-row-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--type-color, var(--text-faint));
  flex: none;
  overflow: hidden;
}

.item-row-icon img { width: 100%; height: 100%; object-fit: cover; }

.item-row-main { flex: 1; min-width: 0; }

.item-row-title {
  font-size: var(--text-base);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-row-side {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  .item-row-side .hide-sm { display: none; }
}

/* ------------------------------------------------------------- selection action bar */
.selection-bar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  translate: -50% 0;
  z-index: calc(var(--z-sticky) + 2);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(180%);
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--t-base) var(--ease-out);
  max-width: calc(100vw - 32px);
  overflow-x: auto;
}

@media (max-width: 900px) {
  .selection-bar { bottom: calc(var(--bottomnav-h) + 16px); }
}

/* ------------------------------------------------------------------- command palette */
.palette-overlay {
  align-items: flex-start;
  padding-top: min(14vh, 120px);
}

.palette {
  width: 100%;
  max-width: 620px;
  max-height: min(68vh, 560px);
  display: flex;
  flex-direction: column;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in var(--t-base) var(--ease-out);
}

.palette-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.palette-input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: var(--text-md);
  color: var(--text);
  min-width: 0;
}

.palette-input::placeholder { color: var(--text-faint); }

.palette-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
}

.palette-group-label {
  padding: 8px 10px 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.palette-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  text-align: left;
  color: var(--text-dim);
  transition: background var(--t-fast);
}

.palette-row:hover,
.palette-row.active {
  background: var(--surface-hover);
  color: var(--text);
}

.palette-row.active { background: var(--accent-soft); }

.palette-row-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--r-xs);
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--type-color, var(--text-faint));
  flex: none;
}

.palette-row-main { flex: 1; min-width: 0; }

.palette-snippet {
  font-size: var(--text-xs);
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-snippet mark {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 2px;
}

.palette-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: var(--text-xs);
  color: var(--text-faint);
  flex: none;
}

/* ------------------------------------------------------------------------ type picker */
.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 9px;
}

.type-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 8px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: var(--text-sm);
  font-weight: 550;
  transition: border-color var(--t-fast), transform var(--t-fast) var(--ease),
              background var(--t-fast), color var(--t-fast);
}

.type-tile:hover {
  border-color: var(--type-color, var(--accent));
  color: var(--text);
  transform: translateY(-2px);
}

.type-tile-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--type-color, var(--accent)) 16%, transparent);
  color: var(--type-color, var(--accent));
}

/* --------------------------------------------------------------------------- dropzone */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: 26px 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-sm);
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
  cursor: pointer;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* Full-window drop target, shown only while a file is dragged over the app. */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.drop-overlay-inner {
  padding: 40px 56px;
  border-radius: var(--r-xl);
  border: 2px dashed var(--accent);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-lg);
  font-weight: 600;
  text-align: center;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: var(--text-sm);
}

.progress-track {
  flex: 1;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width 150ms linear;
}

/* --------------------------------------------------------------------------- viewer */
.viewer-stage {
  display: grid;
  place-items: center;
  background: #06070a;
  min-height: 300px;
  max-height: 70vh;
  overflow: auto;
  padding: 10px;
}

.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 68vh;
  display: block;
  border-radius: var(--r-sm);
}

.viewer-text {
  margin: 0;
  padding: 16px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-size: var(--text-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow: auto;
}

.kv {
  display: grid;
  grid-template-columns: minmax(110px, max-content) minmax(0, 1fr);
  gap: 8px 14px;
  font-size: var(--text-sm);
  align-items: baseline;
}

.kv dt { color: var(--text-faint); }
.kv dd { margin: 0; word-break: break-word; }

.secret-field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  min-width: 0;
}

.secret-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
}

.secret-value.masked {
  letter-spacing: 0.18em;
  user-select: none;
  color: var(--text-faint);
}

.pw-strength {
  height: 4px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}

.pw-strength i {
  display: block;
  height: 100%;
  border-radius: var(--r-full);
  transition: width var(--t-base) var(--ease), background var(--t-base);
}

/* -------------------------------------------------------------------------- projects */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--t-fast), transform var(--t-fast) var(--ease);
}

.project-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.project-card.offline { opacity: 0.62; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--text-faint);
  min-width: 0;
}

.breadcrumb button {
  padding: 3px 7px;
  border-radius: var(--r-xs);
  color: var(--text-dim);
  transition: background var(--t-fast), color var(--t-fast);
}

.breadcrumb button:hover { background: var(--surface-hover); color: var(--text); }
.breadcrumb .sep { opacity: 0.5; }
.breadcrumb .crumb-current { font-weight: 600; color: var(--text); padding: 3px 7px; }

.icon-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 190px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  align-content: flex-start;
}

.icon-chip {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: left;
  transition: background var(--t-fast);
}

.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--surface-hover); }

.file-row .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
}

.file-row .size {
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.file-row .row-actions {
  display: flex;
  gap: 2px;
  flex: none;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.file-row:hover .row-actions,
.file-row:focus-within .row-actions { opacity: 1; }

@media (hover: none) {
  .file-row .row-actions { opacity: 1; }
}

/* ------------------------------------------------------------------------ AI assistant */
.ai-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.ai-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 2px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
}

.ai-msg .bubble {
  padding: 10px 13px;
  border-radius: var(--r-md);
  font-size: var(--text-base);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
}

.ai-msg.user { flex-direction: row-reverse; }

/* An assistant turn can carry a bubble plus sources plus a list of changes; stacking
   them keeps each one full width instead of strung out along a row. */
.ai-msg.assistant {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.ai-msg.user .bubble {
  background: var(--accent);
  color: var(--text-on-brand);
  border-bottom-right-radius: var(--r-xs);
}

.ai-msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--r-xs);
  box-shadow: var(--shadow-sm);
}

/* What the assistant changed, reported under its reply. */
.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.ai-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  border: 1px solid transparent;
  background: var(--success-soft);
  color: var(--success);
  font-size: var(--text-xs);
  font-weight: 600;
}

.ai-action.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.ai-action.clickable { cursor: pointer; }
.ai-action.clickable:hover { border-color: currentColor; }

.ai-cite {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  margin: 0 2px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  vertical-align: baseline;
}

.ai-cite:hover { background: var(--accent); color: #fff; }

.ai-compose {
  flex: none;
  display: flex;
  /* Кнопок ліворуч три, а на телефоні ще й поле вводу — проміжок менший, ніж був,
     інакше на вузькому екрані вводити стає нікуди. */
  gap: 4px;
  align-items: flex-end;
  padding: 7px 7px 7px 6px;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.ai-compose:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring), var(--shadow-md);
}

.ai-compose textarea {
  flex: 1;
  min-height: 38px;
  max-height: 140px;
  resize: none;
  border: none;
  background: transparent;
  padding: 9px 10px;
}

.ai-compose textarea:focus {
  outline: none;
  border: none;
  background: transparent;
  box-shadow: none;
}

.ai-compose .btn {
  height: 38px;
  width: 42px;
  padding: 0;
  border-radius: var(--r-lg);
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

/* Shown while the conversation is empty: centred in the card, so the panel reads as an
   invitation rather than as a blank area above an input. */
.ai-empty {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  max-width: 460px;
  text-align: center;
}

.ai-empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--r-lg);
  background: var(--accent-soft);
  color: var(--accent);
}

.ai-empty-text {
  font-size: var(--text-md);
  font-weight: 550;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------------- dashboard */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 14px 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 11px;
}

.section-head h2 {
  font-size: var(--text-md);
  font-weight: 650;
}

/* ------------------------------------------------------------------- sheet editor */
.sheet-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--surface);
}

.sheet-table {
  border-collapse: collapse;
  font-size: var(--text-sm);
  table-layout: fixed;
}

.sheet-table th,
.sheet-table td {
  border: 1px solid var(--border);
  padding: 0;
  height: 30px;
  min-width: 108px;
  max-width: 108px;
  position: relative;
}

.sheet-table thead th,
.sheet-table tbody th {
  background: var(--surface-2);
  color: var(--text-faint);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
  min-width: 42px;
  max-width: 42px;
  position: sticky;
  z-index: 2;
  user-select: none;
}

.sheet-table thead th { top: 0; }
.sheet-table tbody th { left: 0; z-index: 1; }
.sheet-table thead th:first-child { left: 0; z-index: 3; }

.sheet-cell {
  width: 100%;
  height: 100%;
  padding: 4px 6px;
  border: none;
  background: none;
  outline: none;
  font: inherit;
  color: var(--text);
}

.sheet-cell:focus {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--surface-2);
}

.sheet-cell.computed { color: var(--success); font-variant-numeric: tabular-nums; }
.sheet-cell.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------- paint editor */
.paint-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.paint-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex: none;
}

.paint-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  /* Checkerboard so a transparent canvas is visibly transparent. */
  background-color: var(--surface-3);
  background-image:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%),
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}

#paint-canvas {
  background: #ffffff;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  cursor: crosshair;
  touch-action: none;       /* required, or a stylus/finger pans instead of drawing */
  max-width: 100%;
}

.swatches {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: var(--r-xs);
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px var(--border-strong);
  transition: transform var(--t-fast);
}

.swatch:hover { transform: scale(1.12); }
.swatch.active { border-color: var(--text); }

.tool-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  color: var(--text-dim);
  transition: background var(--t-fast), color var(--t-fast);
}

.tool-btn:hover { background: var(--surface-hover); color: var(--text); }

.tool-btn.active {
  background: var(--accent);
  color: #fff;
}

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 92px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  outline: none;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
}

.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
}

/* ------------------------------------------------------------------------ note editor */
.note-editor {
  flex: 1;
  min-height: 320px;
  border: none;
  background: none;
  outline: none;
  resize: none;
  font-size: var(--text-md);
  line-height: 1.7;
  padding: 4px 2px;
  font-family: var(--font);
}

.note-editor.mono { font-family: var(--font-mono); font-size: var(--text-sm); }

.editor-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-xs);
  color: var(--text-faint);
}

/* --------------------------------------------------------------------------- home */
/* Quick-add on top, the conversation underneath. Both are centred on one column so the
   page has a single focal point instead of a grid of competing widgets. */
.home {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  overflow: hidden;
  padding: 18px 20px 20px;
}

.home-inner {
  width: 100%;
  max-width: 880px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 14px;
}

.home-greeting {
  text-align: center;
  flex: none;
}

.home-greeting h1 {
  font-size: var(--text-2xl);
  letter-spacing: -0.03em;
}

.home-greeting p {
  margin-top: 4px;
  font-size: var(--text-sm);
  color: var(--text-faint);
}

.home-quick {
  flex: none;
  display: grid;
  grid-template-rows: auto 1fr;
  transition: grid-template-rows var(--t-base) var(--ease), opacity var(--t-base);
}

.home-quick.collapsed { grid-template-rows: auto 0fr; }

.home-quick-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-bottom: 2px;
}

.home-quick-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  cursor: pointer;
}

.home-quick-toggle {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--r-xs);
  color: var(--text-faint);
  transition: background var(--t-fast), color var(--t-fast);
}

.home-quick-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.home-quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  /* Clipping is what makes the collapse animate (the row goes to 0fr), but it also cut
     off a tile's 2px hover lift and its focus ring. The inset gives them room; with
     border-box it is squeezed away along with the content when the row closes. */
  padding: 6px;
  overflow: hidden;
  min-height: 0;
}

.home-quick .type-tile {
  padding: 13px 6px;
  gap: 6px;
  font-size: var(--text-xs);
}

.home-quick .type-tile-icon {
  width: 32px;
  height: 32px;
}

.home-chat {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.home-chat .ai-panel { flex: 1; min-width: 0; }
.home-chat .empty { flex: 1; }

@media (max-width: 900px) {
  .home {
    padding: 12px 14px calc(var(--bottomnav-h) + 14px);
  }

  .home-greeting h1 { font-size: var(--text-xl); }
  .home-greeting p { display: none; }

  .home-quick-grid {
    grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
    gap: 6px;
    padding: 5px;
  }

  .home-quick .type-tile { padding: 11px 4px; }
  .home-quick .type-tile-icon { width: 28px; height: 28px; }
}

/* --------------------------------------------------------------------------- guide */
.guide-head {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  max-width: 820px;
}

.guide-sections {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 820px;
}

.guide-section {
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.guide-section > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  cursor: pointer;
  font-size: var(--text-md);
  font-weight: 600;
  list-style: none;
  transition: background var(--t-fast);
}

.guide-section > summary::-webkit-details-marker { display: none; }
.guide-section > summary:hover { background: var(--surface-hover); }

.guide-section-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
  flex: none;
}

/* The chevron is drawn in CSS so the section header needs no extra markup. */
.guide-section > summary::after {
  content: "";
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-right: 1.8px solid var(--text-faint);
  border-bottom: 1.8px solid var(--text-faint);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform var(--t-fast) var(--ease);
}

.guide-section[open] > summary::after {
  transform: rotate(-135deg) translate(-2px, -2px);
}

.guide-body {
  padding: 2px 18px 18px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--text-dim);
}

.guide-body p { margin-bottom: 10px; }
.guide-body p:last-child { margin-bottom: 0; }
.guide-body strong { color: var(--text); font-weight: 600; }

.guide-sub {
  margin: 16px 0 8px;
  font-size: var(--text-base);
  font-weight: 650;
  color: var(--text);
}

.guide-sub:first-child { margin-top: 0; }

.guide-list {
  margin: 0 0 10px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.guide-list li { padding-left: 2px; }

.guide-code {
  padding: 1px 6px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.88em;
  white-space: nowrap;
}

/* Text stand-in for items with no picture: the opening lines of a note or sheet, faded
   out at the bottom so it reads as an excerpt rather than as truncated content. */
.item-preview {
  display: block;
  width: 100%;
  height: 100%;
  padding: 11px 12px;
  overflow: hidden;
  font-size: 11.5px;
  line-height: 1.5;
  text-align: left;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-mask-image: linear-gradient(to bottom, #000 58%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 58%, transparent 100%);
}

.item-card:hover .item-preview { color: var(--text); }


/* ---------------------------------------------------- files dropped into the chat */
.ai-panel { position: relative; }

.ai-compose .icon-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
}

/* На вузькому екрані три кнопки ліворуч з'їдають поле вводу — стискаємо їх, але
   лишаємо всі: ховати «новий діалог» саме там, де історія найдовша, безглуздо. */
@media (max-width: 520px) {
  .ai-compose .icon-btn { width: 30px; height: 30px; }
}

/* Only shown mid-drag, so it sits above the log rather than reserving space. */
.ai-drop {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 82%, var(--accent));
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
  z-index: 3;
}

.ai-panel.dragging .ai-drop { display: flex; }


/* Кнопка переходу в проєкт під відповіддю помічника. */
.ai-open-project {
  align-self: flex-start;
  margin-top: 8px;
}

/* ------------------------------------------------ затримана підказка */

.hover-card {
  position: fixed;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 340px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: var(--text-xs);
  line-height: 1.45;
  /* Підказка не має перехоплювати мишу: інакше курсор «наїжджає» на неї, елемент
     під нею втрачає наведення, і вона миттєво зникає сама від себе. */
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.hover-card.visible { opacity: 1; }
.hover-card strong { font-size: var(--text-sm); }
.hover-card-path { color: var(--text-faint); word-break: break-all; }
.hover-card-warn { color: var(--danger); }

/* Заголовок, якому дозволено переноситися: у проєктів назви довгі, і побачити її
   цілком важливіше, ніж утримати шапку в один рядок. */
.content-title.title-wrap h1 {
  white-space: normal;
  overflow: visible;
  line-height: 1.25;
}

/* Олівець на картці проєкту: з'являється при наведенні, щоб не шуміти в списку. */
.project-card { position: relative; }

.project-edit {
  position: absolute;
  /* Унизу праворуч, а не вгорі: вгорі стоїть індикатор зв'язку, і олівець накрив би
     саме те, заради чого на картку дивляться. Унизу він перекриває лише підпис
     статусу, а сам статус видно за крапкою. */
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: var(--text-faint);
  background: var(--surface);
  opacity: 0;
  cursor: pointer;
  transition: opacity var(--t-fast), color var(--t-fast);
}

.project-card:hover .project-edit,
.project-edit:focus-visible { opacity: 1; }
.project-edit:hover { color: var(--accent); }

@media (hover: none) {
  .project-edit { opacity: 1; }
}

/* ------------------------------------- машина з проєктами не на зв'язку */

/* Плашка в бічній панелі. Видно завжди, поки хоч одна машина мовчить: обрив, який
   помічають лише відкривши проєкт, помічають запізно. */
.agent-health {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 9px 11px;
  margin-bottom: 8px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 84%, var(--danger));
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast);
}

.agent-health:hover { background: color-mix(in srgb, var(--surface) 72%, var(--danger)); }

.agent-health-head {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--danger);
  font-size: var(--text-xs);
  font-weight: 600;
}

.agent-health-body {
  font-size: var(--text-xs);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Смуга над списком файлів усередині недоступного проєкту. */
.offline-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 84%, var(--danger));
  color: var(--danger);
  font-size: var(--text-sm);
}

.file-row.row-offline .name,
.file-row.row-offline .size { opacity: 0.55; }

/* .btn:disabled уже описано в components.css; тут лише іконкові кнопки. */
.icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ------------------------------------------- попередження про паролі у файлі */
.secret-warning {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--warning);
  border-radius: 12px;
  background: var(--warning-soft);
}

.secret-warning-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--warning);
}

.secret-warning-head h4 { margin: 0; font-size: 15px; }
.secret-warning p { margin: 0; color: var(--text-muted); font-size: 13px; line-height: 1.5; }

.secret-reasons {
  margin: 0;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 13px;
  word-break: break-word;
}

.secret-reasons li { margin: 2px 0; }

/* Лишається над текстом, поки файл відкритий: легко забути, що на екрані ключ. */
.secret-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 13px;
  font-weight: 600;
}

/* Кнопки попередження на вузькому екрані стають одна під одною, а не вилазять. */
@media (max-width: 480px) {
  .secret-warning .row { flex-wrap: wrap; }
  .secret-warning .row .btn { flex: 1 1 auto; justify-content: center; }
}
