:root {
    --bg: #1a1a1a;
    --card: #2d2d2d;
    --text: #ffffff;
    --muted: #b3b3b3;
    --accent: #007acc;
    --danger: #ff6a7a;
    --ok: #7dffa3;
    --border: #404040
}

* {
    box-sizing: border-box
}

html,
body {
    height: 100%;
    overflow-x: hidden;
    touch-action: pan-y;
}

html {
    position: fixed;
    width: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif
}

header {
    position: sticky;
    top: 0;
    background: rgba(26, 26, 26, .9);
    backdrop-filter: saturate(140%) blur(8px);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
}

header h1 {
    margin: 0;
    font-size: 18px;
    letter-spacing: .3px
}

nav {
    display: flex;
    gap: 8px
}

.tab {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer
}

.tab.active {
    border-color: var(--accent);
    color: var(--accent)
}

.tab:disabled {
    opacity: .5;
    cursor: not-allowed
}

main {
    padding: 12px;
    max-width: 720px;
    margin: 0 auto
}

.view.hidden {
    display: none
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .3)
}

.card h2 {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: var(--text);
    font-weight: 600;
}

label {
    display: block;
    margin: 6px 0;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600
}

input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #404040;
    color: var(--text);
    font-size: 16px
}

button {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #ffffff;
    font-size: 16px;
    cursor: pointer;
    margin-top: 8px;
    font-weight: 600;
    transition: all 0.2s ease;
}

button:hover:not(:disabled) {
    background: #0088dd;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 122, 204, 0.3);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:focus {
    outline: none;
}

button:focus:not(:focus-visible) {
    outline: none;
}

button.secondary:focus {
    outline: none;
    box-shadow: none;
}

button.secondary:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

.tab:focus {
    outline: none;
}

.tab:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

button.secondary {
    background: #1e2633;
    color: var(--muted);
    border: 1px solid var(--border)
}

#automation-name-btn {
    background: #2a2a2a !important;
    color: white !important;
    border: 1px solid var(--border) !important;
}

button.secondary:hover {
    color: var(--text);
    border-color: var(--accent);
    background: rgba(0, 122, 204, 0.12);
}

/* Left aligned nav-like buttons with chevron */
.nav-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    padding: 12px 14px;
    color: var(--muted);
    background: rgba(38, 38, 38, 0.6);
    border: 1px dashed var(--border);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.nav-button::after {
    content: ">";
    color: var(--muted);
    margin-left: 12px;
    transition: color 0.2s ease;
}

.nav-button:hover {
    background: rgba(38, 38, 38, 0.8);
    border-color: var(--accent);
    color: var(--accent);
}

.nav-button:hover::after {
    color: var(--accent);
}


.error {
    color: var(--danger);
    min-height: 20px
}

.info {
    color: var(--ok);
    min-height: 20px
}

