/* Вёрстка UI: шапка, дерево папок, список записей и форма */

@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto-cyrillic-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto-cyrillic-500.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto-latin-500.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  font-family: "Roboto", sans-serif;
  color: #1a1a1a;
  background: #f4f4f5;
  --tab-bar-offset: max(0.75rem, env(safe-area-inset-bottom, 0px));
  --tab-bar-clearance: calc(3.75rem + var(--tab-bar-offset));
}

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

.zone-top {
  position: sticky;
  top: 0;
  z-index: 20;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: #fff;
  border-bottom: 1px solid #e4e4e7;
}

/* PWA window-controls-overlay: шапка — зона перетаскивания окна, кнопки кликабельны */
@media (display-mode: window-controls-overlay) {
  .zone-top {
    padding-top: max(0.5rem, env(titlebar-area-y, 0px));
    padding-left: max(0.75rem, env(titlebar-area-x, 0px));
    padding-right: max(
      0.75rem,
      calc(100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw))
    );
    min-height: env(titlebar-area-height, 2.75rem);
    -webkit-app-region: drag;
    app-region: drag;
  }

  .zone-top button {
    -webkit-app-region: no-drag;
    app-region: no-drag;
  }
}

.top-start {
  justify-self: start;
}

.top-end {
  justify-self: end;
}

.zone-top h1 {
  margin: 0;
  justify-self: center;
  font-size: 1.125rem;
  font-weight: 600;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
}

.icon-hamburger {
  display: block;
  width: 1.125rem;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor;
}

.icon-panel {
  display: block;
  width: 1.125rem;
  height: 0.875rem;
  border: 2px solid currentColor;
  border-radius: 2px;
  background: linear-gradient(to left, currentColor 0.35rem, transparent 0.35rem);
}

.app-layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.zone-tabs {
  position: absolute;
  left: 50%;
  bottom: var(--tab-bar-offset);
  z-index: 30;
  display: flex;
  width: max-content;
  gap: 0.375rem;
  padding: 0.375rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 1rem;
  box-shadow: 0 0.25rem 1.25rem rgb(0 0 0 / 0.14);
  transform: translateX(-50%);
}

.zone-tabs button {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: none;
  border-radius: 0.75rem;
  background: transparent;
  color: #71717a;
}

.zone-tabs button:hover {
  background: #f4f4f5;
}

.zone-tabs button.selected {
  color: #1a1a1a;
  background: #e4e4e7;
}

.tab-icon {
  display: block;
  width: 1.5rem;
  height: 1.5rem;
}

.zone-menu,
.zone-context {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: #fff;
}

.zone-menu::after,
.zone-context::after {
  content: "";
  flex: 0 0 var(--tab-bar-clearance);
  pointer-events: none;
}

.zone-menu {
  flex: 0 0 14rem;
  width: 14rem;
  max-width: 14rem;
  border-right: 1px solid #e4e4e7;
}

.zone-context {
  flex: 0 0 18rem;
  width: 18rem;
  max-width: 18rem;
  border-left: 1px solid #e4e4e7;
}

.menu-collapsed .zone-menu,
.context-collapsed .zone-context {
  display: none;
}

.zone-actions {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.menu-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  border-top: 1px solid #e4e4e7;
}

#user-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  font-size: 0.875rem;
}

#user-login {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.status {
  margin: 0;
  font-size: 0.875rem;
}

.status.error {
  color: #b91c1c;
}

.status.ok {
  color: #166534;
}

.view-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
}

.view-nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-badge {
  flex: 0 0 auto;
  min-width: 1.25rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: #16a34a;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
}

#tab-messages {
  position: relative;
}

.tab-badge {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  min-width: 1rem;
  padding: 0 0.22rem;
  font-size: 0.625rem;
  line-height: 1.15;
}

.view-nav button.selected {
  background: #e4e4e7;
  font-weight: 600;
}

.zone-actions > .status:not([hidden]) {
  flex: 0 0 auto;
  margin: 0.5rem 0.75rem;
}

