* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f5f5f7;
  color: #1c1c1e;
}

#app {
  max-width: 390px;
  margin: 0 auto;
  padding: 12px;
}

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

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.add-form input {
  flex: 1;
  min-width: 0;
  padding: 8px;
  font-size: 14px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.add-form button {
  padding: 8px 12px;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  background: #007aff;
  color: #fff;
}

.add-form button:disabled {
  background: #a9a9a9;
}

.limit-message {
  color: #c00;
  font-size: 13px;
  margin: 0 0 8px;
}

.habit-list {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.habit-item {
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.drag-handle {
  cursor: grab;
  color: #999;
  touch-action: none;
  padding: 0 4px;
}

.habit-item.dragging {
  opacity: 0.6;
}

.habit-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.habit-name input {
  width: 100%;
  font-size: 14px;
  padding: 4px;
}

.habit-streak {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
}

.habit-toggle {
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  background: #e5e5ea;
}

.habit-toggle.done {
  background: #34c759;
  color: #fff;
}

.habit-actions {
  display: flex;
  gap: 4px;
}

.habit-actions button {
  border: none;
  background: none;
  font-size: 14px;
  padding: 4px;
}

.history-table {
  width: 100%;
  max-width: 390px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 10px;
}

.history-table th,
.history-table td {
  text-align: center;
  padding: 4px 2px;
  overflow: hidden;
  white-space: normal;
}

.history-table th:first-child,
.history-table td:first-child {
  text-align: left;
  width: 32%;
}

.history-table th {
  font-size: 9px;
  line-height: 1.3;
  font-weight: 500;
}

.day-cell {
  cursor: pointer;
}

.day-cell.none {
  cursor: default;
}

.day-cell.done {
  color: #34c759;
}

.day-cell.missed {
  color: #d0d0d5;
}

.day-cell.none {
  color: #f0f0f2;
}

.day-cell.missed.unplanned,
.day-cell.none.unplanned {
  color: #b8b8c0;
}

.day-cell.done.unplanned {
  color: #2f9147;
}

.unplanned {
  background: #e3e3e8;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal-box {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  max-width: 320px;
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.edit-error {
  color: #c00;
  font-size: 13px;
  margin: 8px 0 0;
}

.modal-actions .danger {
  background: #ff3b30;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
}

.modal-actions button:not(.danger) {
  background: #e5e5ea;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
}

.modal-actions .primary {
  background: #007aff;
  color: #fff;
}

.schedule-picker {
  border: none;
  padding: 0;
  margin: 0 0 8px;
  font-size: 12px;
}

.weekday-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.weekday-picker[hidden],
.weekly-picker[hidden] {
  display: none;
}

.settings-panel {
  margin-top: 16px;
  padding: 12px;
  background: #fff;
  border-radius: 8px;
  font-size: 13px;
}

.telegram-status {
  color: #666;
  margin: 4px 0 0;
}

/* Правка сопровождения 30.09: поле названия занимало 18px — flex:1 из «.add-form input» доставался и
   флажкам расписания, и они съедали ширину строки. Название и кнопка — первой строкой, расписание — второй. */
.add-form { flex-wrap: wrap; }
.add-form #add-input { flex: 1 1 180px; }
.add-form .schedule-picker { flex: 1 1 100%; order: 3; }
.add-form .schedule-picker input { flex: none; min-width: auto; padding: 0; }
.add-form .schedule-picker input[type="number"] { width: 3.5em; padding: 2px 4px; }