.chip-row { display:flex; flex-direction:column; gap:6px; }
.chip { padding:6px 10px; border-radius:999px; border:1px solid var(--border); background:#2a2a2a; color:var(--text); font-size:14px; cursor:pointer; width:100%; box-sizing:border-box; }
.chip.active { border-color: var(--accent); color: var(--accent); background: rgba(0, 122, 204, 0.12); }
.item-pill { display:inline-flex; align-items:center; gap:6px; padding:6px 10px; border-radius:10px; border:1px solid var(--border); background:#2a2a2a; margin:4px 6px 0 0; line-height:1; flex-wrap:wrap; }
#triggers-list .item-pill,
.action-item .item-pill,
.condition-pill { display:flex; width:100%; box-sizing:border-box; margin:0; justify-content:space-between; flex-wrap:wrap; }
#triggers-list .item-pill { margin:0 0 6px 0; }
.item-pill-label { flex:1; min-width:0; word-break:break-word; overflow-wrap:break-word; hyphens:manual; -webkit-hyphens:manual; -ms-hyphens:manual; }
.item-pill-right { display:flex; align-items:center; gap:6px; margin-left:auto; flex-shrink:0; }
.item-pill .remove { background:#3a3a3a; border:1px solid var(--border); color:var(--muted); width:24px; height:24px; display:flex; align-items:center; justify-content:center; border-radius:6px; cursor:pointer; padding:0; line-height:0; box-sizing:border-box; transition:all 0.2s ease; }
.item-pill .remove::before { content:"×"; font-size:14px; line-height:1; display:block; font-weight:bold; }
.item-pill .remove:hover { background:#4a4a4a; color:var(--danger); }

/* Улучшенный интерфейс для условий */
.conditions-container {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #1e1e1e;
  padding: 12px;
  padding-top: 20px;
  position: relative;
  overflow: visible;
}

.condition-group {
  position: relative;
  margin-bottom: 8px;
}

.condition-group:last-child {
  margin-bottom: 0;
}

.condition-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #2a2a2a;
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
  overflow: visible;
  margin-bottom: 0;
}

.condition-item.pill-only {
  padding: 0;
  background: transparent;
  border: none;
  align-items: stretch;
}

.condition-item.pill-only .condition-content {
  padding: 0;
}

.condition-item:last-child {
  margin-bottom: 0;
}

.condition-item.nested:not(.or-condition) {
  margin-left: 20px;
  border-left: 3px solid var(--accent);
  background: #252525;
}

.condition-item.or-condition {
  position: relative;
  padding-left: 48px;
  background: transparent;
  border: none;
  margin-bottom: 0;
  border-left: none;
}

.condition-item.group {
  background: #1f1f1f;
  border-color: var(--accent);
  border-style: dashed;
}

.condition-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.condition-label {
  font-weight: 500;
  color: var(--text);
}

.condition-value {
  color: var(--muted);
  font-size: 14px;
}

/* Оператор "И" в левом краю между элементами - унифицированное расстояние */
.condition-operator-left-between {
  display: flex;
  align-items: center;
  margin: -8px 0 -8px;
  height: 28px;
  position: relative;
  z-index: 10;
  pointer-events: auto;
  padding-left: 0;
  justify-content: flex-start;
  margin-top: 4px;
}

/* Оператор "ИЛИ" слева вверху элемента - унифицированное расстояние (такое же как у "И") */
.condition-operator-left {
  position: absolute;
  left: 8px;
  top: 4px;
  z-index: 10;
  pointer-events: auto;
  width: 32px;
  height: 32px;
}

.condition-item.or-condition .condition-content {
  margin-left: 0;
}

/* На мобильных устройствах */
@media (max-width: 768px) {
  .condition-item {
    position: relative;
    padding-left: 48px;
    padding-right: 8px;
    min-height: 48px;
    overflow: visible;
  }
  
  .condition-operator-left {
    position: absolute;
    left: 8px;
    top: 4px;
    z-index: 100;
    pointer-events: auto;
  }
  
  .condition-operator-left-between {
    margin: -8px 0 -8px;
    margin-top: 4px;
    justify-content: flex-start;
  }
  
  .condition-content {
    flex: 1;
    min-width: 0;
    padding-left: 0;
    pointer-events: auto;
  }
  
  .condition-actions {
    flex-shrink: 0;
    margin-left: auto;
    pointer-events: auto;
  }
  
  /* Убеждаемся, что кнопка оператора кликабельна */
  .condition-operator-btn {
    pointer-events: auto !important;
    touch-action: manipulation;
    cursor: pointer;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
  }
}

.condition-operator-btn {
  background: #1e2633;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: bold;
  width: 32px;
  height: 32px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  touch-action: manipulation;
  position: relative;
  z-index: 20;
  -webkit-tap-highlight-color: transparent;
  outline: none !important;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0) !important;
}

.condition-operator-btn:hover {
  background: #2a3441;
  transform: scale(1.05);
}

.condition-operator-btn.and:hover {
  background: #45a049 !important;
  color: white !important;
  border-color: #45a049 !important;
  transform: scale(1.05);
}

.condition-operator-btn.or:hover {
  background: #e68900 !important;
  color: white !important;
  border-color: #e68900 !important;
  transform: scale(1.05);
}

.condition-operator-btn.and {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

.condition-operator-btn.or {
  background: #FF9800;
  color: white;
  border-color: #FF9800;
}

.condition-operator-btn.active {
  background: var(--accent) !important;
  color: white !important;
  border-color: var(--accent) !important;
}

.condition-operator-btn:focus {
  outline: none !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

.condition-operator-btn:focus:not(:focus-visible) {
  outline: none !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

.condition-operator-btn.and.active,
.condition-operator-btn.and:focus,
.condition-operator-btn.and:focus-visible,
.condition-operator-btn.and:active,
.condition-operator-btn.and:focus:active {
  background: #4CAF50 !important;
  color: white !important;
  border-color: #4CAF50 !important;
  outline: none !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

.condition-operator-btn.or.active,
.condition-operator-btn.or:focus,
.condition-operator-btn.or:focus-visible,
.condition-operator-btn.or:active,
.condition-operator-btn.or:focus:active {
  background: #FF9800 !important;
  color: white !important;
  border-color: #FF9800 !important;
  outline: none !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

.condition-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.condition-add-btn {
  background: #1e2633;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.condition-add-btn:hover {
  background: #2a3441;
}

.condition-remove-btn {
  background: #3a3a3a;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.condition-remove-btn:hover {
  background: #4a4a4a;
  color: var(--danger);
}

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.group-type {
  background: var(--accent);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
}

.group-type.or {
  background: #FF9800;
}

.group-type.not {
  background: #F44336;
}

.group-count {
  color: var(--muted);
  font-size: 12px;
}

.conditions-empty {
  text-align: center;
  color: var(--muted);
  padding: 20px;
  font-style: italic;
}

/* Calendar and wheels */
.picker-row { display:flex; gap:8px; align-items:center; }
.wheel { width: 100px; height: 180px; overflow-y: auto; border:1px solid var(--border); border-radius:10px; background:#222; scrollbar-width: none; scroll-behavior: smooth; }
.wheel::-webkit-scrollbar { display:none; }
.wheel-item { height:36px; display:flex; align-items:center; justify-content:center; text-align:center; color:var(--text); }
.wheel-item.active { background:#2f2f2f; color:var(--accent); font-weight:600; }
.wheel-wrap { position: relative; }
.wheel-center { display:none; }
.muted { color: var(--muted); }
.calendar { display:grid; grid-template-columns: repeat(7, 1fr); gap:6px; background:#222; padding:8px; border:1px solid var(--border); border-radius:10px; }
.calendar button { background:#2a2a2a; border:1px solid var(--border); color:var(--text); padding:8px; border-radius:8px; }
.calendar button.active { background:#2f2f2f; color:var(--accent); }

.list {
    list-style: none;
    margin: 12px 0 0 0;
    padding: 0;
    display: grid;
    gap: 8px
}

.list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #262626;
    cursor: default;
    color: var(--text);
}

.list li span:first-child {
    color: var(--text);
    font-weight: 500;
}

.list li.offline {
    opacity: 1;
    cursor: pointer
}

.list li:hover {
    filter: brightness(1.05)
}

.banner:empty {
    display: none
}

.badge {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #333333;
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: pre-line;
}

/* Active state for suggestion buttons */
button.secondary.active { border-color: var(--accent); color: var(--accent); background: rgba(0, 122, 204, 0.12); }

.list li.add-automation {
    background: rgba(38, 38, 38, 0.6);
    border-style: dashed;
    color: var(--muted);
}

.list li.add-automation span.plus {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 122, 204, 0.22);
    color: var(--text);
    border: 1px solid var(--border);
    margin-right: 8px;
}

.add-btn {
    background: rgba(38, 38, 38, 0.9);
    border: 1px dashed var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-btn:hover {
    background: rgba(38, 38, 38, 1);
    color: var(--text);
}

.add-btn .plus {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 122, 204, 0.35);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

.add-btn-short {
    background: rgba(38, 38, 38, 0.6);
    border: 1px dashed var(--border);
    color: var(--muted);
    padding: 6px 10px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
}

#add-condition-btn {
    background: rgba(38, 38, 38, 0.6) !important;
    color: var(--muted) !important;
}

.add-btn-short:hover {
    background: rgba(38, 38, 38, 0.8);
    color: var(--text);
}

.add-btn-short .plus {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 122, 204, 0.22);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

.add-btn.active,
.add-btn-short.active {
    background: rgba(0, 122, 204, 0.25);
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(0, 122, 204, 0.4);
}

.add-btn.active .plus,
.add-btn-short.active .plus {
    background: rgba(0, 122, 204, 0.4);
    border-color: var(--accent);
}

.sheet {
    position: fixed;
    left: 6%;
    right: 6%;
    bottom: 0;
    background: rgba(29,29,29,.98);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(0,0,0,.45);
    padding: 12px;
    max-height: 75vh;
    overflow: auto;
    transform: translateY(100%);
    transition: transform .2s ease-out;
    touch-action: auto;
    z-index: 1001;
}

.sheet h3 {
    color: var(--text);
}

.sheet.sheet-tall { max-height: 88vh; }

.sheet.hidden {
    display: block;
    transform: translateY(100%);
}

.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(2px);
    z-index: 1000;
}

.sheet-backdrop.hidden {
    display: none;
}

.sheet-handle {
    width: 80px;
    min-height: 32px;
    margin: 8px auto 16px auto;
    touch-action: none;
    cursor: grab;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Увеличиваем область клика */
    padding: 12px 10px;
}

.sheet-handle::before {
    content: '';
    width: 60px;
    height: 8px;
    border-radius: 4px;
    background: #555;
    display: block;
}

.sheet-handle:active {
    cursor: grabbing;
}

/* Стили для кнопок перемещения действий */
.arrow-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    height: 24px;
    padding: 0;
    width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.arrow-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.arrow-btn:active {
    background: var(--bg-active);
}

.action-item {
    transition: all 0.2s ease;
}

.action-item:hover .arrow-btn {
    opacity: 1;
}

.info-icon {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #121212;
    color: var(--text);
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
    transition: all 0.2s ease;
    user-select: none;
}

.info-icon.new {
    background: rgba(0, 122, 204, 0.3);
    color: var(--accent);
    box-shadow: 0 0 8px rgba(0, 122, 204, 0.4);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 8px rgba(0, 122, 204, 0.4);
    }
    50% {
        box-shadow: 0 0 12px rgba(0, 122, 204, 0.6);
    }
}

.info-icon:hover {
    background: #151515;
    transform: scale(1.1);
}

.info-icon.new:hover {
    background: rgba(0, 122, 204, 0.4);
    box-shadow: 0 0 12px rgba(0, 122, 204, 0.6);
}

.login-centered {
  display: flex;
  flex-direction: column;
  align-items: center; /* Центрирует всё по горизонтали */
  text-align: center;
  padding: 20px;
}

.login-logo {
  width: 80px; /* Увеличил размер, так как 28px для центра экрана слишком мало */
  height: 80px;
  border-radius: 15px; /* Соразмерно новому размеру */
  margin-bottom: 20px;
  display: block;
}

.logo-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.login-centered button {
  width: 100%;
  margin-top: 10px;
}