#view-dashboard-pane:not([hidden]),
#view-agents-pane:not([hidden]),
#view-variables-pane:not([hidden]),
#view-foods-items-pane:not([hidden]),
#view-foods-sets-pane:not([hidden]),
#view-foods-meals-pane:not([hidden]),
#view-foods-stats-pane:not([hidden]),
#view-rules-pane:not([hidden]),
#view-skills-pane:not([hidden]),
#view-templates-pane:not([hidden]),
#view-tasks-pane:not([hidden]),
#view-events-pane:not([hidden]),
#view-actions-pane:not([hidden]),
#view-timeline-pane:not([hidden]),
#view-messages-pane:not([hidden]),
#view-relations-pane:not([hidden]),
#view-requests-pane:not([hidden]),
#view-settings-pane:not([hidden]) {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#view-variables-pane:not([hidden]),
#view-foods-items-pane:not([hidden]),
#view-foods-sets-pane:not([hidden]),
#view-foods-meals-pane:not([hidden]),
#view-foods-stats-pane:not([hidden]),
#view-rules-pane:not([hidden]),
#view-skills-pane:not([hidden]),
#view-templates-pane:not([hidden]),
#view-tasks-pane:not([hidden]),
#view-events-pane:not([hidden]),
#view-actions-pane:not([hidden]),
#view-timeline-pane:not([hidden]),
#view-messages-pane:not([hidden]),
#view-relations-pane:not([hidden]),
#view-requests-pane:not([hidden]) {
  position: relative;
}

#variables-list-pane,
#foods-items-list-pane,
#foods-sets-list-pane,
#foods-meals-list-pane,
#foods-stats-pane,
#rules-list-pane,
#skills-list-pane,
#templates-list-pane,
#tasks-list-pane,
#events-list-pane,
#actions-list-pane,
#messages-list-pane,
#relations-list-pane,
#requests-list-pane,
#agents-pane:not([hidden]),
#agent-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#agents-pane:not([hidden]),
#variables-list-pane,
#foods-items-list-pane,
#foods-sets-list-pane,
#foods-meals-list-pane,
#foods-stats-pane,
#tasks-list-pane,
#events-list-pane,
#actions-list-pane,
#messages-list-pane,
#templates-list-pane,
#rules-list-pane,
#skills-list-pane,
#relations-list-pane,
#requests-list-pane {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: hidden;
  background: #fff;
}

#agent-thread {
  flex: 1 1 auto;
  background: #fafafa;
}

#dashboard-stub {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fafafa;
}

#dashboard-stub > p {
  padding: 0.75rem;
}

#tasks-list-pane,
#messages-list-pane {
  flex: 1 1 auto;
}

.pane-head {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid #e4e4e7;
}

.pane-head h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.variables-path {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.2rem;
  min-width: 0;
  flex: 1 1 auto;
  font-size: 0.875rem;
  font-weight: 600;
}

.variables-path button {
  border-color: transparent;
  background: transparent;
  padding: 0.15rem 0.3rem;
  color: #2563eb;
}

.variables-path button:hover {
  background: #f4f4f5;
  text-decoration: underline;
}

.variable-quick-form {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid #e4e4e7;
}

.variable-quick-form[hidden] {
  display: none;
}

.variable-quick-value-wrap {
  flex: 1 1 12rem;
  min-width: 8rem;
}

.variable-quick-form textarea {
  min-height: 2.5rem;
}

.variable-quick-version-label {
  flex: 0 1 16rem;
  min-width: 12rem;
}

.variable-quick-versions {
  flex: 1 1 100%;
  min-width: 0;
  overflow: auto;
}

.variable-item-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.25rem 0;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.variable-item-name-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.variable-item-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-item-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  color: #71717a;
  white-space: nowrap;
}

.variable-item-value {
  font-variant-numeric: tabular-nums;
}

.variable-item-unit {
  flex: 0 0 auto;
}

.variable-item-description {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-size: 0.8125rem;
  color: #71717a;
  word-break: break-word;
}

.variable-item-id,
.variable-record-id {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  color: #71717a;
  word-break: break-all;
  user-select: all;
}

.variable-record-id {
  margin-bottom: 0.75rem;
}

.pane-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

button {
  font: inherit;
  padding: 0.25rem 0.5rem;
  border: 1px solid #d4d4d8;
  border-radius: 0.25rem;
  background: #fff;
  cursor: pointer;
}

button:hover {
  background: #f4f4f5;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.danger {
  color: #b91c1c;
  border-color: #fecaca;
}

.list-btn {
  display: block;
  width: 100%;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-color: transparent;
  background: transparent;
  margin: 0.125rem 0;
}

.list-btn:hover {
  background: #f4f4f5;
}

.list-btn.selected {
  background: #e4e4e7;
  font-weight: 600;
}

.list-meta {
  display: block;
  font-weight: 400;
  color: #71717a;
  font-size: 0.75rem;
}

#variables-list,
#foods-items-list,
#foods-sets-list,
#foods-meals-list,
#rules-list,
#skills-list,
#templates-list,
#tasks-list,
#events-list,
#actions-list,
#messages-list,
#relations-list,
#requests-list,
#agents-threads-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
  padding-bottom: calc(0.75rem + var(--tab-bar-clearance));
}

#ai-list,
#api-tokens-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
}

.zone-context #agents-threads-list {
  overflow-x: hidden;
  overflow-y: auto;
}

#messages {
  flex: 1 1 auto;
  overflow: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bubble {
  max-width: 48rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9375rem;
  line-height: 1.4;
}

.bubble.user {
  align-self: flex-end;
  background: #e0e7ff;
}

.bubble.assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e4e4e7;
}

.bubble.tool {
  align-self: flex-start;
  background: #f4f4f5;
  color: #52525b;
  font-size: 0.8125rem;
  max-width: 100%;
}

.bubble .role {
  display: block;
  font-size: 0.75rem;
  color: #71717a;
  margin-bottom: 0.25rem;
}

.tool-calls {
  margin-top: 0.35rem;
  color: #52525b;
  font-size: 0.8125rem;
}

.agent-status {
  padding: 0 0.75rem 0.25rem;
}

#composer {
  flex: 0 0 auto;
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  padding-bottom: calc(0.75rem + var(--tab-bar-clearance));
  background: #fff;
  border-top: 1px solid #e4e4e7;
}

#composer textarea {
  flex: 1 1 auto;
  min-height: 3rem;
  resize: vertical;
}

.composer-templates-wrap {
  position: relative;
  flex: 0 0 auto;
  align-self: flex-end;
}

#composer-templates-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  z-index: 20;
  min-width: 12rem;
  max-height: 16rem;
  margin-bottom: 0.25rem;
  overflow: auto;
  background: #fff;
  border: 1px solid #e4e4e7;
}

#composer-templates-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
  border: none;
  border-radius: 0;
  background: transparent;
}

#composer-templates-menu button:hover {
  background: #e4e4e7;
}

#composer-templates-menu p {
  margin: 0;
  padding: 0.5rem 0.75rem;
}

#rule-text,
#skill-text,
#template-text {
  min-height: 16rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
}

#request-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
}

#request-data,
#task-input,
#task-output {
  min-height: 8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
}

#rule-form h3,
#skill-form h3,
#variable-form h3,
#task-form h3,
#relation-form h3,
#request-form h3,
#ai-form h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

#task-editor:not([hidden]),
#event-editor:not([hidden]),
#action-editor:not([hidden]),
#message-editor:not([hidden]),
#template-editor:not([hidden]),
#variable-editor:not([hidden]),
#foods-items-editor:not([hidden]),
#foods-sets-editor:not([hidden]),
#foods-meals-editor:not([hidden]),
#rule-editor:not([hidden]),
#skill-editor:not([hidden]),
#relation-editor:not([hidden]),
#request-editor:not([hidden]) {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  max-height: min(85%, 40rem);
  overflow: hidden;
  background: #fff;
  border-bottom: 1px solid #e4e4e7;
  box-shadow: 0 0.75rem 1.5rem rgb(0 0 0 / 0.12);
  animation: task-editor-in 0.2s ease;
}

#action-editor:not([hidden]) {
  z-index: 6;
}

#variable-editor:not([hidden]),
#foods-items-editor:not([hidden]),
#foods-sets-editor:not([hidden]) {
  max-height: min(90%, 52rem);
}

#foods-meals-editor:not([hidden]) {
  top: 0;
  bottom: 0;
  height: 100%;
  max-height: none;
}

@keyframes task-editor-in {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

.task-editor-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid #e4e4e7;
}

.task-editor-head h3 {
  margin: 0;
  font-size: 1rem;
}

#task-form,
#event-form,
#action-form,
#message-form,
#template-form,
#variable-form,
#foods-items-form,
#foods-sets-form,
#foods-meals-form,
#rule-form,
#skill-form,
#relation-form,
#request-form {
  overflow: auto;
  padding: 0.75rem;
}

#variable-form {
  flex: 1 1 auto;
  min-height: 0;
}

#foods-items-form,
#foods-sets-form {
  flex: 1 1 auto;
  min-height: 0;
}

#foods-meals-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#foods-meals-add-food {
  flex: 0 0 auto;
}

#foods-meals-items {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.foods-sets-items {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0;
}

.foods-sets-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.foods-meals-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.foods-meals-item-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.foods-meals-item-amount {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.foods-meals-item-amount input {
  width: 5rem;
}

#foods-stats-pane {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#foods-stats-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 0 0 1rem;
}

.foods-stats-date-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.foods-stats-date-nav input[type="date"] {
  min-width: 9rem;
}

.foods-stats-block-title {
  margin: 0 0 0.5rem;
  font-size: 0.9375rem;
  font-weight: 500;
}

.foods-stats-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.foods-stats-row {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e4e4e7;
  background: #fff;
  font-size: 0.875rem;
  overflow: hidden;
}

.foods-stats-row-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: #2563eb;
  opacity: 0.2;
  pointer-events: none;
  z-index: 0;
}

.foods-stats-row-has-norm::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  border-left: 1px solid #94a3b8;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
}

.foods-stats-row-name,
.foods-stats-row-value {
  position: relative;
  z-index: 2;
}

.foods-stats-row-name {
  flex: 1 1 auto;
  min-width: 0;
}

.foods-stats-row-value {
  flex: 0 0 auto;
  text-align: right;
  white-space: nowrap;
}

.foods-meals-item-unit {
  min-width: 1.5rem;
}

#variable-versions-block {
  flex: 0 1 16rem;
  min-height: 8rem;
  overflow: auto;
  padding: 0.75rem;
  border-top: 1px solid #e4e4e7;
}

#variable-versions-block[hidden] {
  display: none;
}

#variable-versions-block h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.rules-table,
.skills-table,
.templates-table,
.relations-table,
.requests-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.rules-table th,
.rules-table td,
.skills-table th,
.skills-table td,
.templates-table th,
.templates-table td,
.relations-table th,
.relations-table td,
.requests-table th,
.requests-table td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid #e4e4e7;
  text-align: left;
  vertical-align: top;
}

.rules-table button,
.skills-table button,
.templates-table button,
.relations-table button,
.requests-table button {
  width: 100%;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.task-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  padding: 0.75rem;
  text-align: left;
  border: 1px solid #e4e4e7;
  background: #fff;
  cursor: pointer;
}

.task-item.selected {
  background: #e4e4e7;
}

.task-item-main {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.task-item-heading {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}

.task-item-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 500;
  word-break: break-word;
}

.task-status-dots {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex: 0 0 auto;
  margin-top: 0.4em;
}

.task-status-dot {
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}

.task-status-dot-completed {
  background: #2563eb;
}

.task-status-dot-overdue {
  background: #dc2626;
}

.task-status-dot-inactive {
  background: #a1a1aa;
}

.task-status-dot-active {
  background: #16a34a;
}

.task-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.8125rem;
  color: #71717a;
}

.task-item-linked-actions {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding-left: 1.25rem;
}

.task-item-linked-action {
  font-size: 0.8125rem;
  color: #71717a;
  word-break: break-word;
  cursor: pointer;
}

.task-item-linked-action:hover,
#task-linked-actions-list .task-linked-action-row:hover {
  color: #18181b;
}

#task-linked-actions-list .task-linked-action-row {
  cursor: pointer;
}

.task-day-group {
  font-size: 0.75rem;
  font-weight: 600;
  color: #52525b;
  padding: 0.25rem 0.25rem 0;
}

.task-day-group-divider {
  border-top: 3px solid #18181b;
  margin-top: 0.25rem;
  padding-top: 0.75rem;
}

#task-relations,
#event-relations,
#action-relations,
#task-linked-actions,
#task-checklists {
  margin: 1rem 0 0;
}

#task-relations h4,
#event-relations h4,
#action-relations h4,
#task-linked-actions h4,
#task-checklists h4 {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
}

#task-relations-list > .muted,
#event-relations-list > .muted,
#action-relations-list > .muted,
#task-linked-actions-list > .muted {
  margin: 0.25rem 0 0;
}

.task-checklists-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.task-checklist-item-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.task-checklist-item-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 auto;
  margin: 0;
}

.task-checklist-item-row input[type="checkbox"] {
  flex: 0 0 auto;
}

.task-checklist-item-row input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
}

.task-checklist-item-meta {
  flex: 0 0 auto;
  font-size: 0.75rem;
}

.task-checklist-add {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.task-checklist-add label {
  flex: 1 1 12rem;
  margin: 0;
}

#task-relations-list td:last-child,
#event-relations-list td:last-child,
#action-relations-list td:last-child {
  white-space: nowrap;
  width: 1%;
}

.task-item .task-actions {
  position: relative;
  flex: 0 0 auto;
}

.task-item .task-actions-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.15rem;
}

.task-item .task-actions .icon-btn {
  width: 2rem;
  height: 2rem;
}

.icon-check {
  display: block;
  width: 0.55rem;
  height: 0.3rem;
  margin-bottom: 0.15rem;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.icon-play {
  display: block;
  width: 0;
  height: 0;
  margin-left: 0.1rem;
  border-style: solid;
  border-width: 0.32rem 0 0.32rem 0.5rem;
  border-color: transparent transparent transparent currentColor;
}

.icon-dots {
  display: block;
  width: 0.25rem;
  height: 0.25rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: -0.4rem 0 0 currentColor, 0.4rem 0 0 currentColor;
}

.icon-repeat {
  display: block;
  width: 0.875rem;
  height: 0.875rem;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  position: relative;
}

.icon-repeat::after {
  content: "";
  position: absolute;
  top: -0.2rem;
  right: -0.05rem;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 0.28rem 0.38rem;
  border-color: transparent transparent transparent currentColor;
  transform: rotate(-35deg);
}

.task-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.15rem);
  z-index: 6;
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 12rem;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 0.25rem;
  box-shadow: 0 0.5rem 1rem rgb(0 0 0 / 0.12);
}

.task-menu:not([hidden]) {
  display: flex;
}

.task-item .task-actions-row button {
  width: auto;
  text-align: center;
}

.task-menu button {
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.rules-table tr.selected,
.skills-table tr.selected,
.templates-table tr.selected,
.relations-table tr.selected,
.requests-table tr.selected {
  background: #e4e4e7;
}

#tasks-list,
#events-list,
#actions-list,
#messages-list,
#templates-list,
#variables-list,
#foods-items-list,
#foods-sets-list,
#foods-meals-list,
#rules-list,
#skills-list,
#relations-list,
#requests-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  padding: 0.75rem;
  text-align: left;
  border: 1px solid #e4e4e7;
  background: #fff;
}

.message-item.selected {
  background: #e4e4e7;
}

.message-item.unread .message-item-sender {
  font-weight: 600;
}

.message-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  font-size: 0.8125rem;
  cursor: pointer;
}

.message-item-sender {
  flex: 1 1 auto;
  min-width: 0;
}

.message-item-time,
.message-item-status {
  color: #71717a;
  flex: 0 0 auto;
}

.message-item-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.message-item-heading {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.message-unread-dot {
  flex: 0 0 auto;
  width: 0.5rem;
  height: 0.5rem;
  margin-top: 0.35em;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #16a34a;
  cursor: pointer;
}

.message-item-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 500;
}

.message-item-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

#message-reader {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
}

#message-reader-sender {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  color: #71717a;
}

#message-reader-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 500;
}

#message-reader-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.875rem;
}

.muted {
  margin: 0;
  color: #71717a;
  font-size: 0.875rem;
}

.variable-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.75rem;
  text-align: left;
  border: 1px solid #e4e4e7;
  background: #fff;
}

.variable-item.selected {
  background: #e4e4e7;
}

.variable-item .task-item-name {
  flex: 1 1 auto;
  min-width: 0;
}

.var-type-icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.25rem;
  color: #52525b;
}

.var-icon {
  display: block;
  width: 1.125rem;
  height: 1.125rem;
}

.variable-item .icon-btn {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  margin-top: 0.125rem;
}

.entries-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.entries-table th,
.entries-table td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid #e4e4e7;
  text-align: left;
  vertical-align: top;
}

.entries-table button {
  width: 100%;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.entries-table tr.selected {
  background: #e4e4e7;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.75rem;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

.form-grid-divider {
  grid-column: 1 / -1;
  border: none;
  border-top: 1px solid #e4e4e7;
  margin: 0.25rem 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
}

input,
select,
textarea {
  font: inherit;
  padding: 0.375rem 0.5rem;
  border: 1px solid #d4d4d8;
  border-radius: 0.25rem;
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

fieldset.flags {
  margin: 0.75rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e4e4e7;
  border-radius: 0.25rem;
}

fieldset.flags label {
  flex-direction: row;
  align-items: center;
  margin: 0.25rem 0;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.variable-versions {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.variable-versions th,
.variable-versions td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid #e4e4e7;
  text-align: left;
  vertical-align: top;
}

.variable-versions td {
  white-space: pre-wrap;
  word-break: break-word;
}

dialog {
  border: 1px solid #e4e4e7;
  border-radius: 0.5rem;
  padding: 1rem;
  min-width: 18rem;
}

#action-dialog {
  min-width: 24rem;
}

.datetime-with-now,
.field-with-button {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.datetime-with-now input,
.field-with-button input {
  flex: 1 1 auto;
  min-width: 0;
}

.foods-items-extra {
  margin-top: 0.75rem;
}

.foods-items-extra-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.foods-items-extra-row label {
  flex: 1 1 auto;
  min-width: 0;
}

.foods-items-extra-add {
  margin-bottom: 0.75rem;
}

.foods-items-extra-add label {
  flex: 1 1 auto;
  min-width: 0;
}

.foods-items-json-import {
  margin-top: 0.75rem;
}

.foods-items-json-import textarea {
  width: 100%;
  min-height: 6rem;
  margin-top: 0.25rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.4;
}

.foods-items-json-import button {
  margin-top: 0.5rem;
}

.foods-items-catalog-search-wrap {
  position: relative;
}

.foods-items-catalog-suggest {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% - 0.25rem);
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid #d4d4d8;
  border-radius: 0.25rem;
  background: #fff;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.08);
}

.foods-items-catalog-empty {
  margin: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.875rem;
}

.foods-items-catalog-option {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  text-align: left;
  border: none;
  border-bottom: 1px solid #f4f4f5;
  background: #fff;
  cursor: pointer;
  font: inherit;
}

.foods-items-catalog-option:last-child {
  border-bottom: none;
}

.foods-items-catalog-option:hover,
.foods-items-catalog-option:focus-visible {
  background: #f4f4f5;
}

.foods-items-catalog-option-primary {
  font-size: 0.875rem;
}

.foods-items-catalog-option-secondary {
  font-size: 0.75rem;
  color: #71717a;
}

.foods-items-catalog-option-id {
  font-size: 0.75rem;
  color: #71717a;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.35);
}

dialog h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

dialog label {
  margin-bottom: 0.75rem;
}

#token-dialog-value {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  word-break: break-all;
}

label.inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#messages-list-pane > .inline {
  flex: 0 0 auto;
  padding: 0.5rem 0.75rem 0;
}

.action-minutes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 0.75rem;
}

.action-minutes button {
  min-width: 2.5rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.row-check {
  flex-direction: row;
  align-items: center;
}

#settings-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: var(--tab-bar-clearance);
}

#settings-ai {
  display: flex;
  padding: 0.75rem;
}

.settings-default {
  margin: 0 0 0.5rem;
}

.settings-default select {
  min-width: 12rem;
  max-width: 100%;
}

.settings-split {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(12rem, 16rem) 1fr;
  gap: 1rem;
}

.settings-split > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#ai-form {
  overflow: auto;
}

#settings-language,
#settings-timezone,
#settings-telegram,
#settings-tokens {
  padding: 0.75rem;
  border-top: 1px solid #e4e4e7;
}

.token-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.25rem 0;
}

@media (max-width: 48rem) {
  .zone-menu,
  .zone-context {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 10;
    box-shadow: 0 0 1.5rem rgb(0 0 0 / 0.16);
  }

  .zone-menu {
    left: 0;
  }

  .zone-context {
    right: 0;
  }

  .app-layout {
    position: relative;
  }

  .settings-split {
    grid-template-columns: 1fr;
  }
}

.timeline-date-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: #fff;
  border-bottom: 1px solid #d4d4d8;
}

.timeline-date-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 8rem;
  text-align: center;
}

.timeline-date-value {
  font-size: 0.875rem;
  font-weight: 500;
  color: #18181b;
}

.timeline-date-hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: #71717a;
}

.icon-chevron-left {
  display: block;
  width: 0.45rem;
  height: 0.45rem;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.icon-chevron-right {
  display: block;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

#timeline-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-bottom: var(--tab-bar-clearance);
  background: #e4e4e7;
}

#timeline-block {
  position: relative;
  width: 2880px;
}

#timeline-hours {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  height: 2rem;
  margin-bottom: 4px;
  background: #fff;
  border-bottom: 1px solid #d4d4d8;
}

.timeline-hour {
  box-sizing: border-box;
  flex: 0 0 120px;
  width: 120px;
  padding: 0.35rem 0.4rem;
  font-size: 0.75rem;
  color: #71717a;
  border-right: 1px solid #f4f4f5;
}

#timeline-now {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5px;
  margin-left: -2px;
  background: rgb(0 0 0 / 0.1);
  z-index: 2;
  pointer-events: none;
}

.timeline-group {
  width: 2880px;
  margin-bottom: 2px;
}

.timeline-group-title {
  position: sticky;
  left: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--timeline-view-width, 100%);
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #3f3f46;
  text-align: center;
}

.timeline-group-create {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.5rem;
  height: 1.5rem;
  border: 0;
  background: transparent;
  color: #71717a;
}

.timeline-group-create:hover {
  background: #f4f4f5;
  color: #18181b;
}

.icon-plus {
  display: block;
  position: relative;
  width: 0.7rem;
  height: 0.7rem;
}

.icon-plus::before,
.icon-plus::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.icon-plus::before {
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  margin-left: -1px;
}

.icon-plus::after {
  top: 50%;
  left: 0;
  height: 2px;
  width: 100%;
  margin-top: -1px;
}

.timeline-row {
  position: relative;
  width: 2880px;
  margin-bottom: 4px;
  padding: 4px 0;
  background: #fff;
  cursor: pointer;
}

.timeline-row-name {
  position: sticky;
  left: 0;
  z-index: 2;
  box-sizing: border-box;
  width: var(--timeline-view-width, 100%);
  min-height: 1.25rem;
  line-height: 1.25rem;
  padding: 0 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 0.8125rem;
  color: #18181b;
  pointer-events: none;
}

.timeline-row-checklist {
  margin-bottom: 2px;
  padding: 2px 0;
}

.timeline-row-checklist-name {
  padding-left: 1.5rem;
  font-size: 0.75rem;
  color: #52525b;
  text-align: left;
}

.timeline-row-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.5;
}

.timeline-row-bar-planned {
  opacity: 0.1;
}

.timeline-row-bar-task {
  background: rgb(34, 197, 94);
}

.timeline-row-bar-action {
  background: rgb(59, 130, 246);
}

.timeline-row-bar-event {
  background: rgb(168, 85, 247);
}

.timeline-row-bar-task-overdue {
  background: rgb(220, 38, 38);
}

/* Вход и OAuth: форма по центру, без панелей приложения */

body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow: auto;
}

#auth-form,
#oauth-form {
  width: min(22rem, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  border-radius: 0.5rem;
}

#auth-form h1,
#auth-form h2,
#oauth-form h1,
#oauth-form h2 {
  margin: 0;
}

#auth-form h2,
#oauth-form h2 {
  font-size: 1rem;
  font-weight: 600;
}

#auth-error,
#oauth-error {
  margin: 0;
  font-size: 0.875rem;
  color: #b91c1c;
}

.oauth-actions {
  display: flex;
  gap: 0.5rem;
}

.oauth-actions button {
  flex: 1;
}

#oauth-client,
#oauth-account {
  margin: 0;
  font-size: 0.875rem;
}

@media (display-mode: standalone), (display-mode: window-controls-overlay) {
  body.auth-page {
    -webkit-app-region: drag;
    app-region: drag;
  }

  body.auth-page form,
  body.auth-page button,
  body.auth-page input {
    -webkit-app-region: no-drag;
    app-region: no-drag;
  }
}
